Skip to content

Commit

Permalink
Add incoming.allow to AccessToken VoiceGrant (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-rowland authored and codejudas committed Apr 13, 2018
1 parent 51e3cab commit 01878d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/jwt/AccessToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ _.extend(SyncGrant.prototype, {
/**
* @constructor
* @param {object} options - ...
* @param {boolean} options.incomingAllow - Whether or not this endpoint is allowed to receive incoming calls as grants.identity
* @param {string} options.outgoingApplicationSid - application sid to call when placing outgoing call
* @param {object} options.outgoingApplicationParams - request params to pass to the application
* @param {string} options.pushCredentialSid - Push Credential Sid to use when registering to receive incoming call notifications
Expand All @@ -162,6 +163,7 @@ _.extend(SyncGrant.prototype, {
*/
function VoiceGrant(options) {
options = options || {};
this.incomingAllow = options.incomingAllow;
this.outgoingApplicationSid = options.outgoingApplicationSid;
this.outgoingApplicationParams = options.outgoingApplicationParams;
this.pushCredentialSid = options.pushCredentialSid;
Expand All @@ -172,6 +174,10 @@ _.extend(VoiceGrant.prototype, {
key: 'voice',
toPayload: function() {
var grant = {};
if (this.incomingAllow === true) {
grant.incoming = { allow: true };
}

if (this.outgoingApplicationSid) {
grant.outgoing = {};
grant.outgoing.application_sid = this.outgoingApplicationSid;
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.

10 changes: 10 additions & 0 deletions spec/unit/jwt/AccessToken.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,16 @@ describe('AccessToken', function() {
endpoint_id: 'id'
});
});

it('should set incoming.allow if incomingAllow === true', function() {
var grant = new twilio.jwt.AccessToken.VoiceGrant({ incomingAllow: true });
expect(grant.toPayload()).toEqual({ incoming: { allow: true } });
});

it('should not set incoming.allow if incomingAllow !== true', function() {
var grant = new twilio.jwt.AccessToken.VoiceGrant({ incomingAllow: 'foo' });
expect(grant.toPayload()).toEqual({ });
});
});

describe('VideoGrant', function() {
Expand Down

0 comments on commit 01878d0

Please sign in to comment.