-
Notifications
You must be signed in to change notification settings - Fork 0
mute all #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
mute all #1
Changes from all commits
f192bf2
10ae3b8
a6109a9
0300397
96030a8
c5349bf
5fd5d77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* global require, exports */ | ||
/* jshint strict:false, eqnull:true */ | ||
|
||
var request = require('request'); | ||
var errors = require('./errors'); | ||
var pkg = require('../package.json'); | ||
var _ = require('lodash'); | ||
var generateJwt = require('./generateJwt'); | ||
|
||
var api = function (config, method, session, stream, body, callback) { | ||
var rurl = config.apiEndpoint + '/v2/project/' + config.apiKey + '/session/' + session; | ||
if (stream) { | ||
rurl += '/stream/' + stream; | ||
} | ||
rurl += '/mute'; | ||
request.defaults(_.pick(config, 'proxy', 'timeout'))({ | ||
url: rurl, | ||
method: method, | ||
headers: { | ||
'X-OPENTOK-AUTH': generateJwt(config), | ||
'User-Agent': 'OpenTok-Node-SDK/' + pkg.version + | ||
(config.uaAddendum ? ' ' + config.uaAddendum : '') | ||
}, | ||
json: body | ||
}, callback); | ||
}; | ||
|
||
handleForceMute = function (config, sessionId, streamId, excludedStreamIds = null, callback) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Linting error here. The codebase is not using ES6 (and default parameters). And there are other linting errors. Please run |
||
if (typeof callback !== 'function') { | ||
throw (new errors.ArgumentError('No callback given to signal')); | ||
} | ||
if (sessionId == null) { | ||
return callback(new errors.ArgumentError('No sessionId or connectionId given to signal')); | ||
} | ||
let body=null; | ||
if(excludedStreamIds){ | ||
body = JSON.stringify({excluded:excludedStreamIds}); | ||
} | ||
elishaikatz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return api(config, 'POST', sessionId, streamId, body, function (err, response) { | ||
if (err || Math.floor(response.statusCode / 100) !== 2) { | ||
elishaikatz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (response && response.statusCode === 403) { | ||
callback(new errors.AuthError('Invalid API key or secret')); | ||
} | ||
else if (response && response.statusCode === 404) { | ||
callback(new errors.ForceMuteError('Session or Stream not found')); | ||
} | ||
else { | ||
callback(new errors.RequestError('Unexpected response from OpenTok')); | ||
} | ||
} | ||
else { | ||
callback(null); | ||
} | ||
}); | ||
}; | ||
|
||
exports.forceMute = function(config, sessionId, streamId, callback) { | ||
return this.handleForceMute(config,sessionId,streamId,null,callback); | ||
} | ||
|
||
exports.forceMuteAll = function(config, sessionId, excludedStreamIds=null, callback) { | ||
return this.handleForceMute(config,sessionId,null,excludedStreamIds,callback); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ var archiving = require('./archiving'); | |
var Broadcast = require('./broadcast'); | ||
var SipInterconnect = require('./sipInterconnect'); | ||
var moderation = require('./moderation'); | ||
var muteModeration = require('./muteModeration'); | ||
var signaling = require('./signaling'); | ||
var errors = require('./errors'); | ||
var callbacks = require('./callbacks'); | ||
|
@@ -798,6 +799,54 @@ OpenTok = function (apiKey, apiSecret, env) { | |
*/ | ||
this.forceDisconnect = moderation.forceDisconnect.bind(null, apiConfig); | ||
|
||
/** | ||
* Mutes a participant from an OpenTok session. | ||
* | ||
* @param sessionId The session ID for the OpenTok session that the client you want | ||
* to mute is connected to. | ||
* | ||
* @param streamId The stream ID of the client you want to mute. | ||
* | ||
* @param callback {Function} The function to call upon completing the operation. Two arguments | ||
* are passed to the function: | ||
Comment on lines
+810
to
+811
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the second argument? |
||
* | ||
* <ul> | ||
* | ||
* <li> | ||
* <code>error</code> — An error object (if the call to the method fails). | ||
* </li> | ||
* | ||
* </ul> | ||
* | ||
* @method #forceMute | ||
* @memberof OpenTok | ||
*/ | ||
this.forceMute = muteModeration.forceMute.bind(null, apiConfig); | ||
|
||
/** | ||
* Mutes a participant from an OpenTok session. | ||
* | ||
* @param sessionId The session ID for the OpenTok session that the client you want | ||
* to mute is connected to. | ||
* | ||
* @param excludedSteamIds (optional) A list of stream Ids to exclude from mute. | ||
* | ||
* @param callback {Function} The function to call upon completing the operation. Two arguments | ||
* are passed to the function: | ||
Comment on lines
+834
to
+835
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two arguments? |
||
* | ||
* <ul> | ||
* | ||
* <li> | ||
* <code>error</code> — An error object (if the call to the method fails). | ||
* </li> | ||
* | ||
* </ul> | ||
* | ||
* @method #forceMuteAll | ||
* @memberof OpenTok | ||
*/ | ||
this.forceMuteAll = muteModeration.forceMuteAll.bind(null, apiConfig); | ||
|
||
/** | ||
* Gets info about a stream. The stream must be an active stream in an OpenTok session. | ||
* | ||
|
@@ -1157,7 +1206,7 @@ OpenTok.prototype.createSession = function (opts, callback) { | |
* | ||
* <li> <code>'moderator'</code> — In addition to the privileges granted to a | ||
* publisher, in clients using the OpenTok.js library, a moderator can call the | ||
* <code>forceUnpublish()</code> and <code>forceDisconnect()</code> method of the | ||
* <code>forceMute</code>, <code>forceMuteAll()</code>, <code>forceUnpublish()</code> and <code>forceDisconnect()</code> method of the | ||
* Session object.</li> | ||
* </ul> | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
var expect = require('chai').expect; | ||
var nock = require('nock'); | ||
|
||
// Subject | ||
var OpenTok = require('../lib/opentok.js'); | ||
|
||
describe('MuteModeration', function () { | ||
var opentok = new OpenTok('APIKEY', 'APISECRET'); | ||
var SESSIONID = '1_MX4xMDB-MTI3LjAuMC4xflR1ZSBKYW4gMjggMTU6NDg6NDAgUFNUIDIwMTR-MC43NjAyOTYyfg'; | ||
var STREAMID = '4072fe0f-d499-4f2f-8237-64f5a9d936f5'; | ||
|
||
afterEach(function () { | ||
nock.cleanAll(); | ||
}); | ||
|
||
describe('forceMute', function () { | ||
function mockRequest(status, body) { | ||
var url = '/v2/project/APIKEY/session/' + SESSIONID + '/stream/' + STREAMID +'/mute'; | ||
nock('https://api.opentok.com:443') | ||
.post(url) | ||
.reply(status, body, { | ||
server: 'nginx', | ||
date: 'Fri, 31 Jan 2014 06:32:16 GMT', | ||
connection: 'keep-alive' | ||
}); | ||
} | ||
|
||
describe('valid responses', function () { | ||
beforeEach(function () { | ||
mockRequest(204, ''); | ||
}); | ||
|
||
it('should not return an error', function (done) { | ||
opentok.forceMute(SESSIONID, STREAMID, function (err) { | ||
expect(err).to.be.null; | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return an error for empty stream Id', function (done) { | ||
opentok.forceMute(SESSIONID, null, function (err) { | ||
expect(err).to.not.be.null; | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return an error for empty session', function (done) { | ||
opentok.forceMute(null, STREAMID, function (err) { | ||
expect(err).to.not.be.null; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('invalid responses', function () { | ||
var errors = [400, 403, 404, 500]; | ||
var i; | ||
function test(error) { | ||
it('should fail for status ' + error, function (done) { | ||
mockRequest(error, ''); | ||
|
||
opentok.forceMute(SESSIONID, STREAMID, function (err) { | ||
expect(err).to.not.be.null; | ||
done(); | ||
}); | ||
}); | ||
} | ||
for (i = 0; i < errors.length; i++) { | ||
test(errors[i]); | ||
} | ||
}); | ||
}); | ||
describe('forceMuteAll', function () { | ||
function mockRequest(status, body) { | ||
var url = '/v2/project/APIKEY/session/' + SESSIONID +'/mute'; | ||
nock('https://api.opentok.com:443') | ||
.post(url) | ||
.reply(status, body, { | ||
server: 'nginx', | ||
date: 'Fri, 31 Jan 2014 06:32:16 GMT', | ||
connection: 'keep-alive' | ||
}); | ||
} | ||
const excludedSteamIds = JSON.parse('{"1":1, "2":2}'); | ||
describe('valid responses', function () { | ||
beforeEach(function () { | ||
mockRequest(204, ''); | ||
}); | ||
|
||
it('should not return an error', function (done) { | ||
opentok.forceMuteAll(SESSIONID, excludedSteamIds, function (err) { | ||
expect(err).to.be.null; | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should not return an error for empty stream Id list', function (done) { | ||
opentok.forceMuteAll(SESSIONID, null, function (err) { | ||
expect(err).to.be.null; | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return an error for empty session', function (done) { | ||
opentok.forceMuteAll(null, excludedSteamIds, function (err) { | ||
expect(err).to.not.be.null; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('invalid responses', function () { | ||
var errors = [400, 403, 404, 500]; | ||
var i; | ||
function test(error) { | ||
it('should fail for status ' + error, function (done) { | ||
mockRequest(error, ''); | ||
|
||
opentok.forceMuteAll(SESSIONID, excludedSteamIds, function (err) { | ||
expect(err).to.not.be.null; | ||
done(); | ||
}); | ||
}); | ||
} | ||
for (i = 0; i < errors.length; i++) { | ||
test(errors[i]); | ||
} | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.