Skip to content

Commit

Permalink
Merge pull request #195 from opentok/dev
Browse files Browse the repository at this point in the history
v2.8.1
  • Loading branch information
Manik Sachdeva authored Feb 22, 2019
2 parents 33c47a9 + 339cd4c commit d0eb02e
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 10 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ var broadcastOptions = {
}]
},
maxDuration: 5400,
resolution: '640x480'
resolution: '640x480',
layout: {
type: 'verticalPresentation'
}
};
opentok.startBroadcast(sessionId, options, function(error, broadcast) {
opentok.startBroadcast(sessionId, broadcastOptions, function(error, broadcast) {
if (error) {
return console.log(error);
}
Expand All @@ -298,7 +298,7 @@ broadcast ID (the `id` property of the Broadcast object) as the first parameter.
parameter is the callback function:

```javascript
opentok.stopBroadcast(sessionId, function(error, broadcast) {
opentok.stopBroadcast(broadcastId, function(error, broadcast) {
if (error) {
return console.log(error);
}
Expand Down Expand Up @@ -371,6 +371,10 @@ feature. This requires a SIP URI, the session ID you wish to add the audio-only
token to connect to that session ID.

```javascript
var options = {
from: '15551115555',
secure: true,
};
opentok.dial(sessionId, token, sipUri, options, function (error, sipCall) {
if (error) return console.log("error: ", error);

Expand Down
13 changes: 12 additions & 1 deletion lib/opentok.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ OpenTok = function (apiKey, apiSecret, env) {
*
* @param sipUri The sip URI the SIP Interconnect feature will dial.
*
* @param options {Object} An optional options object with the following properties:
* @param options {Object} An optional options object with the following properties (all of which are optional):
* <p>
* <ul>
* <li>
Expand All @@ -839,6 +839,12 @@ OpenTok = function (apiKey, apiSecret, env) {
* <code>secure</code> (Boolean) &mdash; Whether the SIP media streams should be transmitted
* encrypted or not.
* </li>
* <li>
* <code>from</code> (String) &mdash; The number or string that will be sent to the final SIP number as the caller. It must be a string in the form of
* <code>[email protected]</code>, where <code>from</code> can be a string or a number.
* If <code>from</code> is set to a number (for example, <code>"[email protected]"</code>), it will show up as the incoming number on PSTN phones.
* If <code>from</code> is undefined or set to a string (for example, <code>"[email protected]"</code>), <code>+00000000</code> will show up as the incoming number on PSTN phones.
* </li>
* </ul>
*
* @return A {@link SipInterconnect} object with the following properties:
Expand Down Expand Up @@ -890,6 +896,11 @@ OpenTok.prototype.dial = function (sessionId, token, sipUri, options, callback)
if (options.secure) {
body.sip.secure = !!options.secure;
}

if (options.from) {
body.sip.from = String(options.from);
}

this.client.dial(body, function (err, json) {
if (err) return callback(new Error('Failed to dial endpoint. ' + err));
return callback(null, new SipInterconnect(self, json));
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "opentok",
"description": "OpenTok server-side SDK",
"version": "2.8.0",
"version": "2.8.1",
"homepage": "https://github.com/opentok/opentok-node",
"repository": {
"type": "git",
Expand Down
7 changes: 5 additions & 2 deletions sample/Broadcast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,17 @@ is invoked:
```javascript
app.get('/broadcast', function (req, res) {
var broadcastId = app.get('broadcastId');
opentok.getBroadcast(broadcastId, function (err, broadcast) {
if (!broadcastId) {
return res.send(404, 'Broadcast not in progress.');
}
return opentok.getBroadcast(broadcastId, function (err, broadcast) {
if (err) {
return res.send(500, 'Could not get broadcast ' + broadcastId + '. error=' + err.message);
}
if (broadcast.status === 'started') {
return res.redirect(broadcast.broadcastUrls.hls);
}
return res.send(500, 'Broadcast not in progress.');
return res.send(404, 'Broadcast not in progress.');
});
});
```
Expand Down
7 changes: 5 additions & 2 deletions sample/Broadcast/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ app.get('/participant', function (req, res) {

app.get('/broadcast', function (req, res) {
var broadcastId = app.get('broadcastId');
opentok.getBroadcast(broadcastId, function (err, broadcast) {
if (!broadcastId) {
return res.send(404, 'Broadcast not in progress.');
}
return opentok.getBroadcast(broadcastId, function (err, broadcast) {
if (err) {
return res.send(500, 'Could not get broadcast ' + broadcastId + '. error=' + err.message);
}
if (broadcast.status === 'started') {
return res.redirect(broadcast.broadcastUrls.hls);
}
return res.send(500, 'Broadcast not in progress.');
return res.send(404, 'Broadcast not in progress.');
});
});

Expand Down
42 changes: 42 additions & 0 deletions test/opentok-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,48 @@ describe('#dial', function () {
);
});

it('dials a SIP gateway and adds a from field', function (done) {
var scope = nock('https://api.opentok.com:443')
.matchHeader('x-opentok-auth', function (value) {
try {
jwt.verify(value, apiSecret, { issuer: apiKey });
return true;
}
catch (error) {
done(error);
return false;
}
})
.matchHeader('user-agent', new RegExp('OpenTok-Node-SDK/' + pkg.version))
.post('/v2/project/123456/dial', {
sessionId: this.sessionId,
token: this.token,
sip: {
uri: goodSipUri,
from: '15551115555'
}
})
.reply(200, {
id: 'CONFERENCEID',
connectionId: 'CONNECTIONID',
streamId: 'STREAMID'
});
this.opentok.dial(
this.sessionId, this.token, goodSipUri, { from: '15551115555' },
function (err, sipCall) {
if (err) {
done(err);
return;
}
expect(sipCall).to.be.an.instanceof(SipInterconnect);
expect(sipCall.id).to.equal('CONFERENCEID');
expect(sipCall.streamId).to.equal('STREAMID');
expect(sipCall.connectionId).to.equal('CONNECTIONID');
done();
}
);
});

it('complains if sessionId, token, SIP URI, or callback are missing or invalid', function () {
// Missing all params
expect(function () {
Expand Down

0 comments on commit d0eb02e

Please sign in to comment.