Commit 00848f7a authored by Yoann HOUPERT's avatar Yoann HOUPERT

Integration KGS

parent 6988fe0d
Pipeline #14027 failed with stage
......@@ -29,6 +29,9 @@ const controllerFactory = require('./lib/controller.js');
const proxy = require('./lib/proxy.js')(config.proxy);
const resumeGenerator = require('./lib/resume.js')(config.offline)
require('dotenv').config()
console.log('starting hublot...');
loader.loadAll('controller', 'lib', 'robot')
......
......@@ -30,7 +30,7 @@ robot = {
room: '',
clientConfig: {},
previousReco: [],
recordedParticipantsWS: {},
recordedParticipantsWS: [],
participantsMediaRecorders: {},
isDisconnected: false,
intervalList: [],
......@@ -106,15 +106,14 @@ robot = {
recordParticipant(easyrtcid) {
robot.socket.emit('new_user', easyrtcid);
robot.getUserStream(easyrtcid);
robot.recordedParticipantsWS.push(easyrtcid);
},
stopRecordParticipant(easyrtcid) {
if (robot.participantsMediaRecorders[easyrtcid]) {
robot.participantsMediaRecorders[easyrtcid].stop();
}
if (robot.recordedParticipantsWS[easyrtcid]) {
robot.recordedParticipantsWS[easyrtcid].close();
}
robot.socket.emit('disconnect_from_' + easyrtcid, 'end of user')
},
checkDisconnect() {
......@@ -129,16 +128,14 @@ robot = {
}
robot.intervalList = [];
const keyMap = Object.keys(robot.recordedParticipantsWS);
if (keyMap) {
for (let i = 0; i < keyMap.length; i++) {
try {
robot.stopRecordParticipant(keyMap[i]);
} catch (err) {
console.log('This user is inactive');
}
for (let i = 0; i < robot.recordedParticipantsWS.length; i++) {
try {
robot.stopRecordParticipant(robot.recordedParticipantsWS[i]);
} catch (err) {
console.log('This user is inactive');
}
}
robot.recordedParticipantsWS = [];
},
start: (room, clientConfig) => {
......@@ -160,8 +157,7 @@ robot = {
console.log(e)
})
robot.socket.on('resume_data', (event) => {
const hyp = JSON.parse(event.data);
robot.socket.on('resume_data', (hyp) => {
if (hyp.status === 0) {
if (hyp.result !== undefined && hyp.result.final) {
const transcription = ((hyp.result.hypotheses)[0]).transcript;
......@@ -178,15 +174,10 @@ robot = {
robotLib.reco.send({
from: robot.room,
text: start +'\t'+ end+ '\t'+ easyrtcid + '\t' + transcription
text: start + '\t' + end + '\t' + hyp.userId + '\t' + transcription
});
}
}
robotLib.reco.send({
from: robot.room,
text: start +'\t'+ end+ '\t'+ 'undefined' + '\t' + event
});
})
robotController.onAttendeePush = (e, data) => {
......
......@@ -39,6 +39,7 @@
},
"api": 3000,
"proxy": {
"asd": false,
"port_ws_audio": 3001,
"port_server_proxy": 3002,
"services": {
......
......@@ -4,8 +4,8 @@
process.env.ASD_CONTROL_PORT = 8881
process.env.ASD_STREAM_PORT = 8882
process.env.ASD_SERVER_IP = "localhost"
const debug = require('debug')('lib:asd')
require('dotenv').config()
const {
EventEmitter
} = require("events")
......@@ -89,7 +89,7 @@ class Asd extends EventEmitter {
}
streamPush(streamId, data) {
this.streams[streamId].write()
this.streams[streamId].write(data)
}
streamDisconnect(streamId) {
......
......@@ -24,6 +24,7 @@ const stomp = require('webstomp-client');
const WebSocket = require('ws');
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
const Asd = require('./asd');
module.exports = config => {
function createStompClient() {
......@@ -117,20 +118,19 @@ module.exports = config => {
}
function kaldiWSInit(socket) {
function kaldiWS(userId, socket) {
const connectionToKaldi = new WebSocket(config.services.kaldi);
connectionToKaldi.on('open', () => {
connectionToKaldi.on('message', message => {
try {
console.log('resume ?')
console.log(message)
socket.emit('resume_data', message);
let msgJson = JSON.parse(message);
msgJson.userId = userId
socket.emit('resume_data', msgJson);
} catch (err) {
// Sometimes, the client will close the connection unexpectedly
// (e.g. when stopping). This is expected
}
});
connectionToKaldi.on('close', () => {
connectionToClient.close()
});
......@@ -138,42 +138,71 @@ module.exports = config => {
return connectionToKaldi;
}
return {
create: (resume) => {
resume.createFolder()
const audioWebSocketServer = http.createServer();
const stompClient = createStompClient();
const io = require('socket.io')(audioWebSocketServer, {
transports: ['websocket']
});
function audioSocket(resume) {
const audioWebSocketServer = http.createServer();
io.sockets.on('connection', (socket) => {
let asd = {} //port 8881 - connexion de contrôle ASD
let userAudioEvents = []
socket.on('error', (err) => {
for (userEvent in userAudioEvents){
socket.removeListener(userEvent)
}
userAudioEvents = []
asd = {} //disconnect and kill asd sockets
})
socket.on('new_user', (userId) => {
const connectionToKaldi = kaldiWSInit()
//create ASD stream //port 8882 - connexion de data
userAudioEvents.push('audio_from_' + userId)
//asd.on("resume_data", soket.emit('resume_data'))
//register custom event for user
socket.on('audio_from_' + userId, (data) => {
console.log("DATA RECEIVED FOR USER : ", asd)
connectionToKaldi.send(data, {
const io = require('socket.io')(audioWebSocketServer, {
transports: ['websocket']
});
io.sockets.on('connection', (socket) => {
let asd = Asd //port 8881 - connexion de contrôle ASD
let userAudioEvents = []
socket.on('error', (err) => {
for (userEvent in userAudioEvents) {
socket.removeListener(userEvent)
}
userAudioEvents = []
asd = {} //disconnect and kill asd sockets
})
socket.on('new_user', (userId) => {
const streamData = resume.generateStream()
let transcriptor
let thisUserStream;
if (!config.asd)
transcriptor = kaldiWS(userId, socket)
else{
transcriptor = asd
thisUserStream = transcriptor.streamConnect()
}
//create ASD stream //port 8882 - connexion de data
userAudioEvents.push('audio_from_' + userId)
//asd.on("resume_data", soket.emit('resume_data'))
//register custom event for user
socket.on('audio_from_' + userId, (data) => {
if (!config.asd) {
transcriptor.send(data, {
binary: true
});
} else {
transcriptor.streamPush(thisUserStream, data)
}
console.log('stream data save')
streamData.wstream.write(data);
})
})
socket.on('disconnect_from_' + userId, (reason) => {
resume.endStream(streamData)
delete userAudioEvents['audio_from_' + userId]
if (config.asd) {
transcriptor.streamDisconnect(thisUserStream)
}
})
});
audioWebSocketServer.listen(config.port_ws_audio);
})
});
audioWebSocketServer.listen(config.port_ws_audio);
}
return {
create: (resume) => {
resume.createFolder()
const stompClient = createStompClient();
audioSocket(resume)
const proxyEndpointServer = http.createServer();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment