Skip to content

Commit

Permalink
add e2e connection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fippo committed Apr 21, 2018
1 parent 783079f commit c257d8c
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/e2e/connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const MediaSession = require('../../index.js');

function noop() {}

const types = [{audio: true}, /*{video: true}, {audio: true, video: true}*/];
types.forEach((type) => {
let description;
if (type.audio && type.video) {
description = 'audio/video';
} else if (type.audio) {
description = 'audio-only';
} else {
description = 'video-only';
}

describe.only('establishment of a ', () => {
let localStream;
beforeEach(() => {
return navigator.mediaDevices.getUserMedia(type)
.then((stream) => localStream = stream);
});

it(description + ' session', (done) => {
const sessionA = new MediaSession({
sid: '123',
peer: 'some-peer',
initiator: true,
});
const sessionB = new MediaSession({
sid: '123',
peer: 'some-peer',
initiator: false,
});

sessionA.on('send', (data) => {
sessionB.process(data.jingle.action, data.jingle, (err) => {
if (data.jingle.action === 'session-initiate' && !err) {
sessionB.accept(noop);
}
});
});
sessionB.on('send', (data) => {
sessionA.process(data.jingle.action, data.jingle, noop);
});
sessionA.on('change:connectionState', (session, state) => {
if (state === 'connected') {
done();
}
});

sessionA.addStream(localStream);
sessionA.start({});
});
});
});

0 comments on commit c257d8c

Please sign in to comment.