|
|
@ -7,7 +7,7 @@ export class SuggestionService { |
|
|
|
constructor() { |
|
|
|
constructor() { |
|
|
|
console.log('SuggestionService instanciate worker') |
|
|
|
console.log('SuggestionService instanciate worker') |
|
|
|
this.worker = new Worker(new URL('./worker.js', import.meta.url), { |
|
|
|
this.worker = new Worker(new URL('./worker.js', import.meta.url), { |
|
|
|
type: 'module' |
|
|
|
type: 'module' |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.init() |
|
|
|
this.init() |
|
|
|
this.events = new EventEmitter() |
|
|
|
this.events = new EventEmitter() |
|
|
@ -17,46 +17,46 @@ export class SuggestionService { |
|
|
|
async init() { |
|
|
|
async init() { |
|
|
|
const onMessageReceived = (e) => { |
|
|
|
const onMessageReceived = (e) => { |
|
|
|
switch (e.data.status) { |
|
|
|
switch (e.data.status) { |
|
|
|
case 'initiate': |
|
|
|
case 'initiate': |
|
|
|
console.log(e.data) |
|
|
|
console.log(e.data) |
|
|
|
this.events.emit(e.data.status, e.data) |
|
|
|
this.events.emit(e.data.status, e.data) |
|
|
|
// Model file start load: add a new progress item to the list.
|
|
|
|
// Model file start load: add a new progress item to the list.
|
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'progress': |
|
|
|
case 'progress': |
|
|
|
this.events.emit(e.data.status, e.data) |
|
|
|
this.events.emit(e.data.status, e.data) |
|
|
|
console.log(e.data) |
|
|
|
console.log(e.data) |
|
|
|
// Model file progress: update one of the progress items.
|
|
|
|
// Model file progress: update one of the progress items.
|
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'done': |
|
|
|
case 'done': |
|
|
|
this.events.emit(e.data.status, e.data) |
|
|
|
this.events.emit(e.data.status, e.data) |
|
|
|
console.log(e.data) |
|
|
|
console.log(e.data) |
|
|
|
// Model file loaded: remove the progress item from the list.
|
|
|
|
// Model file loaded: remove the progress item from the list.
|
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'ready': |
|
|
|
case 'ready': |
|
|
|
this.events.emit(e.data.status, e.data) |
|
|
|
this.events.emit(e.data.status, e.data) |
|
|
|
console.log(e.data) |
|
|
|
console.log(e.data) |
|
|
|
// Pipeline ready: the worker is ready to accept messages.
|
|
|
|
// Pipeline ready: the worker is ready to accept messages.
|
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'update': |
|
|
|
case 'update': |
|
|
|
this.events.emit(e.data.status, e.data) |
|
|
|
this.events.emit(e.data.status, e.data) |
|
|
|
console.log(e.data) |
|
|
|
console.log(e.data) |
|
|
|
// Generation update: update the output text.
|
|
|
|
// Generation update: update the output text.
|
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'complete': |
|
|
|
case 'complete': |
|
|
|
console.log(e.data) |
|
|
|
console.log(e.data) |
|
|
|
if (this.responses[e.data.id]) { |
|
|
|
if (this.responses[e.data.id]) { |
|
|
|
this.responses[e.data.id](null, e.data) |
|
|
|
this.responses[e.data.id](null, e.data) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.log('no callback for', e.data) |
|
|
|
console.log('no callback for', e.data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Generation complete: re-enable the "Generate" button
|
|
|
|
// Generation complete: re-enable the "Generate" button
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|