mirror of
https://github.com/leon-ai/leon.git
synced 2024-11-24 04:31:31 +03:00
feat(web app): wait for TCP client to be connected first
This commit is contained in:
parent
95bfcfe422
commit
bc228a6860
@ -28,13 +28,17 @@ export default class Client {
|
|||||||
return this._recorder
|
return this._recorder
|
||||||
}
|
}
|
||||||
|
|
||||||
init () {
|
init (loader) {
|
||||||
this.chatbot.init()
|
this.chatbot.init()
|
||||||
|
|
||||||
this.socket.on('connect', () => {
|
this.socket.on('connect', () => {
|
||||||
this.socket.emit('init', this.client)
|
this.socket.emit('init', this.client)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.socket.on('ready', () => {
|
||||||
|
loader.stop()
|
||||||
|
})
|
||||||
|
|
||||||
this.socket.on('answer', (data) => {
|
this.socket.on('answer', (data) => {
|
||||||
this.chatbot.receivedFrom('leon', data)
|
this.chatbot.receivedFrom('leon', data)
|
||||||
})
|
})
|
||||||
|
@ -40,7 +40,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
logger.innerHTML += sLogger
|
logger.innerHTML += sLogger
|
||||||
|
|
||||||
client.init()
|
client.init(loader)
|
||||||
|
|
||||||
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
||||||
navigator.mediaDevices.getUserMedia({ audio: true }).then((stream) => {
|
navigator.mediaDevices.getUserMedia({ audio: true }).then((stream) => {
|
||||||
@ -96,8 +96,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
console.error('MediaDevices.getUserMedia() is not supported on your browser.')
|
console.error('MediaDevices.getUserMedia() is not supported on your browser.')
|
||||||
}
|
}
|
||||||
|
|
||||||
loader.stop()
|
|
||||||
|
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
onkeydowndocument(e, () => {
|
onkeydowndocument(e, () => {
|
||||||
if (rec.enabled === false) {
|
if (rec.enabled === false) {
|
||||||
|
@ -136,6 +136,15 @@ server.handleOnConnection = (socket) => {
|
|||||||
log.info(`Type: ${data}`)
|
log.info(`Type: ${data}`)
|
||||||
log.info(`Socket id: ${socket.id}`)
|
log.info(`Socket id: ${socket.id}`)
|
||||||
|
|
||||||
|
// Check whether the TCP client is connected to the TCP server
|
||||||
|
if (global.tcpClient.isConnected) {
|
||||||
|
socket.emit('ready')
|
||||||
|
} else {
|
||||||
|
global.tcpClient.ee.on('connected', () => {
|
||||||
|
socket.emit('ready')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (data === 'hotword-node') {
|
if (data === 'hotword-node') {
|
||||||
// Hotword triggered
|
// Hotword triggered
|
||||||
socket.on('hotword-detected', (data) => {
|
socket.on('hotword-detected', (data) => {
|
||||||
|
@ -54,6 +54,7 @@ class Nlu {
|
|||||||
log.success('NLP model loaded')
|
log.success('NLP model loaded')
|
||||||
|
|
||||||
this.ner = new Ner(this.nlp.ner)
|
this.ner = new Ner(this.nlp.ner)
|
||||||
|
|
||||||
resolve()
|
resolve()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.brain.talk(`${this.brain.wernicke('random_errors')}! ${this.brain.wernicke('errors', 'nlu', { '%error%': err.message })}.`)
|
this.brain.talk(`${this.brain.wernicke('random_errors')}! ${this.brain.wernicke('errors', 'nlu', { '%error%': err.message })}.`)
|
||||||
|
@ -14,6 +14,7 @@ export default class TcpClient {
|
|||||||
this.tcpSocket = new Net.Socket()
|
this.tcpSocket = new Net.Socket()
|
||||||
this._ee = new EventEmitter()
|
this._ee = new EventEmitter()
|
||||||
this._status = this.tcpSocket.readyState
|
this._status = this.tcpSocket.readyState
|
||||||
|
this._isConnected = false
|
||||||
|
|
||||||
log.title('TCP Client')
|
log.title('TCP Client')
|
||||||
log.success('New instance')
|
log.success('New instance')
|
||||||
@ -22,6 +23,7 @@ export default class TcpClient {
|
|||||||
log.title('TCP Client')
|
log.title('TCP Client')
|
||||||
log.success(`Connected to the TCP server tcp://${this.host}:${this.port}`)
|
log.success(`Connected to the TCP server tcp://${this.host}:${this.port}`)
|
||||||
|
|
||||||
|
this._isConnected = true
|
||||||
this._ee.emit('connected', null)
|
this._ee.emit('connected', null)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -74,6 +76,10 @@ export default class TcpClient {
|
|||||||
return this._ee
|
return this._ee
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isConnected () {
|
||||||
|
return this._isConnected
|
||||||
|
}
|
||||||
|
|
||||||
emit (topic, data) {
|
emit (topic, data) {
|
||||||
const obj = {
|
const obj = {
|
||||||
topic,
|
topic,
|
||||||
|
Loading…
Reference in New Issue
Block a user