From 70e443d2bb3f5ad498af3dba8c8e43b4cb99973d Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Sat, 21 Apr 2018 14:54:44 +0200 Subject: [PATCH] add e2e connection tests --- test/e2e/connection.js | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/e2e/connection.js diff --git a/test/e2e/connection.js b/test/e2e/connection.js new file mode 100644 index 0000000..33ddcc5 --- /dev/null +++ b/test/e2e/connection.js @@ -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('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({}); + }); + }); +});