bumblebee-api
Advanced tools
Comparing version 0.0.1 to 0.0.2
21
index.js
@@ -0,1 +1,2 @@ | ||
const Jaxcore = require('jaxcore'); | ||
@@ -16,2 +17,3 @@ const BumblebeeWebsocketClient = require('./lib/BumblebeeWebsocketClient'); | ||
function connect(options) { | ||
if (!options) options = {}; | ||
@@ -26,3 +28,3 @@ | ||
}, | ||
serviceTimeout: 10000 | ||
serviceTimeout: options.timeout || 10000 | ||
}; | ||
@@ -43,2 +45,4 @@ | ||
console.log('connecting:', wOptions); | ||
let serviceProfileName = 'websocket:'+websocketOptions.host+':'+websocketOptions.port; | ||
@@ -126,7 +130,14 @@ | ||
try { | ||
const api = await BumblebeeAPI.connect({ | ||
// enableReconnect: connect | ||
}); | ||
options = options || {}; | ||
const assistant = await api.launchAssistant(hotword, assistantClass, options); | ||
const connectOptions = { | ||
timeout: options.timeout | ||
}; | ||
const assistantOptions = { | ||
autoStart: options.autoStart | ||
}; | ||
const api = await BumblebeeAPI.connect(connectOptions); | ||
const assistant = await api.launchAssistant(hotword, assistantClass, assistantOptions); | ||
if (callback) callback(assistant); | ||
@@ -133,0 +144,0 @@ |
@@ -24,32 +24,5 @@ // Aconst App = require('./App'); | ||
this.addEvents(this.bumblebee, { | ||
hotword: function(hotword) { | ||
if (this._exitingAssistant) return; | ||
this.emit('hotword', hotword); | ||
}, | ||
command: function(recognition) { | ||
if (this._exitingAssistant) return; | ||
this.emit('command', recognition); | ||
} | ||
}); | ||
/* | ||
console.log('starting loop'); | ||
let loopResult = loop();await this.loop(); | ||
if (loopResult) { | ||
console.log('loop returned', loopResult); | ||
} | ||
else { | ||
} | ||
// console.log('main returned', r); | ||
bumblebee.say('bumblebee main returned').then(() => { | ||
bumblebee.returnValue(r); | ||
}) | ||
*/ | ||
const looper = async () => { | ||
console.log('looper()'); | ||
let loopReturn = await this.loop(); | ||
@@ -66,17 +39,32 @@ // while (!loopReturn) { | ||
this.addEvents(bumblebee, { | ||
main: function (args) { | ||
hotword: function(hotword) { | ||
if (this._exitingAssistant) return; | ||
// this.emit('hotword', hotword); | ||
if (typeof this.onHotword === 'function') { | ||
this.onHotword(hotword); | ||
} | ||
}, | ||
command: function(recognition) { | ||
if (this._exitingAssistant) return; | ||
// this.emit('command', recognition); | ||
if (typeof this.onCommand === 'function') { | ||
this.onCommand(recognition); | ||
} | ||
}, | ||
start: function (args) { | ||
console.log('main'); | ||
this.main(args) | ||
.then(mainReturn => { | ||
if (mainReturn) { | ||
console.log('main returned', mainReturn); | ||
if (this.onBeforeExit) { | ||
this.onBeforeExit(null, mainReturn).then(() => { | ||
bumblebee.returnValue(mainReturn); | ||
// this.main(args) | ||
this.onStart(args) | ||
.then(startReturn => { | ||
if (startReturn) { | ||
console.log('main returned', startReturn); | ||
if (this.onStop) { | ||
this.onStop(null, startReturn).then(() => { | ||
bumblebee.returnValue(startReturn); | ||
}); | ||
} | ||
else { | ||
bumblebee.returnValue(mainReturn); | ||
bumblebee.returnValue(startReturn); | ||
} | ||
return mainReturn; | ||
return startReturn; | ||
} | ||
@@ -90,4 +78,4 @@ else if (this.loop) { | ||
console.log('loop returned', loopReturn); | ||
if (this.onBeforeExit) { | ||
this.onBeforeExit(null, loopReturn).then(() => { | ||
if (this.onStop) { | ||
this.onStop(null, loopReturn).then(() => { | ||
bumblebee.returnValue(loopReturn); | ||
@@ -110,4 +98,4 @@ }); | ||
console.log('main error', e); | ||
if (this.onBeforeExit) { | ||
this.onBeforeExit(e).then(() => { | ||
if (this.onStop) { | ||
this.onStop(e).then(() => { | ||
bumblebee.returnError(e); | ||
@@ -135,22 +123,22 @@ }); | ||
// }, | ||
hotword: function (hotword) { | ||
this.log('bumblebee hotword:', hotword); | ||
bumblebee.console('hotword detected'); | ||
}, | ||
command: function (text, stats) { | ||
this.log('bumblebee command:', text, stats); | ||
// bumblebee.console({ | ||
// type: 'command', | ||
// text, | ||
// stats | ||
// }); | ||
}, | ||
recognize: function (text, stats) { | ||
// this.log('bumblebee recognize:', text, stats); | ||
// bumblebee.console({ | ||
// type: 'stt', | ||
// text, | ||
// stats | ||
// }); | ||
} | ||
// hotword: function (hotword) { | ||
// this.log('bumblebee hotword:', hotword); | ||
// bumblebee.console('hotword detected'); | ||
// }, | ||
// command: function (text, stats) { | ||
// this.log('bumblebee command:', text, stats); | ||
// // bumblebee.console({ | ||
// // type: 'command', | ||
// // text, | ||
// // stats | ||
// // }); | ||
// }, | ||
// recognize: function (text, stats) { | ||
// // this.log('bumblebee recognize:', text, stats); | ||
// // bumblebee.console({ | ||
// // type: 'stt', | ||
// // text, | ||
// // stats | ||
// // }); | ||
// } | ||
}); | ||
@@ -163,5 +151,14 @@ | ||
// async main() { | ||
// return this.onStart(); | ||
// } | ||
// async loop() { | ||
// let recognition = await this.bumblebee.recognize(); | ||
// return this.onRecognize(recognition); | ||
// } | ||
async abort(r) { | ||
if (this.onBeforeExit) { | ||
await this.onBeforeExit(null, r); | ||
if (this.onStop) { | ||
await this.onStop(null, r); | ||
} | ||
@@ -168,0 +165,0 @@ this.bumblebee.emit('abort-recognize', 'exit-assistant'); |
const {Client, createLogger} = require('jaxcore'); | ||
const io = require('socket.io-client'); | ||
const JAXCORE_VERSION = '0.0.3'; | ||
const BUMBLEBEE_PROTOCOL = 1; | ||
const schema = { | ||
@@ -58,8 +61,8 @@ id: { | ||
this.setState({connected: true}); | ||
this.log('socket connect'); | ||
this.log('socket connected'); | ||
const handshake = { | ||
jaxcore: { | ||
version: '0.0.2', | ||
version: JAXCORE_VERSION, | ||
protocol: { | ||
bumblebee: 1 | ||
bumblebee: BUMBLEBEE_PROTOCOL | ||
} | ||
@@ -94,7 +97,3 @@ } | ||
this.log('socket disconnect'); | ||
// socket.destroy(); | ||
this.emit('disconnect'); | ||
// this.destroy(); | ||
socket.destroy(); | ||
@@ -133,3 +132,3 @@ }); | ||
this.main(); | ||
this.startAssistant(); | ||
} | ||
@@ -158,3 +157,2 @@ else { | ||
resolve(); | ||
// process.exit(); | ||
}); | ||
@@ -165,17 +163,7 @@ this.socketEmit('say', text, options, id); | ||
async main() { | ||
this.log('start main', this.state.hotword, this.state.assistantName); | ||
// this.setActiveApp('main'); | ||
this.emit('main'); | ||
async startAssistant() { | ||
this.log('startAssistant', this.state.hotword, this.state.assistantName); | ||
this.emit('start'); | ||
} | ||
setActiveApp(appName) { | ||
this.log('setActiveApp', appName); | ||
this.setState({ | ||
appName | ||
}); | ||
this.emit('active-app', appName); | ||
this.socketEmit('active-app', appName); | ||
} | ||
socketEmit() { | ||
@@ -187,3 +175,2 @@ let args = Array.prototype.slice.call(arguments); | ||
async recognize(options) { | ||
// console.log('await recognize', options); | ||
if (!options) options = {}; | ||
@@ -193,3 +180,2 @@ return new Promise((resolve, reject) => { | ||
let timer; | ||
// let aborted = false; | ||
@@ -208,5 +194,2 @@ const onTimedRecognize = function (recognition) { | ||
const abortHandler = (reason) => { | ||
console.log('aborting.......'); | ||
console.log('==============='); | ||
if (options.timeout) { | ||
@@ -218,3 +201,2 @@ this.removeListener('recognize', onTimedRecognize); | ||
} | ||
// aborted = true; | ||
clearTimeout(timer); | ||
@@ -274,7 +256,2 @@ reject({ | ||
// exitAssistant() { | ||
// this.emit('abort-recognize', 'exit-assistant'); | ||
// // this.socket.emit('exit-assistant'); | ||
// } | ||
returnError(e) { | ||
@@ -288,6 +265,2 @@ console.log('emit assistant-return-error', e); | ||
} | ||
returnAbort(r) { | ||
console.log('emit assistant-return-abort', r); | ||
this.socketEmit('assistant-return-abort', r); | ||
} | ||
@@ -294,0 +267,0 @@ destroy() { |
{ | ||
"name": "bumblebee-api", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Bumblebee voice application server API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
15928
534