mirror of
https://github.com/leon-ai/leon.git
synced 2024-12-01 03:15:58 +03:00
refactor(server): load models and init core instances only once
This commit is contained in:
parent
e182da0048
commit
4d7c49e1ee
@ -35,7 +35,7 @@ export default class SocketServer {
|
||||
}
|
||||
}
|
||||
|
||||
public init(): void {
|
||||
public async init(): void {
|
||||
const { httpServer, host } = HTTP_SERVER
|
||||
const io = IS_DEVELOPMENT_ENV
|
||||
? new SocketIOServer(httpServer, {
|
||||
@ -43,38 +43,6 @@ export default class SocketServer {
|
||||
})
|
||||
: new SocketIOServer(httpServer)
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
LogHelper.title('Client')
|
||||
LogHelper.success('Connected')
|
||||
|
||||
this.socket = socket
|
||||
|
||||
// Init
|
||||
this.socket.on('init', async (data) => {
|
||||
LogHelper.info(`Type: ${data}`)
|
||||
LogHelper.info(`Socket id: ${this.socket.id}`)
|
||||
|
||||
// TODO
|
||||
// const provider = await addProvider(socket.id)
|
||||
|
||||
// Check whether the TCP client is connected to the TCP server
|
||||
if (TCP_CLIENT.isConnected) {
|
||||
this.socket.emit('ready')
|
||||
} else {
|
||||
TCP_CLIENT.ee.on('connected', () => {
|
||||
this.socket.emit('ready')
|
||||
})
|
||||
}
|
||||
|
||||
if (data === 'hotword-node') {
|
||||
// Hotword triggered
|
||||
this.socket.on('hotword-detected', (data) => {
|
||||
LogHelper.title('Socket')
|
||||
LogHelper.success(`Hotword ${data.hotword} detected`)
|
||||
|
||||
this.socket.broadcast.emit('enable-record')
|
||||
})
|
||||
} else {
|
||||
let sttState = 'disabled'
|
||||
let ttsState = 'disabled'
|
||||
|
||||
@ -106,6 +74,38 @@ export default class SocketServer {
|
||||
|
||||
await NLU.loadNLPModels()
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
LogHelper.title('Client')
|
||||
LogHelper.success('Connected')
|
||||
|
||||
this.socket = socket
|
||||
|
||||
// Init
|
||||
this.socket.on('init', (data) => {
|
||||
LogHelper.info(`Type: ${data}`)
|
||||
LogHelper.info(`Socket ID: ${this.socket.id}`)
|
||||
|
||||
// TODO
|
||||
// const provider = await addProvider(socket.id)
|
||||
|
||||
// Check whether the TCP client is connected to the TCP server
|
||||
if (TCP_CLIENT.isConnected) {
|
||||
this.socket.emit('ready')
|
||||
} else {
|
||||
TCP_CLIENT.ee.on('connected', () => {
|
||||
this.socket.emit('ready')
|
||||
})
|
||||
}
|
||||
|
||||
if (data === 'hotword-node') {
|
||||
// Hotword triggered
|
||||
this.socket.on('hotword-detected', (data) => {
|
||||
LogHelper.title('Socket')
|
||||
LogHelper.success(`Hotword ${data.hotword} detected`)
|
||||
|
||||
this.socket.broadcast.emit('enable-record')
|
||||
})
|
||||
} else {
|
||||
// Listen for new utterance
|
||||
this.socket.on('utterance', async (data) => {
|
||||
LogHelper.title('Socket')
|
||||
|
Loading…
Reference in New Issue
Block a user