Commit d116a543 authored by Yoann HOUPERT's avatar Yoann HOUPERT
Browse files

add activity vocality base

parent ce8a1172
Pipeline #13284 failed with stage
......@@ -55,15 +55,39 @@ module.exports = config => {
}
function kaldiWS(connectionToClient, resume) {
//Only manage one conf, manage room name later
const streamData = resume.generateStream();
let participantsStream = {};
let isInit = false;
const connectionToKaldi = new WebSocket(config.services.kaldi);
connectionToKaldi.on('open', () => {
const streamData = resume.generateStream();
//When new user, new message array
const userInformation = resume.userInformation()
participantsStream[userInformation] = []
if(isInit === false){
isInit = true;
setInterval(
function(){
console.log('interval call')
let stream = resume.vocalActivity(participantsStream);
if(stream !== undefined){
connectionToKaldi.send(stream, {
binary: true
});
streamData.wstream.write(stream);
}
}, 100)
}
connectionToClient.on('message', message => {
connectionToKaldi.send(message, {
binary: true
});
streamData.wstream.write(message);
//Push stream user
participantsStream[userInformation].push(message);
});
connectionToKaldi.on('message', message => {
......
......@@ -44,6 +44,10 @@ module.exports = config => {
fs.mkdirSync(config.folder.audio);
}
},
userInformation : () => {
return uuidv1()
},
generateStream : () => {
if(timestamp === undefined){
timestamp = new Date().getTime()
......@@ -58,6 +62,17 @@ module.exports = config => {
}
return streamData
},
vocalActivity : (participantsStream) => {
const keyMap = Object.keys(participantsStream)
if(keyMap){
for(let i = 0; i < keyMap.length; i++){
console.log("userId" , keyMap[i])
}
return participantsStream[keyMap[0]].shift();
}
return undefined;
},
endStream : (streamData) => {
const toSecond = 1000
......
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