Skip to content
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

Fixing stop broadcast #333

Merged
merged 6 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ Client.prototype.stopBroadcast = function (broadcastId, cb) {
method: 'POST',
body: { },
headers: this.generateHeaders(),
callback: cb,
callback: (err, json) => {
const responseText = typeof json === 'object' ? JSON.stringify(json) : json;
cb(err, responseText);
},
});
};

Expand Down
13 changes: 11 additions & 2 deletions test/opentok-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1895,15 +1895,15 @@ describe('#stopBroadcast', function () {
var opentok = new OpenTok('APIKEY', 'APISECRET');
var BROADCAST_ID = 'BROADCAST_ID';

function mockStopBroadcastRequest(broadcastId, status) {
function mockStopBroadcastRequest(broadcastId, status, jsonResponse) {
var body;
if (status) {
body = JSON.stringify({
message: 'error message'
});
}
else {
body = JSON.stringify(mockBroadcastObject);
body = jsonResponse ? JSON.stringify(mockBroadcastObject) : mockBroadcastObject;
}
nock('https://api.opentok.com')
.post('/v2/project/APIKEY/broadcast/' + broadcastId + '/stop')
Expand All @@ -1915,6 +1915,15 @@ describe('#stopBroadcast', function () {
});

it('succeeds given valid parameters', function (done) {
mockStopBroadcastRequest(BROADCAST_ID, null, true);
opentok.stopBroadcast(BROADCAST_ID, function (err, broadcast) {
expect(err).to.be.null;
validateBroadcastObject(broadcast);
done();
});
});

it('succeeds with non-json body response', function (done) {
mockStopBroadcastRequest(BROADCAST_ID);
opentok.stopBroadcast(BROADCAST_ID, function (err, broadcast) {
expect(err).to.be.null;
Expand Down
Loading