diff --git a/lib/client.js b/lib/client.js index bee14713..9983685c 100644 --- a/lib/client.js +++ b/lib/client.js @@ -410,7 +410,7 @@ Client.prototype.listStreams = function listStreams(sessionId, cb) { method: 'GET', headers: this.generateHeaders(), callback: (err, body) => { - cb(err, body?.items.map((stream) => new Stream(JSON.stringify(stream)))) + cb(err, body?.items?.map((stream) => new Stream(JSON.stringify(stream))) || []) }, }); }; diff --git a/test/opentok-test.js b/test/opentok-test.js index 7534d585..93b03610 100644 --- a/test/opentok-test.js +++ b/test/opentok-test.js @@ -2292,6 +2292,18 @@ describe('listStreams', function () { }); }); + it('should not error when items is missing in response', function (done) { + nock('https://api.opentok.com') + .get('/v2/project/123456/session/' + SESSIONID + '/stream') + .reply(200, { count: 0 }, { 'Content-Type': 'application/json' }); + + opentok.listStreams(SESSIONID, function (err, streams) { + expect(err).to.be.null; + expect(streams).to.empty; + done(); + }); + }); + it('should return an error if sessionId is null', function (done) { opentok.listStreams(null, function (err, streams) { expect(err).to.not.be.null;