Commit 857d28df authored by Sami BENHAMICHE's avatar Sami BENHAMICHE
Browse files

Merge branch 'issue-11' into 'master'

client: Add first version of robot behavior

Closes #11

See merge request !12
parents ccd57627 d6ae25ef
......@@ -2,9 +2,28 @@
//
// It is the first file of the `robot` folder to be loaded in the client.
/* global robot:true */
/* global robot:true robotController robotLib MediaRecorder */
/* exported robot */
const config = arguments[1];
robot = {
// TODO
recordedParticipants: {},
processAudio(stream, callback, interval) {
const mediaRecorder = new MediaRecorder(stream);
mediaRecorder.ondataavailable = callback;
mediaRecorder.start(interval);
return mediaRecorder;
},
start: () => {
robotLib.stt = robotLib.stt(config);
robotController.onAttendeePush = (e, data) => {
const stream = robotController.getRemoteStream(data.easyrtcid);
const ws = robotLib.stt.getTranscriptSocket(e => console.log('> ' + e.text));
robot.processAudio(stream, e => ws.send(e.data), 100);
};
}
};
'use strict';
describe('client/robot', () => {
beforeEach(() => {
global.MediaRecorder = function (stream) {
const res = {
type: 'mediaRecorder',
stream,
started: false,
interval: null,
start(interval) {
this.started = true;
this.interval = interval;
}
};
global.MediaRecorder.instance = res;
return res;
};
global.robotController = {
getRemoteStream: id => ({type: 'RemoteStream', id})
};
global.robotLib = {
sttDataSent: [],
stt: () => ({
getTranscriptSocket: () => ({
send(data) {
global.robotLib.sttDataSent.push(data);
}
})
})
};
/* eslint-disable import/no-unassigned-import */
require('./robot.js');
/* eslint-enable */
});
test('should define global robot variable', () => {
expect(global.robot).toBeDefined();
});
test('should return a started mediaRecorder on `processAudio`', () => {
const res = global.robot.processAudio({
type: 'stream'
});
expect(res.type).toBe('mediaRecorder');
expect(res.started).toBe(true);
});
test('should start the mediaRecorder with correct interval on `processAudio`', () => {
const res = global.robot.processAudio({
type: 'stream'
}, () => {}, 9999);
expect(res.interval).toBe(9999);
});
test('shoud correctly set the callback on `processAudio`', () => {
let callbackCalled = '';
const mediaRecorder = global.robot.processAudio({}, e => {
callbackCalled = e;
});
mediaRecorder.ondataavailable('somedata');
expect(callbackCalled).toBe('somedata');
});
test('should start transcribing stream on user connection after `start`', () => {
global.robot.start();
global.robotController.onAttendeePush({}, {easyrtic: 'testid'});
const e = {data: 'somedata'};
global.MediaRecorder.instance.ondataavailable(e);
expect(global.robotLib.sttDataSent[0]).toBe(e.data);
});
});
......@@ -8,6 +8,11 @@ module.exports = config => ({
.then(
() => Promise.all(controllerFilesList.map(
f => client.execute(f, room, clientConfig))))
.then(() => client.execute(() => {
/* eslint-disable no-undef */
robot.start();
/* eslint-enable */
}))
.waitForVisible('#displayname', 30000)
.setValue('#displayname', clientConfig.name)
.click('.btn')
......
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