Commit 9e4c50db authored by Tom JORQUERA's avatar Tom JORQUERA
Browse files

Merge branch 'issue-31' into 'master'

issue-29 client: robot now tries to reopen STT WS on error

Closes #29

See merge request !25
parents 7c3c5ec5 3cf83a4e
......@@ -55,8 +55,7 @@ robot = {
}
},
recordParticipant(easyrtcid) {
const stream = robotController.getRemoteStream(easyrtcid);
openSTTSocket(easyrtcid) {
const ws = robotLib.stt.getTranscriptSocket(e => {
console.log('> ' + e.text);
robotLib.reco.send(
......@@ -65,9 +64,25 @@ robot = {
text: e.from + '\t' + e.until + '\t' + easyrtcid + '\t' + e.text
});
});
robot.participantsMediaRecorders[easyrtcid] = robot.processAudio(stream, e => ws.send(e.data), 100);
ws.onerror = e => {
// Try to open new connection on error
console.error('STT ws for ' + easyrtcid + ' error. Trying to reopen');
console.error(e);
robot.openSTTSocket(easyrtcid);
};
robot.recordedParticipantsWS[easyrtcid] = ws;
},
getUserStream(easyrtcid) {
const stream = robotController.getRemoteStream(easyrtcid);
robot.participantsMediaRecorders[easyrtcid] = robot.processAudio(stream, e => robot.recordedParticipantsWS[easyrtcid].send(e.data), 100);
},
recordParticipant(easyrtcid) {
robot.openSTTSocket(easyrtcid);
robot.getUserStream(easyrtcid);
},
stopRecordParticipant(easyrtcid) {
robot.participantsMediaRecorders[easyrtcid].stop();
robot.recordedParticipantsWS[easyrtcid].close();
......
'use strict';
const sttMock = {
sttDataSent: [],
wsMock: {
status: 'unitialized',
send(data) {
sttMock.sttDataSent.push(data);
},
close() {
sttMock.wsMock.status = 'closed';
}
},
getTranscriptSocket: () => {
sttMock.wsMock.status = 'open';
sttMock.sttDataSend = [];
return sttMock.wsMock;
}
};
describe('client/robot', () => {
beforeEach(() => {
global.MediaRecorder = function (stream) {
......@@ -37,18 +55,7 @@ describe('client/robot', () => {
};
global.robotLib = {
sttDataSent: [],
closed: false,
stt: () => ({
getTranscriptSocket: () => ({
send(data) {
global.robotLib.sttDataSent.push(data);
},
close() {
global.robotLib.closed = true;
}
})
}),
stt: () => sttMock,
reco: () => ({
start: () => {},
getOnlineReco: () => new Promise(() => {}, () => {})
......@@ -100,11 +107,11 @@ describe('client/robot', () => {
const e1 = {data: 'somedata1'};
global.MediaRecorder.instances.someid1.ondataavailable(e1);
expect(global.robotLib.sttDataSent[0]).toBe(e1.data);
expect(sttMock.sttDataSent[0]).toBe(e1.data);
const e2 = {data: 'somedata2'};
global.MediaRecorder.instances.someid2.ondataavailable(e2);
expect(global.robotLib.sttDataSent[1]).toBe(e2.data);
expect(sttMock.sttDataSent[1]).toBe(e2.data);
});
test('should start transcribing stream on user connection after `start`', () => {
......@@ -113,7 +120,8 @@ describe('client/robot', () => {
const e = {data: 'somedata'};
global.MediaRecorder.instances.testid.ondataavailable(e);
expect(global.robotLib.sttDataSent[0]).toBe(e.data);
console.log(sttMock.sttDataSent);
expect(sttMock.sttDataSent[sttMock.sttDataSent.length - 1]).toBe(e.data);
});
test('should stop transcribing stream on user disconnect', () => {
......@@ -121,6 +129,17 @@ describe('client/robot', () => {
global.robotController.onAttendeeRemove({}, {easyrtcid: 'someid1'});
expect(global.MediaRecorder.instances.someid1.stopped).toBeTruthy();
expect(global.robotLib.closed).toBeTruthy();
expect(sttMock.wsMock.status).toBe('closed');
});
test('should try to reopen a stt ws on error', () => {
global.robot.start();
// Trigger an error
sttMock.wsMock.status = 'error';
sttMock.wsMock.onerror('error');
// Check WS has been reopened
expect(sttMock.wsMock.status).toBe('open');
});
});
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