opentok-node icon indicating copy to clipboard operation
opentok-node copied to clipboard

listStreams: TypeError: Cannot read properties of undefined (reading 'map')

Open tapz opened this issue 1 year ago • 1 comments

The optional chaining is not done properly in the callback and causes a crash.

TypeError: Cannot read properties of undefined (reading 'map')
    at callback (/node_modules/opentok/lib/client.js:413:21)
    at /node_modules/opentok/lib/client.js:107:7

FIX: ?.map((steam)) -> ?.map?.((stream))

Client.prototype.listStreams = function listStreams(sessionId, cb) {
  const url = this.c.apiUrl
    + this.c.endpoints.listStreams
      .replace(/<%apiKey%>/g, this.c.apiKey)
      .replace(/<%sessionId%>/g, sessionId);
  api({
    url: url,
    method: 'GET',
    headers: this.generateHeaders(),
    callback: (err, body) => {
      cb(err, body?.items?.map((stream) => new Stream(JSON.stringify(stream))) || [])
    },
  });
};

tapz avatar Mar 21 '24 13:03 tapz

Would be nice if you could test changes even once before publishing a new version.

tapz avatar Mar 21 '24 13:03 tapz

@tapz apologizes for this issue. There was an update made to the API that caused this issue to happen in the back end. The SDK now has guards for this and the API team will work on preventing this issue from happening going forward

manchuck avatar Jun 03 '24 15:06 manchuck