-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnexmoWebsocket.js
44 lines (39 loc) · 1.55 KB
/
nexmoWebsocket.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module.exports = function(server) {
console.log("WebSocket Ready")
var WebSocketServer = require('websocket').server;
var wsServer = new WebSocketServer({
httpServer: server,
autoAcceptConnections: true
});
// var speech = require("./speechToText");
// var speech = require('./googleSpeech');
global.speech__ = require("./googleSpeech");
wsServer.on('connect', function(connection) {
console.log((new Date()) + ' Connection accepted' + ' - Protocol Version ' + connection.webSocketVersion);
console.log("Finished with SAY");
var toggle = 0;
connection.on('message', function(message) {
if (message.type === 'utf8') {
// Reflect the message back
console.log("UTF8 DATA");
console.log(message.utf8Data);
}
else if (message.type === 'binary') {
// console.log("Binary Message Recieved");
// setTimeout(function () {
global.speech__.write(message.binaryData);
// }, )
// if (toggle == 4) {
// toggle = 0;
// } else {
// global.speech__.write(message.binaryData);
// }
// toggle++;
}
});
connection.on('close', function(reasonCode, description) {
console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');
console.log(reasonCode, description);
});
});
};