You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RTC.js 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /* global __filename */
  2. import DataChannels from './DataChannels';
  3. import { getLogger } from 'jitsi-meet-logger';
  4. import GlobalOnErrorHandler from '../util/GlobalOnErrorHandler';
  5. import JitsiLocalTrack from './JitsiLocalTrack.js';
  6. import JitsiTrackError from '../../JitsiTrackError';
  7. import * as JitsiTrackErrors from '../../JitsiTrackErrors';
  8. import Listenable from '../util/Listenable';
  9. import * as MediaType from '../../service/RTC/MediaType';
  10. import RTCEvents from '../../service/RTC/RTCEvents.js';
  11. import RTCUtils from './RTCUtils.js';
  12. import TraceablePeerConnection from './TraceablePeerConnection';
  13. import VideoType from '../../service/RTC/VideoType';
  14. const logger = getLogger(__filename);
  15. let rtcTrackIdCounter = 0;
  16. /**
  17. *
  18. * @param tracksInfo
  19. * @param options
  20. */
  21. function createLocalTracks(tracksInfo, options) {
  22. const newTracks = [];
  23. let deviceId = null;
  24. tracksInfo.forEach(trackInfo => {
  25. if (trackInfo.mediaType === MediaType.AUDIO) {
  26. deviceId = options.micDeviceId;
  27. } else if (trackInfo.videoType === VideoType.CAMERA) {
  28. deviceId = options.cameraDeviceId;
  29. }
  30. rtcTrackIdCounter += 1;
  31. const localTrack
  32. = new JitsiLocalTrack(
  33. rtcTrackIdCounter,
  34. trackInfo.stream,
  35. trackInfo.track,
  36. trackInfo.mediaType,
  37. trackInfo.videoType,
  38. trackInfo.resolution,
  39. deviceId,
  40. options.facingMode);
  41. newTracks.push(localTrack);
  42. });
  43. return newTracks;
  44. }
  45. /**
  46. *
  47. */
  48. export default class RTC extends Listenable {
  49. /**
  50. *
  51. * @param conference
  52. * @param options
  53. */
  54. constructor(conference, options = {}) {
  55. super();
  56. this.conference = conference;
  57. /**
  58. * A map of active <tt>TraceablePeerConnection</tt>.
  59. * @type {Map.<number, TraceablePeerConnection>}
  60. */
  61. this.peerConnections = new Map();
  62. /**
  63. * The counter used to generated id numbers assigned to peer connections
  64. * @type {number}
  65. */
  66. this.peerConnectionIdCounter = 1;
  67. this.localTracks = [];
  68. this.options = options;
  69. // A flag whether we had received that the data channel had opened
  70. // we can get this flag out of sync if for some reason data channel got
  71. // closed from server, a desired behaviour so we can see errors when
  72. // this happen
  73. this.dataChannelsOpen = false;
  74. // Defines the last N endpoints list. It can be null or an array once
  75. // initialised with a datachannel last N event.
  76. // @type {Array<string>|null}
  77. this._lastNEndpoints = null;
  78. // The last N change listener.
  79. this._lastNChangeListener = null;
  80. // Switch audio output device on all remote audio tracks. Local audio
  81. // tracks handle this event by themselves.
  82. if (RTCUtils.isDeviceChangeAvailable('output')) {
  83. RTCUtils.addListener(RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
  84. deviceId => {
  85. const remoteAudioTracks
  86. = this.getRemoteTracks(MediaType.AUDIO);
  87. for (const track of remoteAudioTracks) {
  88. track.setAudioOutput(deviceId);
  89. }
  90. });
  91. }
  92. }
  93. /**
  94. * Creates the local MediaStreams.
  95. * @param {Object} [options] optional parameters
  96. * @param {Array} options.devices the devices that will be requested
  97. * @param {string} options.resolution resolution constraints
  98. * @param {bool} options.dontCreateJitsiTrack if <tt>true</tt> objects with
  99. * the following structure {stream: the Media Stream, type: "audio" or
  100. * "video", videoType: "camera" or "desktop"} will be returned trough the
  101. * Promise, otherwise JitsiTrack objects will be returned.
  102. * @param {string} options.cameraDeviceId
  103. * @param {string} options.micDeviceId
  104. * @returns {*} Promise object that will receive the new JitsiTracks
  105. */
  106. static obtainAudioAndVideoPermissions(options) {
  107. return RTCUtils.obtainAudioAndVideoPermissions(options).then(
  108. tracksInfo => {
  109. const tracks = createLocalTracks(tracksInfo, options);
  110. return tracks.some(track => !track._isReceivingData())
  111. ? Promise.reject(
  112. new JitsiTrackError(
  113. JitsiTrackErrors.NO_DATA_FROM_SOURCE))
  114. : tracks;
  115. });
  116. }
  117. /**
  118. * Initializes the data channels of this instance.
  119. * @param peerconnection the associated PeerConnection.
  120. */
  121. initializeDataChannels(peerconnection) {
  122. if (this.options.config.openSctp) {
  123. this.dataChannels = new DataChannels(peerconnection,
  124. this.eventEmitter);
  125. this._dataChannelOpenListener = () => {
  126. // mark that dataChannel is opened
  127. this.dataChannelsOpen = true;
  128. // when the data channel becomes available, tell the bridge
  129. // about video selections so that it can do adaptive simulcast,
  130. // we want the notification to trigger even if userJid
  131. // is undefined, or null.
  132. // XXX why do we not do the same for pinned endpoints?
  133. try {
  134. this.dataChannels.sendSelectedEndpointMessage(
  135. this.selectedEndpoint);
  136. } catch (error) {
  137. GlobalOnErrorHandler.callErrorHandler(error);
  138. logger.error('Cannot sendSelectedEndpointMessage ',
  139. this.selectedEndpoint, '. Error: ', error);
  140. }
  141. this.removeListener(RTCEvents.DATA_CHANNEL_OPEN,
  142. this._dataChannelOpenListener);
  143. this._dataChannelOpenListener = null;
  144. };
  145. this.addListener(RTCEvents.DATA_CHANNEL_OPEN,
  146. this._dataChannelOpenListener);
  147. // Add Last N change listener.
  148. this._lastNChangeListener = lastNEndpoints => {
  149. this._lastNEndpoints = lastNEndpoints;
  150. };
  151. this.addListener(RTCEvents.LASTN_ENDPOINT_CHANGED,
  152. this._lastNChangeListener);
  153. }
  154. }
  155. /**
  156. * Should be called when current media session ends and after the
  157. * PeerConnection has been closed using PeerConnection.close() method.
  158. */
  159. onCallEnded() {
  160. if (this.dataChannels) {
  161. // DataChannels are not explicitly closed as the PeerConnection
  162. // is closed on call ended which triggers data channel onclose
  163. // events. The reference is cleared to disable any logic related
  164. // to the data channels.
  165. this.dataChannels = null;
  166. this.dataChannelsOpen = false;
  167. }
  168. }
  169. /**
  170. * Elects the participant with the given id to be the selected participant
  171. * in order to always receive video for this participant (even when last n
  172. * is enabled).
  173. * If there is no data channel we store it and send it through the channel
  174. * once it is created.
  175. * @param id {string} the user id.
  176. * @throws NetworkError or InvalidStateError or Error if the operation
  177. * fails.
  178. */
  179. selectEndpoint(id) {
  180. // cache the value if channel is missing, till we open it
  181. this.selectedEndpoint = id;
  182. if (this.dataChannels && this.dataChannelsOpen) {
  183. this.dataChannels.sendSelectedEndpointMessage(id);
  184. }
  185. }
  186. /**
  187. * Elects the participant with the given id to be the pinned participant in
  188. * order to always receive video for this participant (even when last n is
  189. * enabled).
  190. * @param id {string} the user id
  191. * @throws NetworkError or InvalidStateError or Error if the operation
  192. * fails.
  193. */
  194. pinEndpoint(id) {
  195. if (this.dataChannels) {
  196. this.dataChannels.sendPinnedEndpointMessage(id);
  197. } else {
  198. // FIXME: cache value while there is no data channel created
  199. // and send the cached state once channel is created
  200. throw new Error('Data channels support is disabled!');
  201. }
  202. }
  203. /**
  204. *
  205. * @param eventType
  206. * @param listener
  207. */
  208. static addListener(eventType, listener) {
  209. RTCUtils.addListener(eventType, listener);
  210. }
  211. /**
  212. *
  213. * @param eventType
  214. * @param listener
  215. */
  216. static removeListener(eventType, listener) {
  217. RTCUtils.removeListener(eventType, listener);
  218. }
  219. /**
  220. *
  221. */
  222. static isRTCReady() {
  223. return RTCUtils.isRTCReady();
  224. }
  225. /**
  226. *
  227. * @param options
  228. */
  229. static init(options = {}) {
  230. this.options = options;
  231. return RTCUtils.init(this.options);
  232. }
  233. /**
  234. *
  235. */
  236. static getDeviceAvailability() {
  237. return RTCUtils.getDeviceAvailability();
  238. }
  239. /* eslint-disable max-params */
  240. /**
  241. * Creates new <tt>TraceablePeerConnection</tt>
  242. * @param {SignalingLayer} signaling the signaling layer that will
  243. * provide information about the media or participants which is not carried
  244. * over SDP.
  245. * @param {Object} iceConfig an object describing the ICE config like
  246. * defined in the WebRTC specification.
  247. * @param {boolean} isP2P indicates whether or not the new TPC will be used
  248. * in a peer to peer type of session
  249. * @param {Object} options the config options
  250. * @param {boolean} options.disableSimulcast if set to 'true' will disable
  251. * the simulcast
  252. * @param {boolean} options.disableRtx if set to 'true' will disable the RTX
  253. * @param {boolean} options.preferH264 if set to 'true' H264 will be
  254. * preferred over other video codecs.
  255. * @return {TraceablePeerConnection}
  256. */
  257. createPeerConnection(signaling, iceConfig, isP2P, options) {
  258. const newConnection
  259. = new TraceablePeerConnection(
  260. this,
  261. this.peerConnectionIdCounter,
  262. signaling, iceConfig, RTC.getPCConstraints(), isP2P, options);
  263. this.peerConnections.set(newConnection.id, newConnection);
  264. this.peerConnectionIdCounter += 1;
  265. return newConnection;
  266. }
  267. /* eslint-enable max-params */
  268. /**
  269. * Removed given peer connection from this RTC module instance.
  270. * @param {TraceablePeerConnection} traceablePeerConnection
  271. * @return {boolean} <tt>true</tt> if the given peer connection was removed
  272. * successfully or <tt>false</tt> if there was no peer connection mapped in
  273. * this RTC instance.
  274. */
  275. _removePeerConnection(traceablePeerConnection) {
  276. const id = traceablePeerConnection.id;
  277. if (this.peerConnections.has(id)) {
  278. // NOTE Remote tracks are not removed here.
  279. this.peerConnections.delete(id);
  280. return true;
  281. }
  282. return false;
  283. }
  284. /**
  285. *
  286. * @param track
  287. */
  288. addLocalTrack(track) {
  289. if (!track) {
  290. throw new Error('track must not be null nor undefined');
  291. }
  292. this.localTracks.push(track);
  293. track.conference = this.conference;
  294. }
  295. /**
  296. * Get local video track.
  297. * @returns {JitsiLocalTrack|undefined}
  298. */
  299. getLocalVideoTrack() {
  300. const localVideo = this.getLocalTracks(MediaType.VIDEO);
  301. return localVideo.length ? localVideo[0] : undefined;
  302. }
  303. /**
  304. * Get local audio track.
  305. * @returns {JitsiLocalTrack|undefined}
  306. */
  307. getLocalAudioTrack() {
  308. const localAudio = this.getLocalTracks(MediaType.AUDIO);
  309. return localAudio.length ? localAudio[0] : undefined;
  310. }
  311. /**
  312. * Returns the local tracks of the given media type, or all local tracks if
  313. * no specific type is given.
  314. * @param {MediaType} [mediaType] optional media type filter
  315. * (audio or video).
  316. */
  317. getLocalTracks(mediaType) {
  318. let tracks = this.localTracks.slice();
  319. if (mediaType !== undefined) {
  320. tracks = tracks.filter(
  321. track => track.getType() === mediaType);
  322. }
  323. return tracks;
  324. }
  325. /**
  326. * Obtains all remote tracks currently known to this RTC module instance.
  327. * @param {MediaType} [mediaType] the remote tracks will be filtered
  328. * by their media type if this argument is specified.
  329. * @return {Array<JitsiRemoteTrack>}
  330. */
  331. getRemoteTracks(mediaType) {
  332. let remoteTracks = [];
  333. for (const tpc of this.peerConnections.values()) {
  334. const pcRemoteTracks = tpc.getRemoteTracks(undefined, mediaType);
  335. if (pcRemoteTracks) {
  336. remoteTracks = remoteTracks.concat(pcRemoteTracks);
  337. }
  338. }
  339. return remoteTracks;
  340. }
  341. /**
  342. * Set mute for all local audio streams attached to the conference.
  343. * @param value the mute value
  344. * @returns {Promise}
  345. */
  346. setAudioMute(value) {
  347. const mutePromises = [];
  348. this.getLocalTracks(MediaType.AUDIO).forEach(audioTrack => {
  349. // this is a Promise
  350. mutePromises.push(value ? audioTrack.mute() : audioTrack.unmute());
  351. });
  352. // We return a Promise from all Promises so we can wait for their
  353. // execution.
  354. return Promise.all(mutePromises);
  355. }
  356. /**
  357. *
  358. * @param track
  359. */
  360. removeLocalTrack(track) {
  361. const pos = this.localTracks.indexOf(track);
  362. if (pos === -1) {
  363. return;
  364. }
  365. this.localTracks.splice(pos, 1);
  366. }
  367. /**
  368. * Removes all JitsiRemoteTracks associated with given MUC nickname
  369. * (resource part of the JID). Returns array of removed tracks.
  370. *
  371. * @param {string} owner - The resource part of the MUC JID.
  372. * @returns {JitsiRemoteTrack[]}
  373. */
  374. removeRemoteTracks(owner) {
  375. let removedTracks = [];
  376. for (const tpc of this.peerConnections.values()) {
  377. const pcRemovedTracks = tpc.removeRemoteTracks(owner);
  378. removedTracks = removedTracks.concat(pcRemovedTracks);
  379. }
  380. logger.debug(
  381. `Removed remote tracks for ${owner}`
  382. + ` count: ${removedTracks.length}`);
  383. return removedTracks;
  384. }
  385. /**
  386. *
  387. */
  388. static getPCConstraints() {
  389. return RTCUtils.pcConstraints;
  390. }
  391. /**
  392. *
  393. * @param elSelector
  394. * @param stream
  395. */
  396. static attachMediaStream(elSelector, stream) {
  397. return RTCUtils.attachMediaStream(elSelector, stream);
  398. }
  399. /**
  400. *
  401. * @param stream
  402. */
  403. static getStreamID(stream) {
  404. return RTCUtils.getStreamID(stream);
  405. }
  406. /**
  407. * Returns true if retrieving the the list of input devices is supported
  408. * and false if not.
  409. */
  410. static isDeviceListAvailable() {
  411. return RTCUtils.isDeviceListAvailable();
  412. }
  413. /**
  414. * Returns true if changing the input (camera / microphone) or output
  415. * (audio) device is supported and false if not.
  416. * @params {string} [deviceType] - type of device to change. Default is
  417. * undefined or 'input', 'output' - for audio output device change.
  418. * @returns {boolean} true if available, false otherwise.
  419. */
  420. static isDeviceChangeAvailable(deviceType) {
  421. return RTCUtils.isDeviceChangeAvailable(deviceType);
  422. }
  423. /**
  424. * Returns currently used audio output device id, '' stands for default
  425. * device
  426. * @returns {string}
  427. */
  428. static getAudioOutputDevice() {
  429. return RTCUtils.getAudioOutputDevice();
  430. }
  431. /**
  432. * Returns list of available media devices if its obtained, otherwise an
  433. * empty array is returned/
  434. * @returns {Array} list of available media devices.
  435. */
  436. static getCurrentlyAvailableMediaDevices() {
  437. return RTCUtils.getCurrentlyAvailableMediaDevices();
  438. }
  439. /**
  440. * Returns event data for device to be reported to stats.
  441. * @returns {MediaDeviceInfo} device.
  442. */
  443. static getEventDataForActiveDevice(device) {
  444. return RTCUtils.getEventDataForActiveDevice(device);
  445. }
  446. /**
  447. * Sets current audio output device.
  448. * @param {string} deviceId - id of 'audiooutput' device from
  449. * navigator.mediaDevices.enumerateDevices()
  450. * @returns {Promise} - resolves when audio output is changed, is rejected
  451. * otherwise
  452. */
  453. static setAudioOutputDevice(deviceId) {
  454. return RTCUtils.setAudioOutputDevice(deviceId);
  455. }
  456. /**
  457. * Returns <tt>true<tt/> if given WebRTC MediaStream is considered a valid
  458. * "user" stream which means that it's not a "receive only" stream nor a
  459. * "mixed" JVB stream.
  460. *
  461. * Clients that implement Unified Plan, such as Firefox use recvonly
  462. * "streams/channels/tracks" for receiving remote stream/tracks, as opposed
  463. * to Plan B where there are only 3 channels: audio, video and data.
  464. *
  465. * @param {MediaStream} stream the WebRTC MediaStream instance
  466. * @returns {boolean}
  467. */
  468. static isUserStream(stream) {
  469. return RTC.isUserStreamById(RTCUtils.getStreamID(stream));
  470. }
  471. /**
  472. * Returns <tt>true<tt/> if a WebRTC MediaStream identified by given stream
  473. * ID is considered a valid "user" stream which means that it's not a
  474. * "receive only" stream nor a "mixed" JVB stream.
  475. *
  476. * Clients that implement Unified Plan, such as Firefox use recvonly
  477. * "streams/channels/tracks" for receiving remote stream/tracks, as opposed
  478. * to Plan B where there are only 3 channels: audio, video and data.
  479. *
  480. * @param {string} streamId the id of WebRTC MediaStream
  481. * @returns {boolean}
  482. */
  483. static isUserStreamById(streamId) {
  484. return streamId && streamId !== 'mixedmslabel'
  485. && streamId !== 'default';
  486. }
  487. /**
  488. * Allows to receive list of available cameras/microphones.
  489. * @param {function} callback would receive array of devices as an argument
  490. */
  491. static enumerateDevices(callback) {
  492. RTCUtils.enumerateDevices(callback);
  493. }
  494. /**
  495. * A method to handle stopping of the stream.
  496. * One point to handle the differences in various implementations.
  497. * @param mediaStream MediaStream object to stop.
  498. */
  499. static stopMediaStream(mediaStream) {
  500. RTCUtils.stopMediaStream(mediaStream);
  501. }
  502. /**
  503. * Returns whether the desktop sharing is enabled or not.
  504. * @returns {boolean}
  505. */
  506. static isDesktopSharingEnabled() {
  507. return RTCUtils.isDesktopSharingEnabled();
  508. }
  509. /**
  510. * Closes all currently opened data channels.
  511. */
  512. closeAllDataChannels() {
  513. if (this.dataChannels) {
  514. this.dataChannels.closeAllChannels();
  515. this.dataChannelsOpen = false;
  516. if (this._lastNChangeListener) {
  517. this.removeListener(RTCEvents.LASTN_ENDPOINT_CHANGED,
  518. this._lastNChangeListener);
  519. }
  520. }
  521. }
  522. /**
  523. *
  524. * @param resource
  525. * @param audioLevel
  526. */
  527. setAudioLevel(ssrc, audioLevel) {
  528. const track = this._getTrackBySSRC(ssrc);
  529. if (!track) {
  530. return;
  531. }
  532. if (!track.isAudioTrack()) {
  533. logger.warn(`Received audio level for non-audio track: ${ssrc}`);
  534. return;
  535. }
  536. track.setAudioLevel(audioLevel);
  537. }
  538. /**
  539. * Searches in localTracks(session stores ssrc for audio and video) and
  540. * remoteTracks for the ssrc and returns the corresponding resource.
  541. * @param ssrc the ssrc to check.
  542. */
  543. getResourceBySSRC(ssrc) {
  544. const track = this._getTrackBySSRC(ssrc);
  545. return track ? track.getParticipantId() : null;
  546. }
  547. /**
  548. * Finds a track (either local or remote) which runs on the given SSRC.
  549. * @param {string|number} ssrc
  550. * @return {JitsiTrack|undefined}
  551. *
  552. * FIXME figure out where SSRC is stored as a string and convert to number
  553. * @private
  554. */
  555. _getTrackBySSRC(ssrc) {
  556. let track
  557. = this.getLocalTracks().find(
  558. localTrack =>
  559. // It is important that SSRC is not compared with ===,
  560. // because the code calling this method is inconsistent
  561. // about string vs number types
  562. Array.from(this.peerConnections.values())
  563. .find(pc => pc.getLocalSSRC(localTrack) == ssrc) // eslint-disable-line eqeqeq, max-len
  564. );
  565. if (!track) {
  566. track = this._getRemoteTrackBySSRC(ssrc);
  567. }
  568. return track;
  569. }
  570. /**
  571. * Searches in remoteTracks for the ssrc and returns the corresponding
  572. * track.
  573. * @param ssrc the ssrc to check.
  574. * @return {JitsiRemoteTrack|undefined} return the first remote track that
  575. * matches given SSRC or <tt>undefined</tt> if no such track was found.
  576. * @private
  577. */
  578. _getRemoteTrackBySSRC(ssrc) {
  579. /* eslint-disable eqeqeq */
  580. // FIXME: Convert the SSRCs in whole project to use the same type.
  581. // Now we are using number and string.
  582. return this.getRemoteTracks().find(
  583. remoteTrack => ssrc == remoteTrack.getSSRC());
  584. /* eslint-enable eqeqeq */
  585. }
  586. /**
  587. * Sends message via the datachannels.
  588. * @param to {string} the id of the endpoint that should receive the
  589. * message. If "" the message will be sent to all participants.
  590. * @param payload {object} the payload of the message.
  591. * @throws NetworkError or InvalidStateError or Error if the operation
  592. * fails or there is no data channel created
  593. */
  594. sendDataChannelMessage(to, payload) {
  595. if (this.dataChannels) {
  596. this.dataChannels.sendDataChannelMessage(to, payload);
  597. } else {
  598. throw new Error('Data channels support is disabled!');
  599. }
  600. }
  601. /**
  602. * Selects a new value for "lastN". The requested amount of videos are going
  603. * to be delivered after the value is in effect. Set to -1 for unlimited or
  604. * all available videos.
  605. * @param value {int} the new value for lastN.
  606. * @trows Error if there is no data channel created.
  607. */
  608. setLastN(value) {
  609. if (this.dataChannels) {
  610. this.dataChannels.sendSetLastNMessage(value);
  611. } else {
  612. throw new Error('Data channels support is disabled!');
  613. }
  614. }
  615. /**
  616. * Indicates if the endpoint id is currently included in the last N.
  617. *
  618. * @param {string} id the endpoint id that we check for last N.
  619. * @returns {boolean} true if the endpoint id is in the last N or if we
  620. * don't have data channel support, otherwise we return false.
  621. */
  622. isInLastN(id) {
  623. return !this._lastNEndpoints // lastNEndpoints not initialised yet
  624. || this._lastNEndpoints.indexOf(id) > -1;
  625. }
  626. }