Commit 634b88f1 authored by Tom JORQUERA's avatar Tom JORQUERA
Browse files

Merge branch 'issue-23' into 'master'

Issue 23

Closes #23 and #24

See merge request !22
parents 37327664 f22bef0f
......@@ -11,7 +11,8 @@ const config = arguments[1];
robotController.external.load(config);
robot = {
recordedParticipants: {},
recordedParticipantsWS: {},
participantsMediaRecorders: {},
processAudio(stream, callback, interval) {
const mediaRecorder = new MediaRecorder(stream);
......@@ -54,22 +55,35 @@ robot = {
}
},
recordParticipant(easyrtcid) {
const stream = robotController.getRemoteStream(easyrtcid);
const ws = robotLib.stt.getTranscriptSocket(e => {
console.log('> ' + e.text);
robotLib.reco.send(
{
from: room,
text: e.from + '\t' + e.until + '\t' + easyrtcid + '\t' + e.text
});
});
robot.participantsMediaRecorders[easyrtcid] = robot.processAudio(stream, e => ws.send(e.data), 100);
robot.recordedParticipantsWS[easyrtcid] = ws;
},
stopRecordParticipant(easyrtcid) {
robot.participantsMediaRecorders[easyrtcid].stop();
robot.recordedParticipantsWS[easyrtcid].close();
},
start: () => {
robotLib.stt = robotLib.stt(config);
robotLib.reco = robotLib.reco(config);
robotLib.archive = robotLib.archive(config);
robotController.onAttendeePush = (e, data) => {
const stream = robotController.getRemoteStream(data.easyrtcid);
const ws = robotLib.stt.getTranscriptSocket(e => {
console.log('> ' + e.text);
robotLib.reco.send(
{
from: room,
text: e.from + '\t' + e.until + '\t' + data.easyrtcid + '\t' + e.text
});
});
robot.processAudio(stream, e => ws.send(e.data), 100);
robot.recordParticipant(data.easyrtcid);
};
robotController.onAttendeeRemove = (e, data) => {
robot.stopRecordParticipant(data.easyrtcid);
};
robotLib.reco.start(room);
......@@ -78,5 +92,8 @@ robot = {
.then(robot.processReco)
.catch(console.error),
8000);
// Record current participants already present in the room
robotController.getParticipants().map(robot.recordParticipant);
}
};
......@@ -7,29 +7,40 @@ describe('client/robot', () => {
type: 'mediaRecorder',
stream,
started: false,
stopped: false,
interval: null,
start(interval) {
this.started = true;
this.interval = interval;
},
stop() {
this.started = false;
this.stopped = true;
}
};
global.MediaRecorder.instance = res;
global.MediaRecorder.instances[stream.id] = res;
return res;
};
global.MediaRecorder.instances = {};
global.robotController = {
external: {
load: () => {}
},
getParticipants: () => ['someid1', 'someid2'],
getRemoteStream: id => ({type: 'RemoteStream', id})
};
global.robotLib = {
sttDataSent: [],
closed: false,
stt: () => ({
getTranscriptSocket: () => ({
send(data) {
global.robotLib.sttDataSent.push(data);
},
close() {
global.robotLib.closed = true;
}
})
}),
......@@ -73,12 +84,32 @@ describe('client/robot', () => {
expect(callbackCalled).toBe('somedata');
});
test('should start transcribing users already present on `start`', () => {
global.robot.start();
const e1 = {data: 'somedata1'};
global.MediaRecorder.instances.someid1.ondataavailable(e1);
expect(global.robotLib.sttDataSent[0]).toBe(e1.data);
const e2 = {data: 'somedata2'};
global.MediaRecorder.instances.someid2.ondataavailable(e2);
expect(global.robotLib.sttDataSent[1]).toBe(e2.data);
});
test('should start transcribing stream on user connection after `start`', () => {
global.robot.start();
global.robotController.onAttendeePush({}, {easyrtic: 'testid'});
global.robotController.onAttendeePush({}, {easyrtcid: 'testid'});
const e = {data: 'somedata'};
global.MediaRecorder.instance.ondataavailable(e);
global.MediaRecorder.instances.testid.ondataavailable(e);
expect(global.robotLib.sttDataSent[0]).toBe(e.data);
});
test('should stop transcribing stream on user disconnect', () => {
global.robot.start();
global.robotController.onAttendeeRemove({}, {easyrtcid: 'someid1'});
expect(global.MediaRecorder.instances.someid1.stopped).toBeTruthy();
expect(global.robotLib.closed).toBeTruthy();
});
});
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