Skip to content

Commit b463f2e

Browse files
Merge pull request #358 from opentok/feature/add_support_for_bidirectional_node/VIDMC-1226
feat: Add bidirectional flag in websocket connect [VIDMC-1226]
2 parents cafc9e8 + 9a97f11 commit b463f2e

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

lib/opentok.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,10 @@ OpenTok = function (apiKey, apiSecret, env) {
13481348
body.websocket.headers = options.headers;
13491349
}
13501350

1351+
if (options.bidirectional) {
1352+
body.websocket.bidirectional = options.bidirectional;
1353+
}
1354+
13511355
this.client.websocketConnect(body, function (err, json) {
13521356
if (err) return callback(new Error('Error connecting to websocket: ' + err.message));
13531357
return callback(null, json);

test/opentok-test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,49 @@ describe('#websocketconnect', function () {
18211821
);
18221822
});
18231823

1824+
it('connect to a websocket with bidirectional enabled', function (done) {
1825+
var scope = nock('https://api.opentok.com:443')
1826+
.matchHeader('x-opentok-auth', function (value) {
1827+
try {
1828+
jwt.verify(value[0], apiSecret, { issuer: apiKey });
1829+
return true;
1830+
}
1831+
catch (error) {
1832+
done(error);
1833+
return false;
1834+
}
1835+
})
1836+
.matchHeader('user-agent', new RegExp('OpenTok-Node-SDK/' + pkg.version))
1837+
.post('/v2/project/123456/connect', {
1838+
sessionId: this.sessionId,
1839+
token: this.token,
1840+
websocket: {
1841+
uri: goodWebsocketUri,
1842+
bidirectional: true
1843+
}
1844+
})
1845+
.reply(200, {
1846+
id: 'CONFERENCEID',
1847+
connectionId: 'CONNECTIONID'
1848+
});
1849+
this.opentok.websocketConnect(
1850+
this.sessionId,
1851+
this.token,
1852+
goodWebsocketUri,
1853+
{ bidirectional: true },
1854+
function (err, connect) {
1855+
if (err) {
1856+
done(err);
1857+
return;
1858+
}
1859+
expect(connect.id).to.equal('CONFERENCEID');
1860+
expect(connect.connectionId).to.equal('CONNECTIONID');
1861+
scope.done();
1862+
done(err);
1863+
}
1864+
);
1865+
});
1866+
18241867
it('complains if sessionId, token, Websocket URI, or callback are missing or invalid', function () {
18251868
// Missing all params
18261869
expect(function () {

0 commit comments

Comments
 (0)