twilio-video 2.22.2 → 3.0.0-preview.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/CHANGELOG.md +106 -1
  2. package/README.md +1 -1
  3. package/dist/twilio-video.js +1751 -564
  4. package/dist/twilio-video.min.js +21 -20
  5. package/es5/connect.js +75 -13
  6. package/es5/connect.js.map +1 -1
  7. package/es5/createlocaltracks.js +0 -1
  8. package/es5/createlocaltracks.js.map +1 -1
  9. package/es5/localparticipant.js +20 -10
  10. package/es5/localparticipant.js.map +1 -1
  11. package/es5/media/track/audiotrack.js +6 -15
  12. package/es5/media/track/audiotrack.js.map +1 -1
  13. package/es5/media/track/index.js +2 -4
  14. package/es5/media/track/index.js.map +1 -1
  15. package/es5/media/track/localdatatrack.js +4 -1
  16. package/es5/media/track/localdatatrack.js.map +1 -1
  17. package/es5/media/track/localmediatrack.js +1 -0
  18. package/es5/media/track/localmediatrack.js.map +1 -1
  19. package/es5/media/track/mediatrack.js +63 -49
  20. package/es5/media/track/mediatrack.js.map +1 -1
  21. package/es5/media/track/receiver.js +3 -2
  22. package/es5/media/track/receiver.js.map +1 -1
  23. package/es5/media/track/remoteaudiotrack.js +27 -9
  24. package/es5/media/track/remoteaudiotrack.js.map +1 -1
  25. package/es5/media/track/remoteaudiotrackpublication.js +28 -2
  26. package/es5/media/track/remoteaudiotrackpublication.js.map +1 -1
  27. package/es5/media/track/remotedatatrack.js +1 -1
  28. package/es5/media/track/remotedatatrack.js.map +1 -1
  29. package/es5/media/track/remotemediatrack.js +93 -24
  30. package/es5/media/track/remotemediatrack.js.map +1 -1
  31. package/es5/media/track/remotetrackpublication.js +87 -15
  32. package/es5/media/track/remotetrackpublication.js.map +1 -1
  33. package/es5/media/track/remotevideotrack.js +39 -11
  34. package/es5/media/track/remotevideotrack.js.map +1 -1
  35. package/es5/media/track/remotevideotrackpublication.js +28 -2
  36. package/es5/media/track/remotevideotrackpublication.js.map +1 -1
  37. package/es5/media/track/sender.js +1 -1
  38. package/es5/media/track/sender.js.map +1 -1
  39. package/es5/media/track/transceiver.js +6 -1
  40. package/es5/media/track/transceiver.js.map +1 -1
  41. package/es5/media/track/videotrack.js +32 -16
  42. package/es5/media/track/videotrack.js.map +1 -1
  43. package/es5/participant.js +47 -76
  44. package/es5/participant.js.map +1 -1
  45. package/es5/remoteparticipant.js +18 -9
  46. package/es5/remoteparticipant.js.map +1 -1
  47. package/es5/room.js +22 -5
  48. package/es5/room.js.map +1 -1
  49. package/es5/signaling/remotetrackpublication.js +13 -8
  50. package/es5/signaling/remotetrackpublication.js.map +1 -1
  51. package/es5/signaling/track.js.map +1 -1
  52. package/es5/signaling/v2/cancelableroomsignalingpromise.js +6 -3
  53. package/es5/signaling/v2/cancelableroomsignalingpromise.js.map +1 -1
  54. package/es5/signaling/v2/localparticipant.js +3 -3
  55. package/es5/signaling/v2/peerconnection.js +16 -3
  56. package/es5/signaling/v2/peerconnection.js.map +1 -1
  57. package/es5/signaling/v2/peerconnectionmanager.js +12 -0
  58. package/es5/signaling/v2/peerconnectionmanager.js.map +1 -1
  59. package/es5/signaling/v2/remoteparticipant.js +13 -5
  60. package/es5/signaling/v2/remoteparticipant.js.map +1 -1
  61. package/es5/signaling/v2/remotetrackpublication.js +12 -1
  62. package/es5/signaling/v2/remotetrackpublication.js.map +1 -1
  63. package/es5/signaling/v2/room.js +183 -105
  64. package/es5/signaling/v2/room.js.map +1 -1
  65. package/es5/signaling/v2/twilioconnectiontransport.js +3 -1
  66. package/es5/signaling/v2/twilioconnectiontransport.js.map +1 -1
  67. package/es5/signaling/v3/remoteparticipant.js +70 -0
  68. package/es5/signaling/v3/remoteparticipant.js.map +1 -0
  69. package/es5/signaling/v3/remotetrackpublication.js +249 -0
  70. package/es5/signaling/v3/remotetrackpublication.js.map +1 -0
  71. package/es5/signaling/v3/room.js +237 -0
  72. package/es5/signaling/v3/room.js.map +1 -0
  73. package/es5/signaling/v3/tracksubscriptionssignaling.js +73 -0
  74. package/es5/signaling/v3/tracksubscriptionssignaling.js.map +1 -0
  75. package/es5/util/constants.js +7 -0
  76. package/es5/util/constants.js.map +1 -1
  77. package/es5/util/index.js +75 -13
  78. package/es5/util/index.js.map +1 -1
  79. package/es5/util/validate.js +10 -2
  80. package/es5/util/validate.js.map +1 -1
  81. package/es5/webrtc/getstats.js +11 -9
  82. package/es5/webrtc/getstats.js.map +1 -1
  83. package/es5/webrtc/index.js +6 -1
  84. package/es5/webrtc/index.js.map +1 -1
  85. package/lib/connect.js +82 -13
  86. package/lib/createlocaltracks.ts +1 -1
  87. package/lib/localparticipant.js +28 -10
  88. package/lib/media/track/audiotrack.js +6 -16
  89. package/lib/media/track/index.js +4 -6
  90. package/lib/media/track/localdatatrack.js +5 -1
  91. package/lib/media/track/localmediatrack.js +1 -0
  92. package/lib/media/track/mediatrack.js +64 -60
  93. package/lib/media/track/receiver.js +3 -2
  94. package/lib/media/track/remoteaudiotrack.js +27 -9
  95. package/lib/media/track/remoteaudiotrackpublication.js +30 -2
  96. package/lib/media/track/remotedatatrack.js +1 -1
  97. package/lib/media/track/remotemediatrack.js +97 -26
  98. package/lib/media/track/remotetrackpublication.js +70 -15
  99. package/lib/media/track/remotevideotrack.js +40 -11
  100. package/lib/media/track/remotevideotrackpublication.js +30 -2
  101. package/lib/media/track/sender.js +1 -1
  102. package/lib/media/track/transceiver.js +6 -1
  103. package/lib/media/track/videotrack.js +34 -22
  104. package/lib/participant.js +54 -74
  105. package/lib/remoteparticipant.js +18 -9
  106. package/lib/room.js +21 -5
  107. package/lib/signaling/remotetrackpublication.js +13 -8
  108. package/lib/signaling/track.js +0 -1
  109. package/lib/signaling/v2/cancelableroomsignalingpromise.js +6 -3
  110. package/lib/signaling/v2/localparticipant.js +3 -3
  111. package/lib/signaling/v2/peerconnection.js +14 -3
  112. package/lib/signaling/v2/peerconnectionmanager.js +13 -0
  113. package/lib/signaling/v2/remoteparticipant.js +12 -5
  114. package/lib/signaling/v2/remotetrackpublication.js +9 -1
  115. package/lib/signaling/v2/room.js +185 -122
  116. package/lib/signaling/v2/twilioconnectiontransport.js +3 -3
  117. package/lib/signaling/v3/remoteparticipant.js +76 -0
  118. package/lib/signaling/v3/remotetrackpublication.js +246 -0
  119. package/lib/signaling/v3/room.js +248 -0
  120. package/lib/signaling/v3/tracksubscriptionssignaling.js +61 -0
  121. package/lib/util/constants.js +8 -0
  122. package/lib/util/index.js +77 -13
  123. package/lib/util/validate.js +12 -2
  124. package/lib/webrtc/getstats.js +11 -9
  125. package/lib/webrtc/index.js +7 -1
  126. package/package.json +4 -2
  127. package/tsdef/RemoteAudioTrack.d.ts +11 -1
  128. package/tsdef/RemoteAudioTrackPublication.d.ts +8 -0
  129. package/tsdef/RemoteParticipant.d.ts +1 -1
  130. package/tsdef/RemoteTrackPublication.d.ts +4 -1
  131. package/tsdef/RemoteVideoTrack.d.ts +11 -1
  132. package/tsdef/RemoteVideoTrackPublication.d.ts +8 -0
  133. package/tsdef/Room.d.ts +1 -1
  134. package/tsdef/Track.d.ts +7 -0
  135. package/tsdef/index.d.ts +2 -2
  136. package/tsdef/twilio-video-tests.ts +4 -0
  137. package/tsdef/types.d.ts +18 -10
@@ -1,4 +1,4 @@
1
- /*! twilio-video.js 2.22.2
1
+ /*! twilio-video.js 3.0.0-preview.2
2
2
 
3
3
  The following license applies to all parts of this software except as
4
4
  documented below.
@@ -83,7 +83,7 @@ function createCancelableRoomPromise(getLocalTracks, createLocalParticipant, cre
83
83
  }
84
84
  module.exports = createCancelableRoomPromise;
85
85
 
86
- },{"./util/cancelablepromise":121}],2:[function(require,module,exports){
86
+ },{"./util/cancelablepromise":125}],2:[function(require,module,exports){
87
87
  'use strict';
88
88
  var MediaStreamTrack = require('./webrtc').MediaStreamTrack;
89
89
  var _a = require('./webrtc/util'), guessBrowser = _a.guessBrowser, guessBrowserVersion = _a.guessBrowserVersion;
@@ -119,7 +119,7 @@ var deprecatedConnectOptionsProps = new Set([
119
119
  { didWarn: false, shouldDelete: false, name: 'eventListener', newName: 'Video.Logger' },
120
120
  { didWarn: false, shouldDelete: false, name: 'logLevel', newName: 'Video.Logger' },
121
121
  ]);
122
- var deprecatedBandwidthProfileOptions = new Set([
122
+ var deprecatedVideoBandwidthProfileOptions = new Set([
123
123
  { didWarn: false, shouldDelete: false, name: 'maxTracks', newName: 'bandwidthProfile.video.clientTrackSwitchOffControl' },
124
124
  { didWarn: false, shouldDelete: false, name: 'renderDimensions', newName: 'bandwidthProfile.video.contentPreferencesMode' },
125
125
  ]);
@@ -136,6 +136,10 @@ var deprecatedBandwidthProfileOptions = new Set([
136
136
  * {@link LocalAudioTrack} and {@link LocalVideoTrack} automatically, you can
137
137
  * pass your own array which you can stop yourself. See {@link ConnectOptions}
138
138
  * for more information.
139
+ * <br><br>
140
+ * A "trackPublished" event is fired on the {@link LocalParticipant} for each
141
+ * LocalTrack that was successfully published. A "trackPublicationFailed" event
142
+ * is fired for each LocalTrack that was failed to be published.
139
143
  * @alias module:twilio-video.connect
140
144
  * @param {string} token - The Access Token string
141
145
  * @param {ConnectOptions} [options] - Options to override the default behavior, invalid options are ignored.
@@ -212,7 +216,7 @@ var deprecatedBandwidthProfileOptions = new Set([
212
216
  * audio: { name: 'microphone' },
213
217
  * video: { name: 'camera' }
214
218
  * }).then(function(room) {
215
- * room.localParticipants.trackPublications.forEach(function(publication) {
219
+ * room.localParticipant.on('trackPublished', function(publication) {
216
220
  * console.log('The LocalTrack "' + publication.trackName + '" was successfully published');
217
221
  * });
218
222
  * }).catch(error => {
@@ -270,7 +274,7 @@ function connect(token, options) {
270
274
  // NOTE(csantos): Log a warning for the deprecated ConnectOptions properties.
271
275
  // The warning is displayed only for the first call to connect() per browser session.
272
276
  // Additionally, the options that are no longer needed will be removed.
273
- deprecateOptions(options, log, deprecatedConnectOptionsProps);
277
+ deprecateOptions(options, 'ConnectOptions', log, deprecatedConnectOptionsProps);
274
278
  var adaptiveSimulcast = options.preferredVideoCodecs === 'auto';
275
279
  if (adaptiveSimulcast) {
276
280
  // NOTE(mpatwardhan): enable adaptiveSimulcast.
@@ -372,7 +376,7 @@ function connect(token, options) {
372
376
  options.contentPreferencesMode = 'auto';
373
377
  if (options.bandwidthProfile.video) {
374
378
  // log any warnings about deprecated bwp options
375
- deprecateOptions(options.bandwidthProfile.video, log, deprecatedBandwidthProfileOptions);
379
+ deprecateOptions(options.bandwidthProfile.video, 'ConnectOptions.bandwidthProfile.video', log, deprecatedVideoBandwidthProfileOptions);
376
380
  if ('maxTracks' in options.bandwidthProfile.video) {
377
381
  // when deprecated maxTracks is specified. disable clientTrackSwitchOffControl
378
382
  options.clientTrackSwitchOffControl = 'disabled';
@@ -383,6 +387,10 @@ function connect(token, options) {
383
387
  else {
384
388
  options.clientTrackSwitchOffControl = 'auto';
385
389
  }
390
+ if ('maxTracks' in options.bandwidthProfile.video) {
391
+ // move maxTracks over to new property that will be used to create RSP payload
392
+ options.bandwidthProfile.video.maxSwitchedOnTracks = options.bandwidthProfile.video.maxTracks;
393
+ }
386
394
  if ('renderDimensions' in options.bandwidthProfile.video) {
387
395
  options.contentPreferencesMode = 'disabled';
388
396
  }
@@ -444,7 +452,7 @@ function connect(token, options) {
444
452
  * not subscribe to any RemoteTrack in a Group or Small Group Room. Setting it to
445
453
  * <code>true</code>, or not setting it at all preserves the default behavior. This
446
454
  * flag does not have any effect in a Peer-to-Peer Room.
447
- * @property {BandwidthProfileOptions} [bandwidthProfile] - You can optionally configure
455
+ * @property {BandwidthProfile} [bandwidthProfile] - You can optionally configure
448
456
  * how your available downlink bandwidth is shared among the RemoteTracks you have subscribed
449
457
  * to in a Group Room. By default, bandwidth is shared equally among the RemoteTracks.
450
458
  * This has no effect in Peer-to-Peer Rooms.
@@ -539,17 +547,28 @@ function connect(token, options) {
539
547
  * are not provided.
540
548
  */
541
549
  /**
542
- * {@link BandwidthProfileOptions} allows you to configure how your available downlink
550
+ * {@link BandwidthProfile} allows you to configure how your available downlink
543
551
  * bandwidth is shared among the RemoteTracks you have subscribed to in a Group Room.
544
- * @typedef {object} BandwidthProfileOptions
545
- * @property {VideoBandwidthProfileOptions} [video] - Optional parameter to configure
552
+ * @typedef {object} BandwidthProfile
553
+ * @property {VideoBandwidthProfile} [video] - Optional parameter to configure
546
554
  * how your available downlink bandwidth is shared among the {@link RemoteVideoTrack}s you
547
555
  * have subscribed to in a Group Room.
556
+ * @property {AudioBandwidthProfile} [audio] - Optional parameter to configure
557
+ * how your available downlink bandwidth is shared among the {@link RemoteAudioTrack}s you
558
+ * have subscribed to in a Group Room.
548
559
  */
549
560
  /**
550
- * {@link VideoBandwidthProfileOptions} allows you to configure how your available downlink
561
+ * {@link AudioBandwidthProfile} allows you to configure how your available downlink
562
+ * bandwidth is shared among the {@link RemoteAudioTrack}s you have subscribed to in a Group Room.
563
+ * @typedef {object} AudioBandwidthProfile
564
+ * @property {number} [maxSwitchedOnTracks] - Optional
565
+ * parameter to specify the maximum number of {@link RemoteAudioTrack}s, which will be selected based on
566
+ * N-Loudest policy. If not specified server defaults will be used.
567
+ */
568
+ /**
569
+ * {@link VideoBandwidthProfile} allows you to configure how your available downlink
551
570
  * bandwidth is shared among the {@link RemoteVideoTrack}s you have subscribed to in a Group Room.
552
- * @typedef {object} VideoBandwidthProfileOptions
571
+ * @typedef {object} VideoBandwidthProfile
553
572
  * @property {Track.Priority} [dominantSpeakerPriority="standard"] - Optional parameter to
554
573
  * specify the minimum subscribe {@link Track.Priority} of the Dominant Speaker's {@link RemoteVideoTrack}s.
555
574
  * This means that the Dominant Speaker's {@link RemoteVideoTrack}s that are published with
@@ -574,11 +593,15 @@ function connect(token, options) {
574
593
  * parameter to specify the maximum number of visible {@link RemoteVideoTrack}s, which will be selected based on
575
594
  * {@link Track.Priority} and an N-Loudest policy. By default there are no limits on the number of visible {@link RemoteVideoTrack}s.
576
595
  * 0 or a negative value will remove any limit on the maximum number of visible {@link RemoteVideoTrack}s.
596
+ * @property {number} [maxSwitchedOnTracks] - Optional parameter to specify the maximum number of visible {@link RemoteVideoTrack}s,
597
+ * which will be selected based on {@link Track.Priority} and an N-Loudest policy. By default there are no limits
598
+ * on the number of visible {@link RemoteVideoTrack}s. 0 or a negative value will remove any limit
599
+ * on the maximum number of visible {@link RemoteVideoTrack}s.
577
600
  * @property {BandwidthProfileMode} [mode="grid"] - Optional parameter to specify how the {@link RemoteVideoTrack}s'
578
601
  * TrackPriority values are mapped to bandwidth allocation in Group Rooms. This defaults to "grid",
579
602
  * which results in equal bandwidth share allocation to all {@link RemoteVideoTrack}s.
580
603
  * @property {VideoRenderDimensions} [renderDimensions] - <code>(deprecated: use "contentPreferencesMode" instead)</code>. Optional
581
- * parameter to specify the desired render dimensions of {@link RemoteVideoTrack}s.
604
+ * parameter to specify the desired render dimensions of {@link RemoteVideoTrack}s.
582
605
  * @property {TrackSwitchOffMode} [trackSwitchOffMode="predicted"] - Optional parameter to configure
583
606
  * how {@link RemoteVideoTrack}s are switched off in response to bandwidth pressure. Defaults to "predicted".
584
607
  */
@@ -737,6 +760,45 @@ var TrackSwitchOffMode = {
737
760
  */
738
761
  disabled: 'disabled'
739
762
  };
763
+ /**
764
+ * {@link TrackSwitchOffReason} describes why a {@link RemoteTrack} is switched off. This reason
765
+ * accompanies the {@link RemoteTrack} event <code>switchedOff</code> and is used for
766
+ * the {@link RemoteTrack} property <code>switchOffReason</code>.
767
+ * @enum {string}
768
+ */
769
+ var TrackSwitchOffReason = {
770
+ /**
771
+ * The {@link RemoteTrack} was disabled by the publishing {@link Participant}.
772
+ * The media server does not send media to the subscribing {@link Participant}s
773
+ * for a disabled {@link Track}.
774
+ */
775
+ 'disabled-by-publisher': 'disabled-by-publisher',
776
+ /**
777
+ * The {@link RemoteVideoTrack} was disabled by the subscribing {@link Participant}
778
+ * and the media server stopped sending its media.
779
+ */
780
+ 'disabled-by-subscriber': 'disabled-by-subscriber',
781
+ /**
782
+ * The {@link RemoteVideoTrack} was switched off because the remaining
783
+ * downlink bandwidth is not sufficient to receive its media. The bandwidth
784
+ * limit is configured by specifying <code>maxSubscriptionBitrate</code>
785
+ * in {@link VideoBandwidthProfile} or a default value is selected
786
+ * by the media server.
787
+ */
788
+ 'max-bandwidth-reached': 'max-bandwidth-reached',
789
+ /**
790
+ * The {@link RemoteTrack} was switched off because the number of switched on
791
+ * {@link Track}s reached the limit set by the media server.
792
+ */
793
+ 'max-tracks-switched-on': 'max-tracks-switched-on',
794
+ /**
795
+ * The {@link RemoteVideoTrack} was switched off because network congestion
796
+ * was detected or predicted. The <code>trackSwitchOffMode</code> property
797
+ * on {@link VideoBandwidthProfile} allows you to specify how the
798
+ * switch off is managed.
799
+ */
800
+ 'network-congestion': 'network-congestion'
801
+ };
740
802
  /**
741
803
  * {@link BandwidthProfileMode} specifies how {@link RemoteVideoTrack}s' {@link Track.Priority} values
742
804
  * are mapped to bandwidth allocation in Group Rooms.
@@ -915,7 +977,7 @@ var EventListenerGroup = {
915
977
  * @property {EventListenerLevel} level='warning'
916
978
  * @property {string} name='waiting'
917
979
  */
918
- function deprecateOptions(options, log, deprecationTable) {
980
+ function deprecateOptions(options, optionsName, log, deprecationTable) {
919
981
  deprecationTable.forEach(function (prop) {
920
982
  var didWarn = prop.didWarn, name = prop.name, newName = prop.newName, shouldDelete = prop.shouldDelete;
921
983
  if (name in options && typeof options[name] !== 'undefined') {
@@ -926,7 +988,7 @@ function deprecateOptions(options, log, deprecationTable) {
926
988
  delete options[name];
927
989
  }
928
990
  if (!didWarn && !['error', 'off'].includes(log.level)) {
929
- log.warn("The ConnectOptions \"" + name + "\" is " + (newName
991
+ log.warn("The " + optionsName + " property \"" + name + "\" is " + (newName
930
992
  ? "deprecated and scheduled for removal. Please use \"" + newName + "\" instead."
931
993
  : 'no longer applicable and will be ignored.'));
932
994
  prop.didWarn = true;
@@ -999,7 +1061,7 @@ function normalizeCodecSettings(nameOrSettings) {
999
1061
  }
1000
1062
  module.exports = connect;
1001
1063
 
1002
- },{"./cancelableroompromise":1,"./encodingparameters":9,"./localparticipant":12,"./media/track/es5":14,"./networkqualityconfiguration":42,"./room":54,"./signaling/v2":68,"./util":128,"./util/cancelablepromise":121,"./util/constants":122,"./util/eventobserver":126,"./util/insightspublisher":129,"./util/insightspublisher/null":130,"./util/log":132,"./util/validate":146,"./webrtc":154,"./webrtc/util":167}],3:[function(require,module,exports){
1064
+ },{"./cancelableroompromise":1,"./encodingparameters":9,"./localparticipant":12,"./media/track/es5":14,"./networkqualityconfiguration":42,"./room":54,"./signaling/v2":68,"./util":132,"./util/cancelablepromise":125,"./util/constants":126,"./util/eventobserver":130,"./util/insightspublisher":133,"./util/insightspublisher/null":134,"./util/log":136,"./util/validate":150,"./webrtc":158,"./webrtc/util":171}],3:[function(require,module,exports){
1003
1065
  'use strict';
1004
1066
  var _a = require('./util/constants'), DEFAULT_LOG_LEVEL = _a.DEFAULT_LOG_LEVEL, DEFAULT_LOGGER_NAME = _a.DEFAULT_LOGGER_NAME;
1005
1067
  /**
@@ -1110,7 +1172,7 @@ module.exports = {
1110
1172
  video: createLocalVideoTrack
1111
1173
  };
1112
1174
 
1113
- },{"./util/constants":122}],4:[function(require,module,exports){
1175
+ },{"./util/constants":126}],4:[function(require,module,exports){
1114
1176
  'use strict';
1115
1177
  var __assign = (this && this.__assign) || function () {
1116
1178
  __assign = Object.assign || function(t) {
@@ -1192,7 +1254,6 @@ var workaround180748 = require('./webaudio/workaround180748');
1192
1254
  // statement belongs to. Each call to createLocalTracks() increments this
1193
1255
  // counter.
1194
1256
  var createLocalTrackCalls = 0;
1195
- ;
1196
1257
  /**
1197
1258
  * Request {@link LocalTrack}s. By default, it requests a
1198
1259
  * {@link LocalAudioTrack} and a {@link LocalVideoTrack}.
@@ -1331,7 +1392,7 @@ function createLocalTracks(options) {
1331
1392
  }
1332
1393
  exports.createLocalTracks = createLocalTracks;
1333
1394
 
1334
- },{"./media/track/es5":14,"./util":128,"./util/constants":122,"./util/log":132,"./webaudio/workaround180748":151,"./webrtc":154}],5:[function(require,module,exports){
1395
+ },{"./media/track/es5":14,"./util":132,"./util/constants":126,"./util/log":136,"./webaudio/workaround180748":155,"./webrtc":158}],5:[function(require,module,exports){
1335
1396
  'use strict';
1336
1397
  var __extends = (this && this.__extends) || (function () {
1337
1398
  var extendStatics = function (d, b) {
@@ -1530,7 +1591,7 @@ var DataTrackSender = /** @class */ (function (_super) {
1530
1591
  }(DataTrackTransceiver));
1531
1592
  module.exports = DataTrackSender;
1532
1593
 
1533
- },{"../util":128,"./transceiver":7}],7:[function(require,module,exports){
1594
+ },{"../util":132,"./transceiver":7}],7:[function(require,module,exports){
1534
1595
  'use strict';
1535
1596
  var __extends = (this && this.__extends) || (function () {
1536
1597
  var extendStatics = function (d, b) {
@@ -1590,7 +1651,7 @@ var DataTrackTransceiver = /** @class */ (function (_super) {
1590
1651
  }(TrackTransceiver));
1591
1652
  module.exports = DataTrackTransceiver;
1592
1653
 
1593
- },{"../transceiver":116}],8:[function(require,module,exports){
1654
+ },{"../transceiver":120}],8:[function(require,module,exports){
1594
1655
  'use strict';
1595
1656
  var __extends = (this && this.__extends) || (function () {
1596
1657
  var extendStatics = function (d, b) {
@@ -1687,7 +1748,7 @@ var DataTransport = /** @class */ (function (_super) {
1687
1748
  */
1688
1749
  module.exports = DataTransport;
1689
1750
 
1690
- },{"events":170}],9:[function(require,module,exports){
1751
+ },{"events":174}],9:[function(require,module,exports){
1691
1752
  'use strict';
1692
1753
  var __extends = (this && this.__extends) || (function () {
1693
1754
  var extendStatics = function (d, b) {
@@ -1785,13 +1846,13 @@ var EncodingParametersImpl = /** @class */ (function (_super) {
1785
1846
  */
1786
1847
  module.exports = EncodingParametersImpl;
1787
1848
 
1788
- },{"events":170}],10:[function(require,module,exports){
1849
+ },{"events":174}],10:[function(require,module,exports){
1789
1850
  'use strict';
1790
1851
  var EventEmitter = require('events').EventEmitter;
1791
1852
  var hidePrivateAndCertainPublicPropertiesInClass = require('./util').hidePrivateAndCertainPublicPropertiesInClass;
1792
1853
  module.exports = hidePrivateAndCertainPublicPropertiesInClass(EventEmitter, ['domain']);
1793
1854
 
1794
- },{"./util":128,"events":170}],11:[function(require,module,exports){
1855
+ },{"./util":132,"events":174}],11:[function(require,module,exports){
1795
1856
  'use strict';
1796
1857
  var __assign = (this && this.__assign) || function () {
1797
1858
  __assign = Object.assign || function(t) {
@@ -1865,7 +1926,7 @@ module.exports = {
1865
1926
  LocalDataTrack: LocalDataTrack
1866
1927
  };
1867
1928
 
1868
- },{"../package.json":171,"./connect":2,"./createlocaltrack":3,"./createlocaltracks":4,"./media/track/es5":14,"./preflight/preflighttest":48,"./util/support":141,"./vendor/loglevel":148}],12:[function(require,module,exports){
1929
+ },{"../package.json":175,"./connect":2,"./createlocaltrack":3,"./createlocaltracks":4,"./media/track/es5":14,"./preflight/preflighttest":48,"./util/support":145,"./vendor/loglevel":152}],12:[function(require,module,exports){
1869
1930
  'use strict';
1870
1931
  var __extends = (this && this.__extends) || (function () {
1871
1932
  var extendStatics = function (d, b) {
@@ -1883,7 +1944,7 @@ var __extends = (this && this.__extends) || (function () {
1883
1944
  };
1884
1945
  })();
1885
1946
  var MediaStreamTrack = require('./webrtc').MediaStreamTrack;
1886
- var _a = require('./util'), asLocalTrack = _a.asLocalTrack, asLocalTrackPublication = _a.asLocalTrackPublication, trackClass = _a.trackClass;
1947
+ var _a = require('./util'), asLocalTrack = _a.asLocalTrack, asLocalTrackPublication = _a.asLocalTrackPublication, reemitTrackPublicationEvents = _a.reemitTrackPublicationEvents, trackClass = _a.trackClass;
1887
1948
  var _b = require('./util/constants'), E = _b.typeErrors, trackPriority = _b.trackPriority;
1888
1949
  var validateLocalTrack = require('./util/validate').validateLocalTrack;
1889
1950
  var _c = require('./media/track/es5'), LocalAudioTrack = _c.LocalAudioTrack, LocalDataTrack = _c.LocalDataTrack, LocalVideoTrack = _c.LocalVideoTrack;
@@ -1984,17 +2045,28 @@ var LocalParticipant = /** @class */ (function (_super) {
1984
2045
  /**
1985
2046
  * @private
1986
2047
  * @param {LocalTrack} track
1987
- * @param {Track.ID} id
1988
2048
  * @param {Track.Priority} priority
1989
2049
  * @returns {?LocalTrack}
1990
2050
  */
1991
- LocalParticipant.prototype._addTrack = function (track, id, priority) {
1992
- var addedTrack = _super.prototype._addTrack.call(this, track, id);
2051
+ LocalParticipant.prototype._addTrack = function (track, priority) {
2052
+ var addedTrack = _super.prototype._addTrack.call(this, track, track.id);
1993
2053
  if (addedTrack && this.state !== 'disconnected') {
1994
2054
  this._addLocalTrack(track, priority);
1995
2055
  }
1996
2056
  return addedTrack;
1997
2057
  };
2058
+ /**
2059
+ * @private
2060
+ * @param {LocalTrackPublication} publication
2061
+ * @returns {?LocalTrackPublication}
2062
+ */
2063
+ LocalParticipant.prototype._addTrackPublication = function (publication) {
2064
+ publication = _super.prototype._addTrackPublication.call(this, publication);
2065
+ if (publication) {
2066
+ reemitTrackPublicationEvents(this, publication);
2067
+ }
2068
+ return publication;
2069
+ };
1998
2070
  /**
1999
2071
  * @private
2000
2072
  * @param {LocalTrack} track
@@ -2009,11 +2081,10 @@ var LocalParticipant = /** @class */ (function (_super) {
2009
2081
  /**
2010
2082
  * @private
2011
2083
  * @param {LocalTrack} track
2012
- * @param {Track.ID} id
2013
2084
  * @returns {?LocalTrack}
2014
2085
  */
2015
- LocalParticipant.prototype._removeTrack = function (track, id) {
2016
- var removedTrack = _super.prototype._removeTrack.call(this, track, id);
2086
+ LocalParticipant.prototype._removeTrack = function (track) {
2087
+ var removedTrack = _super.prototype._removeTrack.call(this, track, track.id);
2017
2088
  if (removedTrack && this.state !== 'disconnected') {
2018
2089
  this._signaling.removeTrack(track._trackSender);
2019
2090
  this._log.info("Removed a " + trackClass(track, true) + ":", track.id);
@@ -2133,7 +2204,7 @@ var LocalParticipant = /** @class */ (function (_super) {
2133
2204
  if (error) {
2134
2205
  trackSignaling.removeListener('updated', updated);
2135
2206
  log.warn("Failed to publish the " + trackClass(localTrack, true) + ": " + error.message);
2136
- self._removeTrack(localTrack, localTrack.id);
2207
+ self._removeTrack(localTrack);
2137
2208
  setTimeout(function () {
2138
2209
  self.emit('trackPublicationFailed', error, localTrack);
2139
2210
  });
@@ -2295,7 +2366,7 @@ var LocalParticipant = /** @class */ (function (_super) {
2295
2366
  // eslint-disable-next-line new-cap
2296
2367
  return Promise.reject(E.INVALID_VALUE('LocalTrackPublishOptions.priority', priorityValues));
2297
2368
  }
2298
- var addedLocalTrack = this._addTrack(localTrack, localTrack.id, options.priority)
2369
+ var addedLocalTrack = this._addTrack(localTrack, options.priority)
2299
2370
  || this._tracks.get(localTrack.id);
2300
2371
  return this._getOrCreateLocalTrackPublication(addedLocalTrack);
2301
2372
  };
@@ -2421,7 +2492,7 @@ var LocalParticipant = /** @class */ (function (_super) {
2421
2492
  }
2422
2493
  var trackSignaling = this._signaling.getPublication(localTrack._trackSender);
2423
2494
  trackSignaling.publishFailed(new Error("The " + localTrack + " was unpublished"));
2424
- localTrack = this._removeTrack(localTrack, localTrack.id);
2495
+ localTrack = this._removeTrack(localTrack);
2425
2496
  if (!localTrack) {
2426
2497
  return null;
2427
2498
  }
@@ -2568,7 +2639,7 @@ function getTrackPublication(trackPublications, track) {
2568
2639
  }
2569
2640
  module.exports = LocalParticipant;
2570
2641
 
2571
- },{"./media/track/es5":14,"./media/track/localaudiotrackpublication":20,"./media/track/localdatatrackpublication":22,"./media/track/localvideotrackpublication":26,"./participant":43,"./util":128,"./util/constants":122,"./util/validate":146,"./webrtc":154}],13:[function(require,module,exports){
2642
+ },{"./media/track/es5":14,"./media/track/localaudiotrackpublication":20,"./media/track/localdatatrackpublication":22,"./media/track/localvideotrackpublication":26,"./participant":43,"./util":132,"./util/constants":126,"./util/validate":150,"./webrtc":158}],13:[function(require,module,exports){
2572
2643
  'use strict';
2573
2644
  var __extends = (this && this.__extends) || (function () {
2574
2645
  var extendStatics = function (d, b) {
@@ -2595,7 +2666,9 @@ var MediaTrack = require('./mediatrack');
2595
2666
  * @property {boolean} isEnabled - Whether or not the {@link AudioTrack} is
2596
2667
  * enabled; if the {@link AudioTrack} is not enabled, it is "muted"
2597
2668
  * @property {Track.Kind} kind - "audio"
2598
- * @property {MediaStreamTrack} mediaStreamTrack - An audio MediaStreamTrack
2669
+ * @property {?MediaStreamTrack} mediaStreamTrack - Provides access to the underlying
2670
+ * MediaStreamTrack; It is set to <code>null</code> if it is a {@link RemoteAudioTrack}
2671
+ * that is switched off
2599
2672
  * @property {?MediaStreamTrack} processedTrack - The source of processed audio samples.
2600
2673
  * It is always null as audio processing is not currently supported.
2601
2674
  * @emits AudioTrack#disabled
@@ -2606,23 +2679,12 @@ var AudioTrack = /** @class */ (function (_super) {
2606
2679
  __extends(AudioTrack, _super);
2607
2680
  /**
2608
2681
  * Construct an {@link AudioTrack}.
2609
- * @param {MediaTrackTransceiver} mediaTrackTransceiver
2610
- * @param {{log: Log}} options
2682
+ * @param {?MediaTrackTransceiver} mediaTrackTransceiver
2683
+ * @param {{log: Log, name: string}} options
2611
2684
  */
2612
2685
  function AudioTrack(mediaTrackTransceiver, options) {
2613
- return _super.call(this, mediaTrackTransceiver, options) || this;
2686
+ return _super.call(this, 'audio', mediaTrackTransceiver, options) || this;
2614
2687
  }
2615
- /**
2616
- * @private
2617
- */
2618
- AudioTrack.prototype._start = function () {
2619
- _super.prototype._start.call(this);
2620
- if (this._dummyEl) {
2621
- // once started let go of dummy element
2622
- this._dummyEl.srcObject = null;
2623
- this._dummyEl = null;
2624
- }
2625
- };
2626
2688
  /**
2627
2689
  * Create an HTMLAudioElement and attach the {@link AudioTrack} to it.
2628
2690
  *
@@ -2757,7 +2819,7 @@ function LocalAudioTrack(mediaStreamTrack, options) {
2757
2819
  inherits(LocalAudioTrack, LocalAudioTrackClass);
2758
2820
  module.exports = LocalAudioTrack;
2759
2821
 
2760
- },{"../../../vendor/inherits":147,"../localaudiotrack":19}],16:[function(require,module,exports){
2822
+ },{"../../../vendor/inherits":151,"../localaudiotrack":19}],16:[function(require,module,exports){
2761
2823
  // eslint-disable-next-line no-warning-comments
2762
2824
  // TODO(mroberts): Remove this when we go to the next major version. This is
2763
2825
  // only in place so that we can support ES6 classes without requiring `new`.
@@ -2772,7 +2834,7 @@ function LocalDataTrack(options) {
2772
2834
  inherits(LocalDataTrack, LocalDataTrackClass);
2773
2835
  module.exports = LocalDataTrack;
2774
2836
 
2775
- },{"../../../vendor/inherits":147,"../localdatatrack":21}],17:[function(require,module,exports){
2837
+ },{"../../../vendor/inherits":151,"../localdatatrack":21}],17:[function(require,module,exports){
2776
2838
  // eslint-disable-next-line no-warning-comments
2777
2839
  // TODO(mroberts): Remove this when we go to the next major version. This is
2778
2840
  // only in place so that we can support ES6 classes without requiring `new`.
@@ -2787,7 +2849,7 @@ function LocalVideoTrack(mediaStreamTrack, options) {
2787
2849
  inherits(LocalVideoTrack, LocalVideoTrackClass);
2788
2850
  module.exports = LocalVideoTrack;
2789
2851
 
2790
- },{"../../../vendor/inherits":147,"../localvideotrack":25}],18:[function(require,module,exports){
2852
+ },{"../../../vendor/inherits":151,"../localvideotrack":25}],18:[function(require,module,exports){
2791
2853
  'use strict';
2792
2854
  var __extends = (this && this.__extends) || (function () {
2793
2855
  var extendStatics = function (d, b) {
@@ -2819,14 +2881,12 @@ var Track = /** @class */ (function (_super) {
2819
2881
  __extends(Track, _super);
2820
2882
  /**
2821
2883
  * Construct a {@link Track}.
2822
- * @param {Track.ID} id - The {@link Track}'s ID
2823
2884
  * @param {Track.Kind} kind - The {@link Track}'s kind
2824
- * @param {{ log: Log, name: ?string }} options
2885
+ * @param {{ log: Log, name: string }} options
2825
2886
  */
2826
- function Track(id, kind, options) {
2887
+ function Track(kind, options) {
2827
2888
  var _this = this;
2828
2889
  options = Object.assign({
2829
- name: id,
2830
2890
  log: null,
2831
2891
  logLevel: DEFAULT_LOG_LEVEL
2832
2892
  }, options);
@@ -2899,7 +2959,7 @@ var Track = /** @class */ (function (_super) {
2899
2959
  */
2900
2960
  module.exports = Track;
2901
2961
 
2902
- },{"../../eventemitter":10,"../../util":128,"../../util/constants":122,"../../util/log":132}],19:[function(require,module,exports){
2962
+ },{"../../eventemitter":10,"../../util":132,"../../util/constants":126,"../../util/log":136}],19:[function(require,module,exports){
2903
2963
  'use strict';
2904
2964
  var __extends = (this && this.__extends) || (function () {
2905
2965
  var extendStatics = function (d, b) {
@@ -3185,7 +3245,10 @@ var LocalDataTrack = /** @class */ (function (_super) {
3185
3245
  }, options);
3186
3246
  var DataTrackSender = options.DataTrackSender;
3187
3247
  var dataTrackSender = new DataTrackSender(options.maxPacketLifeTime, options.maxRetransmits, options.ordered);
3188
- _this = _super.call(this, dataTrackSender.id, 'data', options) || this;
3248
+ options = Object.assign({
3249
+ name: dataTrackSender.id
3250
+ }, options);
3251
+ _this = _super.call(this, 'data', options) || this;
3189
3252
  Object.defineProperties(_this, {
3190
3253
  _trackSender: {
3191
3254
  value: dataTrackSender
@@ -3343,6 +3406,7 @@ function mixinLocalMediaTrack(AudioOrVideoTrack) {
3343
3406
  options = Object.assign({
3344
3407
  getUserMedia: getUserMedia,
3345
3408
  isCreatedByCreateLocalTracks: false,
3409
+ name: mediaStreamTrack.id,
3346
3410
  workaroundWebKitBug1208516: workaroundWebKitBug1208516,
3347
3411
  gUMSilentTrackWorkaround: gUMSilentTrackWorkaround
3348
3412
  }, options);
@@ -3644,7 +3708,7 @@ function restartWhenInadvertentlyStopped(localMediaTrack) {
3644
3708
  }
3645
3709
  module.exports = mixinLocalMediaTrack;
3646
3710
 
3647
- },{"../../util":128,"../../util/constants":122,"../../util/detectsilentaudio":123,"../../util/detectsilentvideo":124,"../../util/documentvisibilitymonitor.js":125,"../../util/localmediarestartdeferreds":131,"../../webaudio/workaround180748":151,"../../webrtc":154,"../../webrtc/util":167,"./sender":37}],24:[function(require,module,exports){
3711
+ },{"../../util":132,"../../util/constants":126,"../../util/detectsilentaudio":127,"../../util/detectsilentvideo":128,"../../util/documentvisibilitymonitor.js":129,"../../util/localmediarestartdeferreds":135,"../../webaudio/workaround180748":155,"../../webrtc":158,"../../webrtc/util":171,"./sender":37}],24:[function(require,module,exports){
3648
3712
  /* eslint new-cap:0 */
3649
3713
  'use strict';
3650
3714
  var __extends = (this && this.__extends) || (function () {
@@ -3810,7 +3874,7 @@ var LocalTrackPublication = /** @class */ (function (_super) {
3810
3874
  */
3811
3875
  module.exports = LocalTrackPublication;
3812
3876
 
3813
- },{"../../util/constants":122,"./trackpublication":38}],25:[function(require,module,exports){
3877
+ },{"../../util/constants":126,"./trackpublication":38}],25:[function(require,module,exports){
3814
3878
  'use strict';
3815
3879
  var __extends = (this && this.__extends) || (function () {
3816
3880
  var extendStatics = function (d, b) {
@@ -4157,7 +4221,7 @@ function workaroundSilentLocalVideo(localVideoTrack, doc) {
4157
4221
  */
4158
4222
  module.exports = LocalVideoTrack;
4159
4223
 
4160
- },{"../../util":128,"../../util/detectsilentvideo":124,"../../webrtc/util":167,"./localmediatrack":23,"./videotrack":41}],26:[function(require,module,exports){
4224
+ },{"../../util":132,"../../util/detectsilentvideo":128,"../../webrtc/util":171,"./localmediatrack":23,"./videotrack":41}],26:[function(require,module,exports){
4161
4225
  'use strict';
4162
4226
  var __extends = (this && this.__extends) || (function () {
4163
4227
  var extendStatics = function (d, b) {
@@ -4232,24 +4296,22 @@ var Track = require('./');
4232
4296
  * @property {Track.ID} id - This {@link Track}'s ID
4233
4297
  * @property {boolean} isStarted - Whether or not the {@link MediaTrack} has
4234
4298
  * started
4235
- * @property {boolean} isEnabled - Whether or not the {@link MediaTrack} is
4236
- * enabled (i.e., whether it is paused or muted)
4237
4299
  * @property {Track.Kind} kind - The kind of the underlying
4238
4300
  * MediaStreamTrack, "audio" or "video"
4239
- * @property {MediaStreamTrack} mediaStreamTrack - The underlying
4240
- * MediaStreamTrack
4241
- * @emits MediaTrack#disabled
4242
- * @emits MediaTrack#enabled
4301
+ * @property {?MediaStreamTrack} mediaStreamTrack - Provides access to the underlying
4302
+ * MediaStreamTrack; It is set to <code>null</code> if it is a {@link RemoteTrack}
4303
+ * that is switched off
4243
4304
  * @emits MediaTrack#started
4244
4305
  */
4245
4306
  var MediaTrack = /** @class */ (function (_super) {
4246
4307
  __extends(MediaTrack, _super);
4247
4308
  /**
4248
4309
  * Construct a {@link MediaTrack}.
4249
- * @param {MediaTrackTransceiver} mediaTrackTransceiver
4250
- * @param {{log: Log}} options
4310
+ * @param {Track.Kind} kind
4311
+ * @param {?MediaTrackTransceiver} mediaTrackTransceiver
4312
+ * @param {{ log: Log, name: string }} options
4251
4313
  */
4252
- function MediaTrack(mediaTrackTransceiver, options) {
4314
+ function MediaTrack(kind, mediaTrackTransceiver, options) {
4253
4315
  var _this = this;
4254
4316
  options = Object.assign({
4255
4317
  playPausedElementsIfNotBackgrounded: (guessBrowser() === 'safari' || isIOSChrome())
@@ -4257,8 +4319,7 @@ var MediaTrack = /** @class */ (function (_super) {
4257
4319
  && typeof document.addEventListener === 'function'
4258
4320
  && typeof document.visibilityState === 'string'
4259
4321
  }, options);
4260
- _this = _super.call(this, mediaTrackTransceiver.id, mediaTrackTransceiver.kind, options) || this;
4261
- var isStarted = false;
4322
+ _this = _super.call(this, kind, options) || this;
4262
4323
  options = Object.assign({
4263
4324
  MediaStream: MediaStream
4264
4325
  }, options);
@@ -4275,12 +4336,12 @@ var MediaTrack = /** @class */ (function (_super) {
4275
4336
  value: new WeakMap()
4276
4337
  },
4277
4338
  _isStarted: {
4278
- get: function () {
4279
- return isStarted;
4280
- },
4281
- set: function (_isStarted) {
4282
- isStarted = _isStarted;
4283
- }
4339
+ value: false,
4340
+ writable: true
4341
+ },
4342
+ _mediaTrackTransceiver: {
4343
+ value: mediaTrackTransceiver,
4344
+ writable: true
4284
4345
  },
4285
4346
  _playPausedElementsIfNotBackgrounded: {
4286
4347
  value: options.playPausedElementsIfNotBackgrounded
@@ -4299,13 +4360,15 @@ var MediaTrack = /** @class */ (function (_super) {
4299
4360
  isStarted: {
4300
4361
  enumerable: true,
4301
4362
  get: function () {
4302
- return isStarted;
4363
+ return this._isStarted;
4303
4364
  }
4304
4365
  },
4305
4366
  mediaStreamTrack: {
4306
4367
  enumerable: true,
4307
4368
  get: function () {
4308
- return this._unprocessedTrack || mediaTrackTransceiver.track;
4369
+ return this._unprocessedTrack || (this._mediaTrackTransceiver
4370
+ ? this._mediaTrackTransceiver.track
4371
+ : null);
4309
4372
  }
4310
4373
  },
4311
4374
  processedTrack: {
@@ -4333,27 +4396,40 @@ var MediaTrack = /** @class */ (function (_super) {
4333
4396
  * @private
4334
4397
  */
4335
4398
  MediaTrack.prototype._initialize = function () {
4399
+ var log = this._log;
4400
+ if (!this.mediaStreamTrack) {
4401
+ log.debug('Skipping initialization as .mediaStreamTrack is null');
4402
+ return;
4403
+ }
4336
4404
  var self = this;
4337
- this._log.debug('Initializing');
4338
- this._dummyEl = this._createElement();
4405
+ log.debug('Initializing');
4406
+ if (!this._dummyEl) {
4407
+ this._dummyEl = this._createElement();
4408
+ }
4339
4409
  this.mediaStreamTrack.addEventListener('ended', function onended() {
4340
4410
  self._end();
4341
- self.mediaStreamTrack.removeEventListener('ended', onended);
4411
+ if (self.mediaStreamTrack) {
4412
+ self.mediaStreamTrack.removeEventListener('ended', onended);
4413
+ }
4342
4414
  });
4343
4415
  if (this._dummyEl) {
4344
4416
  this._dummyEl.muted = true;
4345
4417
  this._dummyEl.oncanplay = this._start.bind(this, this._dummyEl);
4346
4418
  // NOTE(csantos): We always want to attach the original mediaStreamTrack for dummyEl
4347
4419
  this._attach(this._dummyEl, this.mediaStreamTrack);
4348
- this._attachments.delete(this._dummyEl);
4349
4420
  }
4350
4421
  };
4351
4422
  /**
4352
4423
  * @private
4353
4424
  */
4354
4425
  MediaTrack.prototype._end = function () {
4355
- this._log.debug('Ended');
4426
+ var log = this._log;
4427
+ if (!this.mediaStreamTrack) {
4428
+ log.debug('Skipping ended as .mediaStreamTrack is null');
4429
+ return;
4430
+ }
4356
4431
  if (this._dummyEl) {
4432
+ this._log.debug('Ended');
4357
4433
  this._dummyEl.remove();
4358
4434
  this._dummyEl.srcObject = null;
4359
4435
  this._dummyEl.oncanplay = null;
@@ -4382,30 +4458,33 @@ var MediaTrack = /** @class */ (function (_super) {
4382
4458
  * Attach the provided MediaStreamTrack to the media element.
4383
4459
  * @param el - The media element to attach to
4384
4460
  * @param mediaStreamTrack - The MediaStreamTrack to attach. If this is
4385
- * not provided, it uses the processedTrack if it exists
4386
- * or it defaults to the current mediaStreamTrack
4461
+ * not provided, it uses the .processedTrack if it exists,
4462
+ * or it defaults to the current .mediaStreamTrack
4387
4463
  * @private
4388
4464
  */
4389
4465
  MediaTrack.prototype._attach = function (el, mediaStreamTrack) {
4390
4466
  if (mediaStreamTrack === void 0) { mediaStreamTrack = this.processedTrack || this.mediaStreamTrack; }
4391
- var mediaStream = el.srcObject;
4392
- if (!(mediaStream instanceof this._MediaStream)) {
4393
- mediaStream = new this._MediaStream();
4394
- }
4395
- var getTracks = mediaStreamTrack.kind === 'audio'
4396
- ? 'getAudioTracks'
4397
- : 'getVideoTracks';
4398
- mediaStream[getTracks]().forEach(function (track) {
4399
- mediaStream.removeTrack(track);
4400
- });
4401
- mediaStream.addTrack(mediaStreamTrack);
4402
- // NOTE(mpatwardhan): resetting `srcObject` here, causes flicker (JSDK-2641), but it lets us
4403
- // to sidestep the a chrome bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1052353
4404
- //
4405
- el.srcObject = mediaStream;
4467
+ var mediaStream = el.srcObject || new this._MediaStream();
4468
+ var getTracks = this.kind === 'audio' ? 'getAudioTracks' : 'getVideoTracks';
4469
+ mediaStream[getTracks]().forEach(function (track) { return mediaStream.removeTrack(track); });
4470
+ if (mediaStreamTrack) {
4471
+ mediaStream.addTrack(mediaStreamTrack);
4472
+ }
4473
+ var isEmptyVideoMediaStream = this.kind === 'video' && mediaStream.getTracks().length <= 0;
4474
+ if (!el.srcObject) {
4475
+ el.srcObject = isEmptyVideoMediaStream ? null : mediaStream;
4476
+ }
4477
+ else if (isEmptyVideoMediaStream) {
4478
+ // NOTE(mmalavalli): VIDEO-10752 - When a track is switched off, and the attached video element's .srcObject property
4479
+ // is assigned a MediaStream that does not contain any MediaStreamTrack, the browser for some reason caches a snapshot
4480
+ // from the most recently removed MediaStreamTrack and displays it in the video element. The workaround for this is
4481
+ // to set the .srcObject property to null which causes the browser to clear any cached snapshots from the removed
4482
+ // MediaStreamTrack and show a black frame.
4483
+ el.srcObject = null;
4484
+ }
4406
4485
  el.autoplay = true;
4407
4486
  el.playsInline = true;
4408
- if (!this._attachments.has(el)) {
4487
+ if (el !== this._dummyEl) {
4409
4488
  this._attachments.add(el);
4410
4489
  }
4411
4490
  return el;
@@ -4425,8 +4504,10 @@ var MediaTrack = /** @class */ (function (_super) {
4425
4504
  */
4426
4505
  MediaTrack.prototype._updateElementsMediaStreamTrack = function () {
4427
4506
  var _this = this;
4428
- this._log.debug('Reattaching all elements to update mediaStreamTrack');
4507
+ this._log.debug('Reattaching all elements to update .mediaStreamTrack');
4429
4508
  this._getAllAttachedElements().forEach(function (el) { return _this._attach(el); });
4509
+ // eslint-disable-next-line no-warning-comments
4510
+ // TODO(mpatwardhan): should we emit that mediaStreamTrack was updated?
4430
4511
  };
4431
4512
  /**
4432
4513
  * @private
@@ -4465,8 +4546,9 @@ var MediaTrack = /** @class */ (function (_super) {
4465
4546
  return el;
4466
4547
  }
4467
4548
  var mediaStream = el.srcObject;
4468
- if (mediaStream instanceof this._MediaStream) {
4469
- mediaStream.removeTrack(this.processedTrack || this.mediaStreamTrack);
4549
+ var mediaStreamTrack = this.processedTrack || this.mediaStreamTrack;
4550
+ if (mediaStream && mediaStreamTrack) {
4551
+ mediaStream.removeTrack(mediaStreamTrack);
4470
4552
  }
4471
4553
  this._attachments.delete(el);
4472
4554
  if (this._shouldShimAttachedElements && this._elShims.has(el)) {
@@ -4480,11 +4562,7 @@ var MediaTrack = /** @class */ (function (_super) {
4480
4562
  * @private
4481
4563
  */
4482
4564
  MediaTrack.prototype._getAllAttachedElements = function () {
4483
- var els = [];
4484
- this._attachments.forEach(function (el) {
4485
- els.push(el);
4486
- });
4487
- return els;
4565
+ return Array.from(this._attachments);
4488
4566
  };
4489
4567
  return MediaTrack;
4490
4568
  }(Track));
@@ -4567,7 +4645,7 @@ function shimMediaElement(el, onUnintentionallyPaused) {
4567
4645
  }
4568
4646
  module.exports = MediaTrack;
4569
4647
 
4570
- },{"../../util":128,"../../util/localmediarestartdeferreds":131,"../../webrtc":154,"../../webrtc/util":167,"./":18}],28:[function(require,module,exports){
4648
+ },{"../../util":132,"../../util/localmediarestartdeferreds":135,"../../webrtc":158,"../../webrtc/util":171,"./":18}],28:[function(require,module,exports){
4571
4649
  'use strict';
4572
4650
  var __extends = (this && this.__extends) || (function () {
4573
4651
  var extendStatics = function (d, b) {
@@ -4594,10 +4672,11 @@ var MediaTrackReceiver = /** @class */ (function (_super) {
4594
4672
  /**
4595
4673
  * Construct a {@link MediaTrackReceiver}.
4596
4674
  * @param {Track.ID} id - The MediaStreamTrack ID signaled through RSP/SDP
4675
+ * @param {?string} mid - The MID associated with the MediaStreamTrack
4597
4676
  * @param {MediaStreamTrack} mediaStreamTrack - The remote MediaStreamTrack
4598
4677
  */
4599
- function MediaTrackReceiver(id, mediaStreamTrack) {
4600
- return _super.call(this, id, mediaStreamTrack) || this;
4678
+ function MediaTrackReceiver(id, mid, mediaStreamTrack) {
4679
+ return _super.call(this, id, mid, mediaStreamTrack) || this;
4601
4680
  }
4602
4681
  return MediaTrackReceiver;
4603
4682
  }(MediaTrackTransceiver));
@@ -4627,8 +4706,12 @@ var RemoteMediaAudioTrack = mixinRemoteMediaTrack(AudioTrack);
4627
4706
  * A {@link RemoteAudioTrack} represents an {@link AudioTrack} published to a
4628
4707
  * {@link Room} by a {@link RemoteParticipant}.
4629
4708
  * @extends AudioTrack
4630
- * @property {boolean} isEnabled - Whether the {@link RemoteAudioTrack} is enabled
4709
+ * @property {boolean} isEnabled - <code>Deprecated: Use (.switchOffReason !== "disabled-by-publisher") instead</code>
4710
+ * Whether the {@link RemoteAudioTrack} is enabled (Deprecated only for large group Rooms)
4631
4711
  * @property {boolean} isSwitchedOff - Whether the {@link RemoteAudioTrack} is switched off
4712
+ * @property {?TrackSwitchOffReason} switchOffReason - The reason for the {@link RemoteAudioTrack} being switched off;
4713
+ * If switched on, it is set to <code>null</code>; The {@link RemoteAudioTrack} is initially switched off with this
4714
+ * property set to <code>disabled-by-subscriber</code>
4632
4715
  * @property {Track.SID} sid - The {@link RemoteAudioTrack}'s SID
4633
4716
  * @property {?Track.Priority} priority - The subscribe priority of the {@link RemoteAudioTrack}
4634
4717
  * @emits RemoteAudioTrack#disabled
@@ -4642,16 +4725,17 @@ var RemoteAudioTrack = /** @class */ (function (_super) {
4642
4725
  /**
4643
4726
  * Construct a {@link RemoteAudioTrack}.
4644
4727
  * @param {Track.SID} sid - The {@link RemoteAudioTrack}'s SID
4645
- * @param {MediaTrackReceiver} mediaTrackReceiver - An audio MediaStreamTrack container
4728
+ * @param {?MediaTrackReceiver} mediaTrackReceiver - An audio MediaStreamTrack container
4646
4729
  * @param {boolean} isEnabled - Whether the {@link RemoteAudioTrack} is enabled
4647
4730
  * @param {boolean} isSwitchedOff - Whether the {@link RemoteAudioTrack} is switched off
4731
+ * @param {?string} switchOffReason - The reason the {@link RemoteAudioTrack} is switched off
4648
4732
  * @param {function(?Track.Priority): void} setPriority - Set or clear the subscribe
4649
4733
  * {@link Track.Priority} of the {@link RemoteAudioTrack}
4650
4734
  * @param {function(ClientRenderHint): void} setRenderHint - Set render hints.
4651
- * @param {{log: Log}} options - The {@link RemoteTrack} options
4735
+ * @param {{log: Log, name: string}} options - The {@link RemoteTrack} options
4652
4736
  */
4653
- function RemoteAudioTrack(sid, mediaTrackReceiver, isEnabled, isSwitchedOff, setPriority, setRenderHint, options) {
4654
- return _super.call(this, sid, mediaTrackReceiver, isEnabled, isSwitchedOff, setPriority, setRenderHint, options) || this;
4737
+ function RemoteAudioTrack(sid, mediaTrackReceiver, isEnabled, isSwitchedOff, switchOffReason, setPriority, setRenderHint, options) {
4738
+ return _super.call(this, 'audio', sid, mediaTrackReceiver, isEnabled, isSwitchedOff, switchOffReason, setPriority, setRenderHint, options) || this;
4655
4739
  }
4656
4740
  RemoteAudioTrack.prototype.toString = function () {
4657
4741
  return "[RemoteAudioTrack #" + this._instanceId + ": " + this.sid + "]";
@@ -4669,13 +4753,15 @@ var RemoteAudioTrack = /** @class */ (function (_super) {
4669
4753
  return RemoteAudioTrack;
4670
4754
  }(RemoteMediaAudioTrack));
4671
4755
  /**
4672
- * The {@link RemoteAudioTrack} was disabled, i.e. "muted".
4756
+ * The {@link RemoteAudioTrack} was disabled, i.e. "muted" (Deprecated only for large group Rooms).
4757
+ * @deprecated Use <a href="#event:switchedOff"><code>switchedOff</code></a> (<code>.switchOffReason === "disabled-by-publisher"</code>) instead
4673
4758
  * @param {RemoteAudioTrack} track - The {@link RemoteAudioTrack} that was
4674
4759
  * disabled
4675
4760
  * @event RemoteAudioTrack#disabled
4676
4761
  */
4677
4762
  /**
4678
- * The {@link RemoteAudioTrack} was enabled, i.e. "unmuted".
4763
+ * The {@link RemoteAudioTrack} was enabled, i.e. "unmuted" (Deprecated only for large group Rooms).
4764
+ * @deprecated Use <a href="#event:switchedOn"><code>switchedOn</code></a> instead
4679
4765
  * @param {RemoteAudioTrack} track - The {@link RemoteAudioTrack} that was
4680
4766
  * enabled
4681
4767
  * @event RemoteAudioTrack#enabled
@@ -4687,13 +4773,24 @@ var RemoteAudioTrack = /** @class */ (function (_super) {
4687
4773
  * @event RemoteAudioTrack#started
4688
4774
  */
4689
4775
  /**
4690
- * A {@link RemoteAudioTrack} was switched off.
4776
+ * A {@link RemoteAudioTrack} was switched off. The media server stops sending media for the
4777
+ * {@link RemoteAudioTrack} until it is switched back on. Just before the event is raised,
4778
+ * <code>isSwitchedOff</code> is set to <code>true</code> and <code>switchOffReason</code> is
4779
+ * set to a {@link TrackSwitchOffReason} in large group Rooms (<code>switchOffReason</code> is
4780
+ * <code>null</code> non-large group Rooms). Also, the <code>mediaStreamTrack</code> property
4781
+ * is set to <code>null</code> (only in large group Rooms).
4691
4782
  * @param {RemoteAudioTrack} track - The {@link RemoteAudioTrack} that was
4692
4783
  * switched off
4784
+ * @param {?TrackSwitchOffReason} switchOffReason - The reason the {@link RemoteAudioTrack}
4785
+ * was switched off
4693
4786
  * @event RemoteAudioTrack#switchedOff
4694
4787
  */
4695
4788
  /**
4696
- * A {@link RemoteAudioTrack} was switched on.
4789
+ * A {@link RemoteAudioTrack} was switched on. The media server starts sending media for the
4790
+ * {@link RemoteAudioTrack} until it is switched off. Just before the event is raised,
4791
+ * <code>isSwitchedOff</code> is set to <code>false</code> and <code>switchOffReason</code>
4792
+ * is set to <code>null</code>. Also, the <code>mediaStreamTrack</code> property is set to a
4793
+ * MediaStreamTrack that is the source of the {@link RemoteAudioTrack}'s media.
4697
4794
  * @param {RemoteAudioTrack} track - The {@link RemoteAudioTrack} that was
4698
4795
  * switched on
4699
4796
  * @event RemoteAudioTrack#switchedOn
@@ -4758,13 +4855,39 @@ var RemoteAudioTrackPublication = /** @class */ (function (_super) {
4758
4855
  * @event RemoteAudioTrackPublication#subscriptionFailed
4759
4856
  */
4760
4857
  /**
4761
- * The {@link RemoteAudioTrack} was disabled.
4858
+ * The {@link RemoteAudioTrack} was disabled. It is fired only if <code>.isSubscribed</code>
4859
+ * is set to <code>true</code> (Deprecated only for large group Rooms).
4860
+ * @deprecated Use <a href="event:trackSwitchedOff"><code>trackSwitchedOff</code></a> (<code>track.switchOffReason === "disabled-by-publisher"</code>) instead
4762
4861
  * @event RemoteAudioTrackPublication#trackDisabled
4763
4862
  */
4764
4863
  /**
4765
- * The {@link RemoteAudioTrack} was enabled.
4864
+ * The {@link RemoteAudioTrack} was enabled. It is fired only if <code>.isSubscribed</code>
4865
+ * is set to <code>true</code> (Deprecated only for large group Rooms).
4866
+ * @deprecated Use <a href="event:trackSwitchedOn"><code>trackSwitchedOn</code></a> instead
4766
4867
  * @event RemoteAudioTrackPublication#trackEnabled
4767
4868
  */
4869
+ /**
4870
+ * The {@link RemoteAudioTrack} was switched off. The media server stops sending media for
4871
+ * the {@link RemoteAudioTrack} until it is switched back on. Just before the event is raised,
4872
+ * <code>isSwitchedOff</code> is set to <code>true</code> and <code>switchOffReason</code>
4873
+ * is set to a {@link TrackSwitchOffReason} in large group Rooms (<code>switchOffReason</code> is
4874
+ * <code>null</code> non-large group Rooms). Also, if the {@link RemoteAudioTrack} receives audio
4875
+ * media, the <code>mediaStreamTrack</code> property is set to <code>null</code>. (only in large
4876
+ * group Rooms)
4877
+ * @param {RemoteAudioTrack} track - the {@link RemoteAudioTrack} that was switched off
4878
+ * @param {?TrackSwitchOffReason} switchOffReason - the reason the {@link RemoteAudioTrack}
4879
+ * was switched off
4880
+ * @event RemoteAudioTrackPublication#trackSwitchedOff
4881
+ */
4882
+ /**
4883
+ * The {@link RemoteAudioTrack} was switched on. The media server starts sending media for
4884
+ * the {@link RemoteAudioTrack} until it is switched off. Just before the event is raised,
4885
+ * <code>isSwitchedOff</code> is set to <code>false</code> and <code>switchOffReason</code>
4886
+ * is set to <code>null</code>. Also, the <code>mediaStreamTrack</code> property is set to a
4887
+ * MediaStreamTrack that is the source of the {@link RemoteAudioTrack}'s media.
4888
+ * @param {RemoteAudioTrack} track - the {@link RemoteAudioTrack} that was switched on
4889
+ * @event RemoteAudioTrackPublication#trackSwitchedOn
4890
+ */
4768
4891
  /**
4769
4892
  * Your {@link LocalParticipant} unsubscribed from the {@link RemoteAudioTrack}.
4770
4893
  * @param {RemoteAudioTrack} track - the {@link RemoteAudioTrack} that was unsubscribed from
@@ -4850,7 +4973,7 @@ var RemoteDataTrack = /** @class */ (function (_super) {
4850
4973
  * @param {{log: Log, name: ?string}} options
4851
4974
  */
4852
4975
  function RemoteDataTrack(sid, dataTrackReceiver, options) {
4853
- var _this = _super.call(this, dataTrackReceiver.id, 'data', options) || this;
4976
+ var _this = _super.call(this, 'data', options) || this;
4854
4977
  Object.defineProperties(_this, {
4855
4978
  _isSwitchedOff: {
4856
4979
  value: false,
@@ -4959,7 +5082,7 @@ var RemoteDataTrack = /** @class */ (function (_super) {
4959
5082
  */
4960
5083
  module.exports = RemoteDataTrack;
4961
5084
 
4962
- },{"../../util/constants":122,"./":18}],32:[function(require,module,exports){
5085
+ },{"../../util/constants":126,"./":18}],32:[function(require,module,exports){
4963
5086
  'use strict';
4964
5087
  var __extends = (this && this.__extends) || (function () {
4965
5088
  var extendStatics = function (d, b) {
@@ -5059,15 +5182,20 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
5059
5182
  to[j] = from[i];
5060
5183
  return to;
5061
5184
  };
5062
- var _a = require('../../util/constants'), E = _a.typeErrors, trackPriority = _a.trackPriority;
5185
+ var deprecateEvents = require('../../util').deprecateEvents;
5186
+ var _a = require('../../util/constants'), E = _a.typeErrors, trackPriority = _a.trackPriority, trackSwitchOffReason = _a.trackSwitchOffReason;
5063
5187
  var _b = require('../../webrtc/util'), guessBrowser = _b.guessBrowser, isIOSChrome = _b.isIOSChrome;
5064
5188
  var documentVisibilityMonitor = require('../../util/documentvisibilitymonitor.js');
5065
5189
  function mixinRemoteMediaTrack(AudioOrVideoTrack) {
5066
5190
  /**
5067
5191
  * A {@link RemoteMediaTrack} represents a {@link MediaTrack} published to a
5068
5192
  * {@link Room} by a {@link RemoteParticipant}.
5069
- * @property {boolean} isEnabled - Whether the {@link RemoteMediaTrack} is enabled
5193
+ * @property {boolean} isEnabled - <code>Deprecated: Use (.switchOffReason !== "disabled-by-publisher") instead.</code>
5194
+ * Whether the {@link RemoteAudioTrack} is enabled (Deprecated only for large group Rooms)
5070
5195
  * @property {boolean} isSwitchedOff - Whether the {@link RemoteMediaTrack} is switched off
5196
+ * @property {?TrackSwitchOffReason} switchOffReason - The reason for the {@link RemoteMediaTrack} being switched off;
5197
+ * If switched on, it is set to <code>null</code>; The {@link RemoteMediaTrack} is initially switched off with this
5198
+ * property set to <code>disabled-by-subscriber</code>
5071
5199
  * @property {Track.SID} sid - The SID assigned to the {@link RemoteMediaTrack}
5072
5200
  * @property {?Track.Priority} priority - The subscribe priority of the {@link RemoteMediaTrack}
5073
5201
  * @emits RemoteMediaTrack#disabled
@@ -5079,18 +5207,21 @@ function mixinRemoteMediaTrack(AudioOrVideoTrack) {
5079
5207
  __extends(RemoteMediaTrack, _super);
5080
5208
  /**
5081
5209
  * Construct a {@link RemoteMediaTrack}.
5210
+ * @param {Track.Kind} kind
5082
5211
  * @param {Track.SID} sid
5083
- * @param {MediaTrackReceiver} mediaTrackReceiver
5212
+ * @param {?MediaTrackReceiver} mediaTrackReceiver
5084
5213
  * @param {boolean} isEnabled
5085
- @param {boolean} isSwitchedOff
5214
+ * @param {boolean} isSwitchedOff
5215
+ * @param {?string} switchOffReason
5086
5216
  * @param {function(?Track.Priority): void} setPriority - Set or clear the subscribe
5087
5217
  * {@link Track.Priority} of the {@link RemoteMediaTrack}
5088
5218
  * @param {function(ClientRenderHint): void} setRenderHint - Set render hints.
5089
- * @param {{log: Log, name: ?string}} options
5219
+ * @param {{log: Log, name: string}} options
5090
5220
  */
5091
- function RemoteMediaTrack(sid, mediaTrackReceiver, isEnabled, isSwitchedOff, setPriority, setRenderHint, options) {
5221
+ function RemoteMediaTrack(kind, sid, mediaTrackReceiver, isEnabled, isSwitchedOff, switchOffReason, setPriority, setRenderHint, options) {
5092
5222
  var _this = this;
5093
5223
  options = Object.assign({
5224
+ shouldDeprecateEnabledState: false,
5094
5225
  // NOTE(mpatwardhan): WebKit bug: 212780 sometimes causes the audio/video elements to stay paused when safari
5095
5226
  // regains foreground. To workaround it, when safari gains foreground - we will play any elements that were
5096
5227
  // playing before safari lost foreground.
@@ -5099,6 +5230,7 @@ function mixinRemoteMediaTrack(AudioOrVideoTrack) {
5099
5230
  && typeof document.addEventListener === 'function'
5100
5231
  && typeof document.visibilityState === 'string'
5101
5232
  }, options);
5233
+ var shouldDeprecateEnabledState = options.shouldDeprecateEnabledState;
5102
5234
  _this = _super.call(this, mediaTrackReceiver, options) || this;
5103
5235
  Object.defineProperties(_this, {
5104
5236
  _isEnabled: {
@@ -5122,9 +5254,25 @@ function mixinRemoteMediaTrack(AudioOrVideoTrack) {
5122
5254
  setRenderHint(renderHint);
5123
5255
  }
5124
5256
  },
5257
+ _switchOffReason: {
5258
+ value: switchOffReason,
5259
+ writable: true
5260
+ },
5261
+ _workaroundWebKitBug212780: {
5262
+ value: options.workaroundWebKitBug212780
5263
+ },
5264
+ _workaroundWebKitBug212780Cleanup: {
5265
+ value: null,
5266
+ writable: true
5267
+ },
5125
5268
  isEnabled: {
5126
5269
  enumerable: true,
5127
5270
  get: function () {
5271
+ if (shouldDeprecateEnabledState) {
5272
+ this._log.deprecated('.isEnabled is deprecated and scheduled for removal. '
5273
+ + 'The RemoteMediaTrack is can be considered disabled if .switchOffReason '
5274
+ + 'is set to "disabled-by-publisher".');
5275
+ }
5128
5276
  return this._isEnabled;
5129
5277
  }
5130
5278
  },
@@ -5144,14 +5292,20 @@ function mixinRemoteMediaTrack(AudioOrVideoTrack) {
5144
5292
  enumerable: true,
5145
5293
  value: sid
5146
5294
  },
5147
- _workaroundWebKitBug212780: {
5148
- value: options.workaroundWebKitBug212780
5149
- },
5150
- _workaroundWebKitBug212780Cleanup: {
5151
- value: null,
5152
- writable: true
5295
+ switchOffReason: {
5296
+ enumerable: true,
5297
+ get: function () {
5298
+ return trackSwitchOffReason[this._switchOffReason] || null;
5299
+ }
5153
5300
  }
5154
5301
  });
5302
+ var _a = _this, log = _a._log, name = _a.constructor.name;
5303
+ if (shouldDeprecateEnabledState) {
5304
+ deprecateEvents(name, _this, new Map([
5305
+ ['disabled', 'switchedOff (.switchOffReason === "disabled-by-publisher")'],
5306
+ ['enabled', 'switchedOn']
5307
+ ]), log);
5308
+ }
5155
5309
  return _this;
5156
5310
  }
5157
5311
  /**
@@ -5184,22 +5338,41 @@ function mixinRemoteMediaTrack(AudioOrVideoTrack) {
5184
5338
  this.emit(this._isEnabled ? 'enabled' : 'disabled', this);
5185
5339
  }
5186
5340
  };
5341
+ /**
5342
+ * @private
5343
+ * @param {?MediaTrackReceiver} mediaTrackReceiver
5344
+ */
5345
+ RemoteMediaTrack.prototype._setMediaTrackReceiver = function (mediaTrackReceiver) {
5346
+ if (this._mediaTrackTransceiver !== mediaTrackReceiver) {
5347
+ this._mediaTrackTransceiver = mediaTrackReceiver;
5348
+ this._initialize();
5349
+ this._updateElementsMediaStreamTrack();
5350
+ }
5351
+ };
5187
5352
  /**
5188
5353
  * @private
5189
5354
  * @param {boolean} isSwitchedOff
5355
+ * @param {?string} [switchOffReason=null]
5190
5356
  */
5191
- RemoteMediaTrack.prototype._setSwitchedOff = function (isSwitchedOff) {
5192
- if (this._isSwitchedOff !== isSwitchedOff) {
5357
+ RemoteMediaTrack.prototype._setSwitchedOff = function (isSwitchedOff, switchOffReason) {
5358
+ if (switchOffReason === void 0) { switchOffReason = null; }
5359
+ if (this._isSwitchedOff !== isSwitchedOff || this._switchOffReason !== switchOffReason) {
5193
5360
  this._isSwitchedOff = isSwitchedOff;
5194
- this.emit(isSwitchedOff ? 'switchedOff' : 'switchedOn', this);
5361
+ this._switchOffReason = switchOffReason;
5362
+ this.emit.apply(this, __spreadArray([isSwitchedOff ? 'switchedOff' : 'switchedOn', this], __read((isSwitchedOff ? [this.switchOffReason] : []))));
5195
5363
  }
5196
5364
  };
5197
- RemoteMediaTrack.prototype.attach = function (el) {
5198
- var result = _super.prototype.attach.call(this, el);
5199
- if (this.mediaStreamTrack.enabled !== true) {
5365
+ RemoteMediaTrack.prototype._attach = function () {
5366
+ var returnVal = _super.prototype._attach.apply(this, arguments);
5367
+ if (this._attachments.size > 0 && this.mediaStreamTrack && this.mediaStreamTrack.enabled !== true) {
5200
5368
  // NOTE(mpatwardhan): we disable mediaStreamTrack when there
5201
- // are no attachments to it (see notes below). Now that there
5369
+ // are no attachments to it (see notes in detach function below). Now that there
5202
5370
  // are attachments re-enable the track.
5371
+ // we handle this in _attach instead of public attach below because for large room, we switch mediaStreamTracks between
5372
+ // RemoteMediaTracks as mid changes, invoking this internal _attach.
5373
+ // if we got the mediaStreamTrack from RemoteMediaTrack that was detached, it would have
5374
+ // mediaStreamTrack.enabled set to false which needs to be fixed before attaching.
5375
+ this._log.debug('Enabling mediaStreamTrack that was disabled while detached.');
5203
5376
  this.mediaStreamTrack.enabled = true;
5204
5377
  if (this.processedTrack) {
5205
5378
  this.processedTrack.enabled = true;
@@ -5211,6 +5384,10 @@ function mixinRemoteMediaTrack(AudioOrVideoTrack) {
5211
5384
  this._captureFrames();
5212
5385
  }
5213
5386
  }
5387
+ return returnVal;
5388
+ };
5389
+ RemoteMediaTrack.prototype.attach = function (el) {
5390
+ var result = _super.prototype.attach.call(this, el);
5214
5391
  if (this._workaroundWebKitBug212780) {
5215
5392
  this._workaroundWebKitBug212780Cleanup = this._workaroundWebKitBug212780Cleanup
5216
5393
  || playIfPausedWhileInBackground(this);
@@ -5225,7 +5402,9 @@ function mixinRemoteMediaTrack(AudioOrVideoTrack) {
5225
5402
  // https://bugs.chromium.org/p/chromium/issues/detail?id=749928
5226
5403
  // to workaround: here disable the track when
5227
5404
  // there are no elements attached to it.
5228
- this.mediaStreamTrack.enabled = false;
5405
+ if (this.mediaStreamTrack) {
5406
+ this.mediaStreamTrack.enabled = false;
5407
+ }
5229
5408
  if (this.processedTrack) {
5230
5409
  this.processedTrack.enabled = false;
5231
5410
  }
@@ -5273,25 +5452,38 @@ function playIfPausedWhileInBackground(remoteMediaTrack) {
5273
5452
  };
5274
5453
  }
5275
5454
  /**
5276
- * A {@link RemoteMediaTrack} was disabled.
5455
+ * A {@link RemoteMediaTrack} was disabled (Deprecated only for large group Rooms).
5456
+ * @deprecated Use <a href="#event:switchedOff"><code>switchedOff</code></a> (<code>.switchOffReason !== "disabled-by-publisher"</code>) instead
5277
5457
  * @param {RemoteMediaTrack} track - The {@link RemoteMediaTrack} that was
5278
5458
  * disabled
5279
5459
  * @event RemoteMediaTrack#disabled
5280
5460
  */
5281
5461
  /**
5282
- * A {@link RemoteMediaTrack} was enabled.
5462
+ * A {@link RemoteMediaTrack} was enabled (Deprecated only for large group Rooms).
5463
+ * @deprecated Use <a href="#event:switchedOn"><code>switchedOn</code></a> instead
5283
5464
  * @param {RemoteMediaTrack} track - The {@link RemoteMediaTrack} that was
5284
5465
  * enabled
5285
5466
  * @event RemoteMediaTrack#enabled
5286
5467
  */
5287
5468
  /**
5288
- * A {@link RemoteMediaTrack} was switched off.
5469
+ * A {@link RemoteMediaTrack} was switched off. The media server stops sending media for the
5470
+ * {@link RemoteMediaTrack} until it is switched back on. Just before the event is raised,
5471
+ * <code>isSwitchedOff</code> is set to <code>true</code> and <code>switchOffReason</code> is
5472
+ * set to a {@link TrackSwitchOffReason} in large group Rooms (<code>switchOffReason</code> is
5473
+ * <code>null</code> non-large group Rooms). Also, the <code>mediaStreamTrack</code> property
5474
+ * is set to <code>null</code> (only in large group Rooms).
5289
5475
  * @param {RemoteMediaTrack} track - The {@link RemoteMediaTrack} that was
5290
5476
  * switched off
5477
+ * @param {?TrackSwitchOffReason} switchOffReason - The reason the {@link RemoteMediaTrack}
5478
+ * was switched off
5291
5479
  * @event RemoteMediaTrack#switchedOff
5292
5480
  */
5293
5481
  /**
5294
- * A {@link RemoteMediaTrack} was switched on.
5482
+ * A {@link RemoteMediaTrack} was switched on. The media server starts sending media for the
5483
+ * {@link RemoteMediaTrack} until it is switched off. Just before the event is raised,
5484
+ * <code>isSwitchedOff</code> is set to <code>false</code> and <code>switchOffReason</code>
5485
+ * is set to <code>null</code>. Also, the <code>mediaStreamTrack</code> property is set to a
5486
+ * MediaStreamTrack that is the source of the {@link RemoteMediaTrack}'s media.
5295
5487
  * @param {RemoteMediaTrack} track - The {@link RemoteMediaTrack} that was
5296
5488
  * switched on
5297
5489
  * @event RemoteMediaTrack#switchedOn
@@ -5307,7 +5499,7 @@ function playIfPausedWhileInBackground(remoteMediaTrack) {
5307
5499
  */
5308
5500
  module.exports = mixinRemoteMediaTrack;
5309
5501
 
5310
- },{"../../util/constants":122,"../../util/documentvisibilitymonitor.js":125,"../../webrtc/util":167}],34:[function(require,module,exports){
5502
+ },{"../../util":132,"../../util/constants":126,"../../util/documentvisibilitymonitor.js":129,"../../webrtc/util":171}],34:[function(require,module,exports){
5311
5503
  'use strict';
5312
5504
  var __extends = (this && this.__extends) || (function () {
5313
5505
  var extendStatics = function (d, b) {
@@ -5324,6 +5516,28 @@ var __extends = (this && this.__extends) || (function () {
5324
5516
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
5325
5517
  };
5326
5518
  })();
5519
+ var __read = (this && this.__read) || function (o, n) {
5520
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
5521
+ if (!m) return o;
5522
+ var i = m.call(o), r, ar = [], e;
5523
+ try {
5524
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
5525
+ }
5526
+ catch (error) { e = { error: error }; }
5527
+ finally {
5528
+ try {
5529
+ if (r && !r.done && (m = i["return"])) m.call(i);
5530
+ }
5531
+ finally { if (e) throw e.error; }
5532
+ }
5533
+ return ar;
5534
+ };
5535
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
5536
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
5537
+ to[j] = from[i];
5538
+ return to;
5539
+ };
5540
+ var deprecateEvents = require('../../util').deprecateEvents;
5327
5541
  var TrackPublication = require('./trackpublication');
5328
5542
  /**
5329
5543
  * A {@link RemoteTrackPublication} represents a {@link RemoteTrack} that has
@@ -5331,8 +5545,8 @@ var TrackPublication = require('./trackpublication');
5331
5545
  * @extends TrackPublication
5332
5546
  * @property {boolean} isSubscribed - whether the published {@link RemoteTrack}
5333
5547
  * is subscribed to
5334
- * @property {boolean} isTrackEnabled - whether the published
5335
- * {@link RemoteTrack} is enabled
5548
+ * @property {boolean} isTrackEnabled - <code>Deprecated: Use (track.switchOffReason !== "disabled-by-publisher") instead. This property is only valid if the corresponding RemoteTrack is subscribed to.</code>
5549
+ * whether the published {@link RemoteTrack} is enabled (Deprecated only for large group Rooms)
5336
5550
  * @property {Track.Kind} kind - kind of the published {@link RemoteTrack}
5337
5551
  * @property {Track.Priority} publishPriority - the {@link Track.Priority} of the published
5338
5552
  * {@link RemoteTrack} set by the {@link RemoteParticipant}
@@ -5352,12 +5566,18 @@ var RemoteTrackPublication = /** @class */ (function (_super) {
5352
5566
  __extends(RemoteTrackPublication, _super);
5353
5567
  /**
5354
5568
  * Construct a {@link RemoteTrackPublication}.
5355
- * @param {RemoteTrackPublicationSignaling} signaling - {@link RemoteTrackPublication} signaling
5569
+ * @param {RemoteTrackPublicationV2|RemoteTrackPublicationV3} signaling - {@link RemoteTrackPublication} signaling
5356
5570
  * @param {RemoteTrackPublicationOptions} options - {@link RemoteTrackPublication}
5357
5571
  * options
5358
5572
  */
5359
5573
  function RemoteTrackPublication(signaling, options) {
5360
- var _this = _super.call(this, signaling.name, signaling.sid, options) || this;
5574
+ var _this = this;
5575
+ options = Object.assign({
5576
+ reemitEventsToRemoteParticipant: function () { }
5577
+ }, options);
5578
+ var rspVersion = signaling.rspVersion, sid = signaling.sid, trackName = signaling.name;
5579
+ var shouldDeprecateEnabledState = rspVersion >= 3;
5580
+ _this = _super.call(this, trackName, sid, options) || this;
5361
5581
  Object.defineProperties(_this, {
5362
5582
  _signaling: {
5363
5583
  value: signaling
@@ -5375,6 +5595,12 @@ var RemoteTrackPublication = /** @class */ (function (_super) {
5375
5595
  isTrackEnabled: {
5376
5596
  enumerable: true,
5377
5597
  get: function () {
5598
+ if (shouldDeprecateEnabledState) {
5599
+ this._log.deprecated('.isTrackEnabled is deprecated and scheduled for removal. '
5600
+ + 'During the deprecation period, this property is only valid if the corresponding '
5601
+ + 'RemoteTrack is subscribed to. The RemoteTrack can be considered disabled if '
5602
+ + '.switchOffReason is set to "disabled-by-publisher".');
5603
+ }
5378
5604
  return signaling.isEnabled;
5379
5605
  }
5380
5606
  },
@@ -5396,7 +5622,8 @@ var RemoteTrackPublication = /** @class */ (function (_super) {
5396
5622
  }
5397
5623
  });
5398
5624
  // remember original state, and fire events only on change.
5399
- var error = signaling.error, isEnabled = signaling.isEnabled, isSwitchedOff = signaling.isSwitchedOff, priority = signaling.priority;
5625
+ var error = signaling.error, isEnabled = signaling.isEnabled, isSwitchedOff = signaling.isSwitchedOff, priority = signaling.priority, _a = signaling.switchOffReason, switchOffReason = _a === void 0 ? null : _a, trackTransceiver = signaling.trackTransceiver;
5626
+ var _b = _this, log = _b._log, name = _b.constructor.name;
5400
5627
  signaling.on('updated', function () {
5401
5628
  if (error !== signaling.error) {
5402
5629
  error = signaling.error;
@@ -5410,15 +5637,28 @@ var RemoteTrackPublication = /** @class */ (function (_super) {
5410
5637
  }
5411
5638
  _this.emit(signaling.isEnabled ? 'trackEnabled' : 'trackDisabled');
5412
5639
  }
5413
- if (isSwitchedOff !== signaling.isSwitchedOff) {
5414
- _this._log.debug(_this.trackSid + ": " + (isSwitchedOff ? 'OFF' : 'ON') + " => " + (signaling.isSwitchedOff ? 'OFF' : 'ON'));
5640
+ var newSwitchOffReason = signaling.switchOffReason || null;
5641
+ if (isSwitchedOff !== signaling.isSwitchedOff || switchOffReason !== newSwitchOffReason) {
5642
+ log.debug(_this.trackSid + ": " + (isSwitchedOff ? 'OFF' : 'ON') + " => " + (signaling.isSwitchedOff ? 'OFF' : 'ON'));
5643
+ log.debug(_this.trackSid + " off_reason: " + switchOffReason + " => " + newSwitchOffReason);
5415
5644
  isSwitchedOff = signaling.isSwitchedOff;
5645
+ switchOffReason = newSwitchOffReason;
5416
5646
  if (_this.track) {
5417
- _this.track._setSwitchedOff(signaling.isSwitchedOff);
5418
- _this.emit(isSwitchedOff ? 'trackSwitchedOff' : 'trackSwitchedOn', _this.track);
5647
+ _this.track._setSwitchedOff(signaling.isSwitchedOff, switchOffReason);
5648
+ _this.emit.apply(_this, __spreadArray([isSwitchedOff ? 'trackSwitchedOff' : 'trackSwitchedOn', _this.track], __read((isSwitchedOff ? [_this.track.switchOffReason] : []))));
5649
+ }
5650
+ else {
5651
+ log.debug("Track was not subscribed to when switched " + (isSwitchedOff ? 'off' : 'on') + ".");
5419
5652
  }
5420
- else if (isSwitchedOff) {
5421
- _this._log.warn('Track was not subscribed when switched Off.');
5653
+ }
5654
+ if (trackTransceiver !== signaling.trackTransceiver) {
5655
+ log.debug(_this.trackSid + " MediaTrackReceiver changed:", trackTransceiver, signaling.trackTransceiver);
5656
+ trackTransceiver = signaling.trackTransceiver;
5657
+ if (_this.track && _this.kind !== 'data') {
5658
+ _this.track._setMediaTrackReceiver(trackTransceiver);
5659
+ }
5660
+ else if (!_this.track) {
5661
+ log.debug('Track was not subscribed to when TrackReceiver changed.');
5422
5662
  }
5423
5663
  }
5424
5664
  if (priority !== signaling.priority) {
@@ -5426,6 +5666,13 @@ var RemoteTrackPublication = /** @class */ (function (_super) {
5426
5666
  _this.emit('publishPriorityChanged', priority);
5427
5667
  }
5428
5668
  });
5669
+ options.reemitEventsToRemoteParticipant(_this);
5670
+ if (shouldDeprecateEnabledState) {
5671
+ deprecateEvents(name, _this, new Map([
5672
+ ['trackDisabled', 'trackSwitchedOff (track.switchOffReason === "disabled-by-publisher")'],
5673
+ ['trackEnabled', 'trackSwitchedOn']
5674
+ ]), log);
5675
+ }
5429
5676
  return _this;
5430
5677
  }
5431
5678
  RemoteTrackPublication.prototype.toString = function () {
@@ -5473,20 +5720,37 @@ var RemoteTrackPublication = /** @class */ (function (_super) {
5473
5720
  * @event RemoteTrackPublication#subscriptionFailed
5474
5721
  */
5475
5722
  /**
5476
- * The {@link RemoteTrack} was disabled.
5723
+ * The {@link RemoteTrack} was disabled. In large group Rooms, it is fired only if <code>.isSubscribed</code>
5724
+ * is set to <code>true</code> (Deprecated only for large group Rooms).
5725
+ * @deprecated Use <a href="event:trackSwitchedOff"><code>trackSwitchedOff</code></a> (<code>track.switchOffReason === "disabled-by-publisher"</code>) instead
5477
5726
  * @event RemoteTrackPublication#trackDisabled
5478
5727
  */
5479
5728
  /**
5480
- * The {@link RemoteTrack} was enabled.
5729
+ * The {@link RemoteTrack} was enabled. In large group Rooms, it is fired only if <code>.isSubscribed</code>
5730
+ * is set to <code>true</code> (Deprecated only for large group Rooms).
5731
+ * @deprecated Use <a href="event:trackSwitchedOn"><code>trackSwitchedOn</code></a> instead
5481
5732
  * @event RemoteTrackPublication#trackEnabled
5482
5733
  */
5483
5734
  /**
5484
- * The {@link RemoteTrack} was switched off.
5735
+ * The {@link RemoteTrack} was switched off. The media server stops sending media or data
5736
+ * for the {@link RemoteTrack} until it is switched back on. Just before the event is raised,
5737
+ * <code>isSwitchedOff</code> is set to <code>true</code> and <code>switchOffReason</code>
5738
+ * is set to a {@link TrackSwitchOffReason} in large group Rooms (<code>switchOffReason</code> is
5739
+ * <code>null</code> non-large group Rooms). Also, if the {@link RemoteTrack} receives either
5740
+ * audio or video media, the <code>mediaStreamTrack</code> property is set to <code>null</code>.
5741
+ * (only in large group Rooms)
5485
5742
  * @param {RemoteTrack} track - the {@link RemoteTrack} that was switched off
5743
+ * @param {?TrackSwitchOffReason} switchOffReason - the reason the {@link RemoteTrack}
5744
+ * was switched off
5486
5745
  * @event RemoteTrackPublication#trackSwitchedOff
5487
5746
  */
5488
5747
  /**
5489
- * The {@link RemoteTrack} was switched on.
5748
+ * The {@link RemoteTrack} was switched on. The media server starts sending media or data
5749
+ * for the {@link RemoteMediaTrack} until it is switched off. Just before the event is raised,
5750
+ * <code>isSwitchedOff</code> is set to <code>false</code> and <code>switchOffReason</code>
5751
+ * is set to <code>null</code>. Also, if the {@link RemoteTrack} receives either audio or video
5752
+ * media,the <code>mediaStreamTrack</code> property is set to a MediaStreamTrack that is the
5753
+ * source of the {@link RemoteTrack}'s media.
5490
5754
  * @param {RemoteTrack} track - the {@link RemoteTrack} that was switched on
5491
5755
  * @event RemoteTrackPublication#trackSwitchedOn
5492
5756
  */
@@ -5502,7 +5766,7 @@ var RemoteTrackPublication = /** @class */ (function (_super) {
5502
5766
  */
5503
5767
  module.exports = RemoteTrackPublication;
5504
5768
 
5505
- },{"./trackpublication":38}],35:[function(require,module,exports){
5769
+ },{"../../util":132,"./trackpublication":38}],35:[function(require,module,exports){
5506
5770
  'use strict';
5507
5771
  var __extends = (this && this.__extends) || (function () {
5508
5772
  var extendStatics = function (d, b) {
@@ -5546,9 +5810,12 @@ var TRACK_TURN_OF_DELAY_MS = 50;
5546
5810
  * A {@link RemoteVideoTrack} represents a {@link VideoTrack} published to a
5547
5811
  * {@link Room} by a {@link RemoteParticipant}.
5548
5812
  * @extends VideoTrack
5549
- * @property {boolean} isEnabled - Whether the {@link RemoteVideoTrack} is enabled
5813
+ * @property {boolean} isEnabled - <code>Deprecated: Use (.switchOffReason !== "disabled-by-publisher") instead</code>
5814
+ * Whether the {@link RemoteVideoTrack} is enabled (Deprecated only for large group Rooms)
5550
5815
  * @property {boolean} isSwitchedOff - Whether the {@link RemoteVideoTrack} is switched off
5551
- * @property {Track.SID} sid - The {@link RemoteVideoTrack}'s SID
5816
+ * @property {?TrackSwitchOffReason} switchOffReason - The reason for the {@link RemoteVideoTrack} being switched off;
5817
+ * If switched on, it is set to <code>null</code>; The {@link RemoteVideoTrack} is initially switched off with this
5818
+ * property set to <code>disabled-by-subscriber</code> * @property {Track.SID} sid - The {@link RemoteVideoTrack}'s SID
5552
5819
  * @property {?Track.Priority} priority - The subscribe priority of the {@link RemoteVideoTrack}
5553
5820
  * @emits RemoteVideoTrack#dimensionsChanged
5554
5821
  * @emits RemoteVideoTrack#disabled
@@ -5562,26 +5829,27 @@ var RemoteVideoTrack = /** @class */ (function (_super) {
5562
5829
  /**
5563
5830
  * Construct a {@link RemoteVideoTrack}.
5564
5831
  * @param {Track.SID} sid - The {@link RemoteVideoTrack}'s SID
5565
- * @param {MediaTrackReceiver} mediaTrackReceiver - A video MediaStreamTrack container
5832
+ * @param {?MediaTrackReceiver} mediaTrackReceiver - A video MediaStreamTrack container
5566
5833
  * @param {boolean} isEnabled - whether the {@link RemoteVideoTrack} is enabled
5567
5834
  * @param {boolean} isSwitchedOff - Whether the {@link RemoteVideoTrack} is switched off
5835
+ * @param {?string} switchOffReason - The reason the {@link RemoteVideoTrack} is switched off
5568
5836
  * @param {function(?Track.Priority): void} setPriority - Set or clear the subscribe
5569
5837
  * {@link Track.Priority} of the {@link RemoteVideoTrack}
5570
5838
  * @param {function(ClientRenderHint): void} setRenderHint - Set render hints.
5571
- * @param {{log: Log}} options - The {@link RemoteTrack} options
5839
+ * @param {{log: Log, name: string}} options - The {@link RemoteTrack} options
5572
5840
  */
5573
- function RemoteVideoTrack(sid, mediaTrackReceiver, isEnabled, isSwitchedOff, setPriority, setRenderHint, options) {
5841
+ function RemoteVideoTrack(sid, mediaTrackReceiver, isEnabled, isSwitchedOff, switchOffReason, setPriority, setRenderHint, options) {
5574
5842
  var _this = this;
5575
5843
  options = Object.assign({
5576
5844
  clientTrackSwitchOffControl: 'auto',
5577
5845
  contentPreferencesMode: 'auto',
5578
- enableDocumentVisibilityTurnOff: true,
5846
+ enableDocumentVisibilityTurnOff: true
5579
5847
  }, options);
5580
5848
  options = Object.assign({
5581
5849
  IntersectionObserver: typeof IntersectionObserver === 'undefined' || options.clientTrackSwitchOffControl !== 'auto' ? NullObserver : IntersectionObserver,
5582
- ResizeObserver: typeof ResizeObserver === 'undefined' || options.contentPreferencesMode !== 'auto' ? NullObserver : ResizeObserver,
5850
+ ResizeObserver: typeof ResizeObserver === 'undefined' || options.contentPreferencesMode !== 'auto' ? NullObserver : ResizeObserver
5583
5851
  }, options);
5584
- _this = _super.call(this, sid, mediaTrackReceiver, isEnabled, isSwitchedOff, setPriority, setRenderHint, options) || this;
5852
+ _this = _super.call(this, 'video', sid, mediaTrackReceiver, isEnabled, isSwitchedOff, switchOffReason, setPriority, setRenderHint, options) || this;
5585
5853
  Object.defineProperties(_this, {
5586
5854
  _enableDocumentVisibilityTurnOff: {
5587
5855
  value: options.enableDocumentVisibilityTurnOff === true && options.clientTrackSwitchOffControl === 'auto',
@@ -5659,6 +5927,21 @@ var RemoteVideoTrack = /** @class */ (function (_super) {
5659
5927
  maybeUpdateEnabledHint(this);
5660
5928
  return result;
5661
5929
  };
5930
+ /**
5931
+ * @private
5932
+ * @override
5933
+ * @param {?MediaTrackReceiver} mediaTrackReceiver
5934
+ */
5935
+ RemoteVideoTrack.prototype._setMediaTrackReceiver = function (mediaTrackReceiver) {
5936
+ var processor = this.processor;
5937
+ if (processor) {
5938
+ this.removeProcessor(processor);
5939
+ }
5940
+ _super.prototype._setMediaTrackReceiver.call(this, mediaTrackReceiver);
5941
+ if (processor) {
5942
+ this.addProcessor(processor);
5943
+ }
5944
+ };
5662
5945
  /**
5663
5946
  * Request to switch on a {@link RemoteVideoTrack}, This method is applicable only for the group rooms and only when connected with
5664
5947
  * clientTrackSwitchOffControl in video bandwidth profile options set to 'manual'
@@ -5905,13 +6188,15 @@ function maybeUpdateDimensionHint(remoteVideoTrack) {
5905
6188
  * @event RemoteVideoTrack#dimensionsChanged
5906
6189
  */
5907
6190
  /**
5908
- * The {@link RemoteVideoTrack} was disabled, i.e. "paused".
6191
+ * The {@link RemoteVideoTrack} was disabled, i.e. "paused" (Deprecated only for large group Rooms).
6192
+ * @deprecated Use <a href="#event:switchedOff"><code>switchedOff</code></a> (<code>.switchOffReason === "disabled-by-publisher"</code>) instead
5909
6193
  * @param {RemoteVideoTrack} track - The {@link RemoteVideoTrack} that was
5910
6194
  * disabled
5911
6195
  * @event RemoteVideoTrack#disabled
5912
6196
  */
5913
6197
  /**
5914
- * The {@link RemoteVideoTrack} was enabled, i.e. "resumed".
6198
+ * The {@link RemoteVideoTrack} was enabled, i.e. "resumed" (Deprecated only for large group Rooms).
6199
+ * @deprecated Use <a href="#event:switchedOn"><code>switchedOn</code></a> instead
5915
6200
  * @param {RemoteVideoTrack} track - The {@link RemoteVideoTrack} that was
5916
6201
  * enabled
5917
6202
  * @event RemoteVideoTrack#enabled
@@ -5923,9 +6208,16 @@ function maybeUpdateDimensionHint(remoteVideoTrack) {
5923
6208
  * @event RemoteVideoTrack#started
5924
6209
  */
5925
6210
  /**
5926
- * A {@link RemoteVideoTrack} was switched off.
6211
+ * A {@link RemoteVideoTrack} was switched off. The media server stops sending media for the
6212
+ * {@link RemoteVideoTrack} until it is switched back on. Just before the event is raised,
6213
+ * <code>isSwitchedOff</code> is set to <code>true</code> and <code>switchOffReason</code> is
6214
+ * set to a {@link TrackSwitchOffReason} in large group Rooms (<code>switchOffReason</code> is
6215
+ * <code>null</code> non-large group Rooms). Also, the <code>mediaStreamTrack</code> property
6216
+ * is set to <code>null</code> (only in large group Rooms).
5927
6217
  * @param {RemoteVideoTrack} track - The {@link RemoteVideoTrack} that was
5928
6218
  * switched off
6219
+ * @param {?TrackSwitchOffReason} switchOffReason - The reason the {@link RemoteVideoTrack}
6220
+ * was switched off
5929
6221
  * @event RemoteVideoTrack#switchedOff
5930
6222
  */
5931
6223
  /**
@@ -5936,7 +6228,7 @@ function maybeUpdateDimensionHint(remoteVideoTrack) {
5936
6228
  */
5937
6229
  module.exports = RemoteVideoTrack;
5938
6230
 
5939
- },{"../../util/documentvisibilitymonitor.js":125,"../../util/nullobserver.js":135,"../../util/timeout":142,"./remotemediatrack":33,"./videotrack":41}],36:[function(require,module,exports){
6231
+ },{"../../util/documentvisibilitymonitor.js":129,"../../util/nullobserver.js":139,"../../util/timeout":146,"./remotemediatrack":33,"./videotrack":41}],36:[function(require,module,exports){
5940
6232
  'use strict';
5941
6233
  var __extends = (this && this.__extends) || (function () {
5942
6234
  var extendStatics = function (d, b) {
@@ -5994,13 +6286,39 @@ var RemoteVideoTrackPublication = /** @class */ (function (_super) {
5994
6286
  * @event RemoteVideoTrackPublication#subscriptionFailed
5995
6287
  */
5996
6288
  /**
5997
- * The {@link RemoteVideoTrack} was disabled.
6289
+ * The {@link RemoteVideoTrack} was disabled. It is fired only if <code>.isSubscribed</code>
6290
+ * is set to <code>true</code> (Deprecated only for large group Rooms).
6291
+ * @deprecated Use <a href="event:trackSwitchedOff"><code>trackSwitchedOff</code></a> (<code>track.switchOffReason === "disabled-by-publisher"</code>) instead
5998
6292
  * @event RemoteVideoTrackPublication#trackDisabled
5999
6293
  */
6000
6294
  /**
6001
- * The {@link RemoteVideoTrack} was enabled.
6295
+ * The {@link RemoteVideoTrack} was enabled. It is fired only if <code>.isSubscribed</code>
6296
+ * is set to <code>true</code> (Deprecated only for large group Rooms).
6297
+ * @deprecated Use <a href="event:trackSwitchedOn"><code>trackSwitchedOn</code></a> instead
6002
6298
  * @event RemoteVideoTrackPublication#trackEnabled
6003
6299
  */
6300
+ /**
6301
+ * The {@link RemoteVideoTrack} was switched off. The media server stops sending media for
6302
+ * the {@link RemoteVideoTrack} until it is switched back on. Just before the event is raised,
6303
+ * <code>isSwitchedOff</code> is set to <code>true</code> and <code>switchOffReason</code>
6304
+ * is set to a {@link TrackSwitchOffReason} in large group Rooms (<code>switchOffReason</code> is
6305
+ * <code>null</code> non-large group Rooms). Also, if the {@link RemoteVideoTrack} receives audio
6306
+ * media, the <code>mediaStreamTrack</code> property is set to <code>null</code>. (only in large
6307
+ * group Rooms)
6308
+ * @param {RemoteVideoTrack} track - the {@link RemoteVideoTrack} that was switched off
6309
+ * @param {?TrackSwitchOffReason} switchOffReason - the reason the {@link RemoteVideoTrack}
6310
+ * was switched off
6311
+ * @event RemoteVideoTrackPublication#trackSwitchedOff
6312
+ */
6313
+ /**
6314
+ * The {@link RemoteVideoTrack} was switched on. The media server starts sending media for
6315
+ * the {@link RemoteVideoTrack} until it is switched off. Just before the event is raised,
6316
+ * <code>isSwitchedOff</code> is set to <code>false</code> and <code>switchOffReason</code>
6317
+ * is set to <code>null</code>. Also, the <code>mediaStreamTrack</code> property is set to a
6318
+ * MediaStreamTrack that is the source of the {@link RemoteVideoTrack}'s media.
6319
+ * @param {RemoteVideoTrack} track - the {@link RemoteVideoTrack} that was switched on
6320
+ * @event RemoteVideoTrackPublication#trackSwitchedOn
6321
+ */
6004
6322
  /**
6005
6323
  * Your {@link LocalParticipant} unsubscribed from the {@link RemoteVideoTrack}.
6006
6324
  * @param {RemoteVideoTrack} track - the {@link RemoteVideoTrack} that was unsubscribed from
@@ -6054,7 +6372,7 @@ var MediaTrackSender = /** @class */ (function (_super) {
6054
6372
  * @param {MediaStreamTrack} mediaStreamTrack
6055
6373
  */
6056
6374
  function MediaTrackSender(mediaStreamTrack) {
6057
- var _this = _super.call(this, mediaStreamTrack.id, mediaStreamTrack) || this;
6375
+ var _this = _super.call(this, mediaStreamTrack.id, null, mediaStreamTrack) || this;
6058
6376
  Object.defineProperties(_this, {
6059
6377
  _clones: {
6060
6378
  value: new Set()
@@ -6254,7 +6572,7 @@ var TrackPublication = /** @class */ (function (_super) {
6254
6572
  */
6255
6573
  module.exports = TrackPublication;
6256
6574
 
6257
- },{"../../eventemitter":10,"../../util":128,"../../util/constants":122,"../../util/log":132}],39:[function(require,module,exports){
6575
+ },{"../../eventemitter":10,"../../util":132,"../../util/constants":126,"../../util/log":136}],39:[function(require,module,exports){
6258
6576
  'use strict';
6259
6577
  var __extends = (this && this.__extends) || (function () {
6260
6578
  var extendStatics = function (d, b) {
@@ -6283,9 +6601,10 @@ var MediaTrackTransceiver = /** @class */ (function (_super) {
6283
6601
  /**
6284
6602
  * Construct a {@link MediaTrackTransceiver}.
6285
6603
  * @param {Track.ID} id - The MediaStreamTrack ID signaled through RSP/SDP
6604
+ * @param {?string} mid - The MID associated with the MediaStreamTrack
6286
6605
  * @param {MediaStreamTrack} mediaStreamTrack
6287
6606
  */
6288
- function MediaTrackTransceiver(id, mediaStreamTrack) {
6607
+ function MediaTrackTransceiver(id, mid, mediaStreamTrack) {
6289
6608
  var _this = _super.call(this, id, mediaStreamTrack.kind) || this;
6290
6609
  Object.defineProperties(_this, {
6291
6610
  _track: {
@@ -6298,6 +6617,10 @@ var MediaTrackTransceiver = /** @class */ (function (_super) {
6298
6617
  return this._track.enabled;
6299
6618
  }
6300
6619
  },
6620
+ mid: {
6621
+ enumerable: true,
6622
+ value: mid
6623
+ },
6301
6624
  readyState: {
6302
6625
  enumerable: true,
6303
6626
  get: function () {
@@ -6321,7 +6644,7 @@ var MediaTrackTransceiver = /** @class */ (function (_super) {
6321
6644
  }(TrackTransceiver));
6322
6645
  module.exports = MediaTrackTransceiver;
6323
6646
 
6324
- },{"../../transceiver":116}],40:[function(require,module,exports){
6647
+ },{"../../transceiver":120}],40:[function(require,module,exports){
6325
6648
  'use strict';
6326
6649
  var __extends = (this && this.__extends) || (function () {
6327
6650
  var extendStatics = function (d, b) {
@@ -6476,7 +6799,7 @@ var VideoProcessorEventObserver = /** @class */ (function (_super) {
6476
6799
  }(EventEmitter));
6477
6800
  module.exports = VideoProcessorEventObserver;
6478
6801
 
6479
- },{"../../util/constants":122,"events":170}],41:[function(require,module,exports){
6802
+ },{"../../util/constants":126,"events":174}],41:[function(require,module,exports){
6480
6803
  'use strict';
6481
6804
  var __extends = (this && this.__extends) || (function () {
6482
6805
  var extendStatics = function (d, b) {
@@ -6507,7 +6830,9 @@ var DEFAULT_FRAME_RATE = require('../../util/constants').DEFAULT_FRAME_RATE;
6507
6830
  * @property {VideoTrack.Dimensions} dimensions - The {@link VideoTrack}'s
6508
6831
  * {@link VideoTrack.Dimensions}
6509
6832
  * @property {Track.Kind} kind - "video"
6510
- * @property {MediaStreamTrack} mediaStreamTrack - A video MediaStreamTrack
6833
+ * @property {?MediaStreamTrack} mediaStreamTrack - Provides access to the underlying
6834
+ * MediaStreamTrack; It is set to <code>null</code> if it is a {@link RemoteVideoTrack}
6835
+ * that is switched off
6511
6836
  * @property {?MediaStreamTrack} processedTrack - The source of processed video frames.
6512
6837
  * It is null if no VideoProcessor has been added.
6513
6838
  * @property {?VideoProcessor} processor - A {@link VideoProcessor} that is currently
@@ -6521,11 +6846,15 @@ var VideoTrack = /** @class */ (function (_super) {
6521
6846
  __extends(VideoTrack, _super);
6522
6847
  /**
6523
6848
  * Construct a {@link VideoTrack}.
6524
- * @param {MediaTrackTransceiver} mediaTrackTransceiver
6525
- * @param {{log: Log}} options
6849
+ * @param {?MediaTrackTransceiver} mediaTrackTransceiver
6850
+ * @param {{log: Log, name: string}} options
6526
6851
  */
6527
6852
  function VideoTrack(mediaTrackTransceiver, options) {
6528
- var _this = _super.call(this, mediaTrackTransceiver, options) || this;
6853
+ var _this = this;
6854
+ options = Object.assign({
6855
+ VideoProcessorEventObserver: VideoProcessorEventObserver
6856
+ }, options);
6857
+ _this = _super.call(this, 'video', mediaTrackTransceiver, options) || this;
6529
6858
  Object.defineProperties(_this, {
6530
6859
  _captureTimeoutId: {
6531
6860
  value: null,
@@ -6544,7 +6873,7 @@ var VideoTrack = /** @class */ (function (_super) {
6544
6873
  writable: true
6545
6874
  },
6546
6875
  _processorEventObserver: {
6547
- value: null,
6876
+ value: new options.VideoProcessorEventObserver(_this._log),
6548
6877
  writable: true,
6549
6878
  },
6550
6879
  _unmuteHandler: {
@@ -6564,7 +6893,6 @@ var VideoTrack = /** @class */ (function (_super) {
6564
6893
  writable: true
6565
6894
  }
6566
6895
  });
6567
- _this._processorEventObserver = new (options.VideoProcessorEventObserver || VideoProcessorEventObserver)(_this._log);
6568
6896
  return _this;
6569
6897
  }
6570
6898
  /**
@@ -6574,20 +6902,23 @@ var VideoTrack = /** @class */ (function (_super) {
6574
6902
  if (isPublishing === void 0) { isPublishing = false; }
6575
6903
  var canCaptureFrames = true;
6576
6904
  var message = '';
6577
- var _a = this.mediaStreamTrack, enabled = _a.enabled, readyState = _a.readyState;
6578
- if (!enabled) {
6905
+ if (!this.mediaStreamTrack) {
6906
+ canCaptureFrames = false;
6907
+ message = 'MediaStreamTrack is null';
6908
+ }
6909
+ else if (!this.mediaStreamTrack.enabled) {
6579
6910
  canCaptureFrames = false;
6580
6911
  message = 'MediaStreamTrack is disabled';
6581
6912
  }
6582
- if (readyState === 'ended') {
6913
+ else if (this.mediaStreamTrack.readyState === 'ended') {
6583
6914
  canCaptureFrames = false;
6584
6915
  message = 'MediaStreamTrack is ended';
6585
6916
  }
6586
- if (!this.processor) {
6917
+ else if (!this.processor) {
6587
6918
  canCaptureFrames = false;
6588
6919
  message = 'VideoProcessor not detected.';
6589
6920
  }
6590
- if (!this._attachments.size && !isPublishing) {
6921
+ else if (!this._attachments.size && !isPublishing) {
6591
6922
  canCaptureFrames = false;
6592
6923
  message = 'VideoTrack is not publishing and there is no attached element.';
6593
6924
  }
@@ -6618,7 +6949,9 @@ var VideoTrack = /** @class */ (function (_super) {
6618
6949
  this._dummyEl.play().then(function () {
6619
6950
  var captureFrame = function (cb) {
6620
6951
  clearTimeout(_this._captureTimeoutId);
6621
- var _a = _this.mediaStreamTrack.getSettings().frameRate, frameRate = _a === void 0 ? DEFAULT_FRAME_RATE : _a;
6952
+ var _a = (_this.mediaStreamTrack
6953
+ ? _this.mediaStreamTrack.getSettings()
6954
+ : {}).frameRate, frameRate = _a === void 0 ? DEFAULT_FRAME_RATE : _a;
6622
6955
  var capturePeriodMs = Math.floor(1000 / frameRate);
6623
6956
  var delay = capturePeriodMs - processFramePeriodMs;
6624
6957
  if (delay < 0 || typeof processFramePeriodMs !== 'number') {
@@ -6761,15 +7094,19 @@ var VideoTrack = /** @class */ (function (_super) {
6761
7094
  _this._restartProcessor();
6762
7095
  }
6763
7096
  };
6764
- this.mediaStreamTrack.addEventListener('unmute', this._unmuteHandler);
7097
+ if (this.mediaStreamTrack) {
7098
+ this.mediaStreamTrack.addEventListener('unmute', this._unmuteHandler);
7099
+ }
6765
7100
  }
6766
- var _a = this.mediaStreamTrack.getSettings(), _b = _a.width, width = _b === void 0 ? 0 : _b, _c = _a.height, height = _c === void 0 ? 0 : _c, _d = _a.frameRate, frameRate = _d === void 0 ? DEFAULT_FRAME_RATE : _d;
7101
+ var _a = this.mediaStreamTrack
7102
+ ? this.mediaStreamTrack.getSettings()
7103
+ : {}, _b = _a.width, width = _b === void 0 ? 0 : _b, _c = _a.height, height = _c === void 0 ? 0 : _c, _d = _a.frameRate, frameRate = _d === void 0 ? DEFAULT_FRAME_RATE : _d;
6767
7104
  this._inputFrame = new OffscreenCanvas(width, height);
6768
7105
  this._outputFrame = document.createElement('canvas');
6769
7106
  this._outputFrame.width = width;
6770
7107
  this._outputFrame.height = height;
6771
7108
  this.processedTrack = this._outputFrame.captureStream(0).getTracks()[0];
6772
- this.processedTrack.enabled = this.mediaStreamTrack.enabled;
7109
+ this.processedTrack.enabled = !!(this.mediaStreamTrack && this.mediaStreamTrack.enabled);
6773
7110
  this.processor = processor;
6774
7111
  this._processorEventObserver.emit('add', {
6775
7112
  processor: processor,
@@ -6912,7 +7249,9 @@ var VideoTrack = /** @class */ (function (_super) {
6912
7249
  this._processorEventObserver.emit('remove');
6913
7250
  this._log.debug('Removing VideoProcessor from the VideoTrack', processor);
6914
7251
  clearTimeout(this._captureTimeoutId);
6915
- this.mediaStreamTrack.removeEventListener('unmute', this._unmuteHandler);
7252
+ if (this.mediaStreamTrack) {
7253
+ this.mediaStreamTrack.removeEventListener('unmute', this._unmuteHandler);
7254
+ }
6916
7255
  this._unmuteHandler = null;
6917
7256
  this._isCapturing = false;
6918
7257
  this.processor = null;
@@ -6991,7 +7330,7 @@ function dimensionsChanged(track, elem) {
6991
7330
  */
6992
7331
  module.exports = VideoTrack;
6993
7332
 
6994
- },{"../../util/constants":122,"./mediatrack":27,"./videoprocessoreventobserver":40}],42:[function(require,module,exports){
7333
+ },{"../../util/constants":126,"./mediatrack":27,"./videoprocessoreventobserver":40}],42:[function(require,module,exports){
6995
7334
  'use strict';
6996
7335
  var __extends = (this && this.__extends) || (function () {
6997
7336
  var extendStatics = function (d, b) {
@@ -7090,7 +7429,7 @@ var NetworkQualityConfigurationImpl = /** @class */ (function (_super) {
7090
7429
  }(EventEmitter));
7091
7430
  module.exports = NetworkQualityConfigurationImpl;
7092
7431
 
7093
- },{"./util":128,"./util/constants":122,"events":170}],43:[function(require,module,exports){
7432
+ },{"./util":132,"./util/constants":126,"events":174}],43:[function(require,module,exports){
7094
7433
  'use strict';
7095
7434
  var __extends = (this && this.__extends) || (function () {
7096
7435
  var extendStatics = function (d, b) {
@@ -7135,7 +7474,7 @@ var RemoteDataTrack = require('./media/track/remotedatatrack');
7135
7474
  var RemoteDataTrackPublication = require('./media/track/remotedatatrackpublication');
7136
7475
  var RemoteVideoTrack = require('./media/track/remotevideotrack');
7137
7476
  var RemoteVideoTrackPublication = require('./media/track/remotevideotrackpublication');
7138
- var util = require('./util');
7477
+ var _a = require('./util'), reemitTrackPublicationEvents = _a.reemitTrackPublicationEvents, trackClass = _a.trackClass, trackPublicationClass = _a.trackPublicationClass, valueToJSON = _a.valueToJSON;
7139
7478
  var nInstances = 0;
7140
7479
  /**
7141
7480
  * {@link NetworkQualityLevel} is a value from 0–5, inclusive, representing the
@@ -7326,31 +7665,31 @@ var Participant = /** @class */ (function (_super) {
7326
7665
  };
7327
7666
  /**
7328
7667
  * @private
7329
- * @param {RemoteTrack} track
7330
- * @param {Track.ID} id
7331
- * @returns {?RemoteTrack}
7668
+ * @param {Track} track
7669
+ * @param {key} key
7670
+ * @returns {?Track}
7332
7671
  */
7333
- Participant.prototype._addTrack = function (track, id) {
7672
+ Participant.prototype._addTrack = function (track, key) {
7334
7673
  var log = this._log;
7335
- if (this._tracks.has(id)) {
7674
+ if (this._tracks.has(key)) {
7336
7675
  return null;
7337
7676
  }
7338
- this._tracks.set(id, track);
7677
+ this._tracks.set(key, track);
7339
7678
  var tracksByKind = {
7340
7679
  audio: this._audioTracks,
7341
7680
  video: this._videoTracks,
7342
7681
  data: this._dataTracks
7343
7682
  }[track.kind];
7344
- tracksByKind.set(id, track);
7345
- reemitTrackEvents(this, track, id);
7346
- log.info("Added a new " + util.trackClass(track) + ":", id);
7347
- log.debug(util.trackClass(track) + ":", track);
7683
+ tracksByKind.set(key, track);
7684
+ reemitTrackEvents(this, track, key);
7685
+ log.info("Added a new " + trackClass(track) + ":", key);
7686
+ log.debug(trackClass(track) + ":", track);
7348
7687
  return track;
7349
7688
  };
7350
7689
  /**
7351
7690
  * @private
7352
- * @param {RemoteTrackPublication} publication
7353
- * @returns {?RemoteTrackPublication}
7691
+ * @param {TrackPublication} publication
7692
+ * @returns {?TrackPublication}
7354
7693
  */
7355
7694
  Participant.prototype._addTrackPublication = function (publication) {
7356
7695
  var log = this._log;
@@ -7364,9 +7703,8 @@ var Participant = /** @class */ (function (_super) {
7364
7703
  video: this.videoTracks
7365
7704
  }[publication.kind];
7366
7705
  trackPublicationsByKind.set(publication.trackSid, publication);
7367
- reemitTrackPublicationEvents(this, publication);
7368
- log.info("Added a new " + util.trackPublicationClass(publication) + ":", publication.trackSid);
7369
- log.debug(util.trackPublicationClass(publication) + ":", publication);
7706
+ log.info("Added a new " + trackPublicationClass(publication) + ":", publication.trackSid);
7707
+ log.debug(trackPublicationClass(publication) + ":", publication);
7370
7708
  return publication;
7371
7709
  };
7372
7710
  /**
@@ -7386,12 +7724,15 @@ var Participant = /** @class */ (function (_super) {
7386
7724
  var RemoteDataTrackPublication = this._RemoteDataTrackPublication;
7387
7725
  var participantSignaling = this._signaling;
7388
7726
  function trackSignalingAdded(signaling) {
7727
+ var reemitEventsToRemoteParticipant = function (publication) {
7728
+ reemitTrackPublicationEvents(self, publication);
7729
+ };
7389
7730
  var RemoteTrackPublication = {
7390
7731
  audio: RemoteAudioTrackPublication,
7391
7732
  data: RemoteDataTrackPublication,
7392
7733
  video: RemoteVideoTrackPublication
7393
7734
  }[signaling.kind];
7394
- var publication = new RemoteTrackPublication(signaling, { log: log });
7735
+ var publication = new RemoteTrackPublication(signaling, { log: log, reemitEventsToRemoteParticipant: reemitEventsToRemoteParticipant });
7395
7736
  self._addTrackPublication(publication);
7396
7737
  var isSubscribed = signaling.isSubscribed;
7397
7738
  if (isSubscribed) {
@@ -7411,7 +7752,7 @@ var Participant = /** @class */ (function (_super) {
7411
7752
  }
7412
7753
  function trackSignalingRemoved(signaling) {
7413
7754
  if (signaling.isSubscribed) {
7414
- signaling.setTrackTransceiver(null);
7755
+ signaling.setTrackTransceiver(null, false);
7415
7756
  }
7416
7757
  var updated = self._trackSignalingUpdatedEventCallbacks.get(signaling.sid);
7417
7758
  if (updated) {
@@ -7424,20 +7765,14 @@ var Participant = /** @class */ (function (_super) {
7424
7765
  }
7425
7766
  }
7426
7767
  function trackSignalingSubscribed(signaling) {
7427
- var isEnabled = signaling.isEnabled, name = signaling.name, kind = signaling.kind, sid = signaling.sid, trackTransceiver = signaling.trackTransceiver, isSwitchedOff = signaling.isSwitchedOff;
7768
+ var isEnabled = signaling.isEnabled, name = signaling.name, kind = signaling.kind, sid = signaling.sid, trackTransceiver = signaling.trackTransceiver, isSwitchedOff = signaling.isSwitchedOff, rspVersion = signaling.rspVersion, _a = signaling.switchOffReason, switchOffReason = _a === void 0 ? null : _a;
7428
7769
  var RemoteTrack = {
7429
7770
  audio: RemoteAudioTrack,
7430
7771
  video: RemoteVideoTrack,
7431
7772
  data: RemoteDataTrack
7432
7773
  }[kind];
7433
7774
  var publication = self.tracks.get(sid);
7434
- // NOTE(mroberts): It should never be the case that the TrackSignaling and
7435
- // MediaStreamTrack or DataTrackReceiver kinds disagree; however, just in
7436
- // case, we handle it here.
7437
- if (!RemoteTrack || kind !== trackTransceiver.kind) {
7438
- return;
7439
- }
7440
- var options = { log: log, name: name, clientTrackSwitchOffControl: clientTrackSwitchOffControl, contentPreferencesMode: contentPreferencesMode };
7775
+ var options = { log: log, name: name, clientTrackSwitchOffControl: clientTrackSwitchOffControl, contentPreferencesMode: contentPreferencesMode, shouldDeprecateEnabledState: rspVersion >= 3 };
7441
7776
  var setPriority = function (newPriority) { return participantSignaling.updateSubscriberTrackPriority(sid, newPriority); };
7442
7777
  var setRenderHint = function (renderHint) {
7443
7778
  if (signaling.isSubscribed) {
@@ -7446,17 +7781,14 @@ var Participant = /** @class */ (function (_super) {
7446
7781
  };
7447
7782
  var track = kind === 'data'
7448
7783
  ? new RemoteTrack(sid, trackTransceiver, options)
7449
- : new RemoteTrack(sid, trackTransceiver, isEnabled, isSwitchedOff, setPriority, setRenderHint, options);
7450
- self._addTrack(track, publication, trackTransceiver.id);
7784
+ : new RemoteTrack(sid, trackTransceiver, isEnabled, isSwitchedOff, switchOffReason, setPriority, setRenderHint, options);
7785
+ self._addTrack(track, publication);
7451
7786
  }
7452
7787
  function trackSignalingUnsubscribed(signaling) {
7453
- var _a = __read(Array.from(self._tracks.entries()).find(function (_a) {
7454
- var _b = __read(_a, 2), track = _b[1];
7455
- return track.sid === signaling.sid;
7456
- }), 2), id = _a[0], track = _a[1];
7788
+ var track = self._tracks.get(signaling.sid);
7457
7789
  var publication = self.tracks.get(signaling.sid);
7458
7790
  if (track) {
7459
- self._removeTrack(track, publication, id);
7791
+ self._removeTrack(track, publication);
7460
7792
  }
7461
7793
  }
7462
7794
  participantSignaling.on('trackAdded', trackSignalingAdded);
@@ -7482,28 +7814,28 @@ var Participant = /** @class */ (function (_super) {
7482
7814
  };
7483
7815
  /**
7484
7816
  * @private
7485
- * @param {RemoteTrack} track
7486
- * @param {Track.ID} id
7487
- * @returns {?RemoteTrack}
7817
+ * @param {Track} track
7818
+ * @param {string} key
7819
+ * @returns {?Track}
7488
7820
  */
7489
- Participant.prototype._removeTrack = function (track, id) {
7490
- if (!this._tracks.has(id)) {
7821
+ Participant.prototype._removeTrack = function (track, key) {
7822
+ if (!this._tracks.has(key)) {
7491
7823
  return null;
7492
7824
  }
7493
- this._tracks.delete(id);
7825
+ this._tracks.delete(key);
7494
7826
  var tracksByKind = {
7495
7827
  audio: this._audioTracks,
7496
7828
  video: this._videoTracks,
7497
7829
  data: this._dataTracks
7498
7830
  }[track.kind];
7499
- tracksByKind.delete(id);
7500
- var reemitters = this._trackEventReemitters.get(id) || new Map();
7831
+ tracksByKind.delete(key);
7832
+ var reemitters = this._trackEventReemitters.get(key) || new Map();
7501
7833
  reemitters.forEach(function (reemitter, event) {
7502
7834
  track.removeListener(event, reemitter);
7503
7835
  });
7504
7836
  var log = this._log;
7505
- log.info("Removed a " + util.trackClass(track) + ":", id);
7506
- log.debug(util.trackClass(track) + ":", track);
7837
+ log.info("Removed a " + trackClass(track) + ":", key);
7838
+ log.debug(trackClass(track) + ":", track);
7507
7839
  return track;
7508
7840
  };
7509
7841
  /**
@@ -7528,12 +7860,12 @@ var Participant = /** @class */ (function (_super) {
7528
7860
  publication.removeListener(event, reemitter);
7529
7861
  });
7530
7862
  var log = this._log;
7531
- log.info("Removed a " + util.trackPublicationClass(publication) + ":", publication.trackSid);
7532
- log.debug(util.trackPublicationClass(publication) + ":", publication);
7863
+ log.info("Removed a " + trackPublicationClass(publication) + ":", publication.trackSid);
7864
+ log.debug(trackPublicationClass(publication) + ":", publication);
7533
7865
  return publication;
7534
7866
  };
7535
7867
  Participant.prototype.toJSON = function () {
7536
- return util.valueToJSON(this);
7868
+ return valueToJSON(this);
7537
7869
  };
7538
7870
  return Participant;
7539
7871
  }(EventEmitter));
@@ -7628,7 +7960,9 @@ function reemitSignalingStateChangedEvents(participant, signaling) {
7628
7960
  log.debug('Removing Track event reemitters');
7629
7961
  signaling.removeListener('stateChanged', stateChanged);
7630
7962
  participant._tracks.forEach(function (track) {
7631
- var reemitters = participant._trackEventReemitters.get(track.id);
7963
+ // NOTE(mmalavalli): Event re-emitters for LocalTracks use the Track.ID as the key,
7964
+ // whereas event re-emitters for RemoteTracks use the Track.SID as the key.
7965
+ var reemitters = participant._trackEventReemitters.get(track.id || track.sid);
7632
7966
  if (track && reemitters) {
7633
7967
  reemitters.forEach(function (reemitter, event) {
7634
7968
  track.removeListener(event, reemitter);
@@ -7639,8 +7973,8 @@ function reemitSignalingStateChangedEvents(participant, signaling) {
7639
7973
  // TODO(joma): Removing this introduced unit test failures in the RemoteParticipant.
7640
7974
  // Investigate further before removing.
7641
7975
  signaling.tracks.forEach(function (trackSignaling) {
7642
- var track = participant._tracks.get(trackSignaling.id);
7643
- var reemitters = participant._trackEventReemitters.get(trackSignaling.id);
7976
+ var track = participant._tracks.get(trackSignaling.sid);
7977
+ var reemitters = participant._trackEventReemitters.get(trackSignaling.sid);
7644
7978
  if (track && reemitters) {
7645
7979
  reemitters.forEach(function (reemitter, event) {
7646
7980
  track.removeListener(event, reemitter);
@@ -7662,10 +7996,10 @@ function reemitSignalingStateChangedEvents(participant, signaling) {
7662
7996
  * Re-emit {@link Track} events.
7663
7997
  * @param {Participant} participant
7664
7998
  * @param {Track} track
7665
- * @param {Track.ID} id
7999
+ * @param {string} key
7666
8000
  * @private
7667
8001
  */
7668
- function reemitTrackEvents(participant, track, id) {
8002
+ function reemitTrackEvents(participant, track, key) {
7669
8003
  var trackEventReemitters = new Map();
7670
8004
  if (participant.state === 'disconnected') {
7671
8005
  return;
@@ -7679,35 +8013,11 @@ function reemitTrackEvents(participant, track, id) {
7679
8013
  });
7680
8014
  track.on(trackEvent, trackEventReemitters.get(trackEvent));
7681
8015
  });
7682
- participant._trackEventReemitters.set(id, trackEventReemitters);
7683
- }
7684
- /**
7685
- * Re-emit {@link TrackPublication} events.
7686
- * @private
7687
- * @param {Participant} participant
7688
- * @param {TrackPublication} publication
7689
- */
7690
- function reemitTrackPublicationEvents(participant, publication) {
7691
- var publicationEventReemitters = new Map();
7692
- if (participant.state === 'disconnected') {
7693
- return;
7694
- }
7695
- participant._getTrackPublicationEvents().forEach(function (_a) {
7696
- var _b = __read(_a, 2), publicationEvent = _b[0], participantEvent = _b[1];
7697
- publicationEventReemitters.set(publicationEvent, function () {
7698
- var args = [];
7699
- for (var _i = 0; _i < arguments.length; _i++) {
7700
- args[_i] = arguments[_i];
7701
- }
7702
- participant.emit.apply(participant, __spreadArray(__spreadArray([participantEvent], __read(args)), [publication]));
7703
- });
7704
- publication.on(publicationEvent, publicationEventReemitters.get(publicationEvent));
7705
- });
7706
- participant._trackPublicationEventReemitters.set(publication.trackSid, publicationEventReemitters);
8016
+ participant._trackEventReemitters.set(key, trackEventReemitters);
7707
8017
  }
7708
8018
  module.exports = Participant;
7709
8019
 
7710
- },{"./eventemitter":10,"./media/track/remoteaudiotrack":29,"./media/track/remoteaudiotrackpublication":30,"./media/track/remotedatatrack":31,"./media/track/remotedatatrackpublication":32,"./media/track/remotevideotrack":35,"./media/track/remotevideotrackpublication":36,"./util":128}],44:[function(require,module,exports){
8020
+ },{"./eventemitter":10,"./media/track/remoteaudiotrack":29,"./media/track/remoteaudiotrackpublication":30,"./media/track/remotedatatrack":31,"./media/track/remotedatatrackpublication":32,"./media/track/remotevideotrack":35,"./media/track/remotevideotrackpublication":36,"./util":132}],44:[function(require,module,exports){
7711
8021
  "use strict";
7712
8022
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7713
8023
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -7909,7 +8219,7 @@ function getTurnCredentials(token, wsServer) {
7909
8219
  }
7910
8220
  exports.getTurnCredentials = getTurnCredentials;
7911
8221
 
7912
- },{"../twilioconnection.js":117,"../util/constants":122,"../util/twilio-video-errors":143,"events":170}],46:[function(require,module,exports){
8222
+ },{"../twilioconnection.js":121,"../util/constants":126,"../util/twilio-video-errors":147,"events":174}],46:[function(require,module,exports){
7913
8223
  "use strict";
7914
8224
  var __read = (this && this.__read) || function (o, n) {
7915
8225
  var m = typeof Symbol === "function" && o[Symbol.iterator];
@@ -8655,7 +8965,7 @@ function runPreflight(token, options) {
8655
8965
  }
8656
8966
  exports.runPreflight = runPreflight;
8657
8967
 
8658
- },{"../eventemitter":10,"../util":128,"../util/constants":122,"../util/eventobserver":126,"../util/insightspublisher":129,"../util/log":132,"../util/movingaveragedelta":133,"../util/sid":140,"../util/twilio-video-errors":143,"./getCombinedConnectionStats":44,"./getturncredentials":45,"./makestat":46,"./mos":47,"./syntheticaudio":49,"./syntheticvideo":50,"./timer":51}],49:[function(require,module,exports){
8968
+ },{"../eventemitter":10,"../util":132,"../util/constants":126,"../util/eventobserver":130,"../util/insightspublisher":133,"../util/log":136,"../util/movingaveragedelta":137,"../util/sid":144,"../util/twilio-video-errors":147,"./getCombinedConnectionStats":44,"./getturncredentials":45,"./makestat":46,"./mos":47,"./syntheticaudio":49,"./syntheticvideo":50,"./timer":51}],49:[function(require,module,exports){
8659
8969
  "use strict";
8660
8970
  Object.defineProperty(exports, "__esModule", { value: true });
8661
8971
  exports.syntheticAudio = void 0;
@@ -8678,7 +8988,7 @@ function syntheticAudio() {
8678
8988
  }
8679
8989
  exports.syntheticAudio = syntheticAudio;
8680
8990
 
8681
- },{"../webaudio/audiocontext":149}],50:[function(require,module,exports){
8991
+ },{"../webaudio/audiocontext":153}],50:[function(require,module,exports){
8682
8992
  "use strict";
8683
8993
  Object.defineProperty(exports, "__esModule", { value: true });
8684
8994
  exports.syntheticVideo = void 0;
@@ -8843,7 +9153,7 @@ var QueueingEventEmitter = /** @class */ (function (_super) {
8843
9153
  }(EventEmitter));
8844
9154
  module.exports = QueueingEventEmitter;
8845
9155
 
8846
- },{"events":170}],53:[function(require,module,exports){
9156
+ },{"events":174}],53:[function(require,module,exports){
8847
9157
  'use strict';
8848
9158
  var __extends = (this && this.__extends) || (function () {
8849
9159
  var extendStatics = function (d, b) {
@@ -8930,11 +9240,10 @@ var RemoteParticipant = /** @class */ (function (_super) {
8930
9240
  * @private
8931
9241
  * @param {RemoteTrack} remoteTrack
8932
9242
  * @param {RemoteTrackPublication} publication
8933
- * @param {Track.ID} id
8934
9243
  * @returns {?RemoteTrack}
8935
9244
  */
8936
- RemoteParticipant.prototype._addTrack = function (remoteTrack, publication, id) {
8937
- if (!_super.prototype._addTrack.call(this, remoteTrack, id)) {
9245
+ RemoteParticipant.prototype._addTrack = function (remoteTrack, publication) {
9246
+ if (!_super.prototype._addTrack.call(this, remoteTrack, remoteTrack.sid)) {
8938
9247
  return null;
8939
9248
  }
8940
9249
  publication._subscribed(remoteTrack);
@@ -8984,15 +9293,14 @@ var RemoteParticipant = /** @class */ (function (_super) {
8984
9293
  * @private
8985
9294
  * @param {RemoteTrack} remoteTrack
8986
9295
  * @param {RemoteTrackPublication} publication
8987
- * @param {Track.ID} id
8988
9296
  * @returns {?RemoteTrack}
8989
9297
  */
8990
- RemoteParticipant.prototype._removeTrack = function (remoteTrack, publication, id) {
8991
- var unsubscribedTrack = this._tracks.get(id);
9298
+ RemoteParticipant.prototype._removeTrack = function (remoteTrack, publication) {
9299
+ var unsubscribedTrack = this._tracks.get(remoteTrack.sid);
8992
9300
  if (!unsubscribedTrack) {
8993
9301
  return null;
8994
9302
  }
8995
- _super.prototype._removeTrack.call(this, unsubscribedTrack, id);
9303
+ _super.prototype._removeTrack.call(this, unsubscribedTrack, unsubscribedTrack.sid);
8996
9304
  publication._unsubscribe();
8997
9305
  this.emit('trackUnsubscribed', unsubscribedTrack, publication);
8998
9306
  return unsubscribedTrack;
@@ -9096,14 +9404,25 @@ var RemoteParticipant = /** @class */ (function (_super) {
9096
9404
  * @event RemoteParticipant#trackPublishPriorityChanged
9097
9405
  */
9098
9406
  /**
9099
- * A {@link RemoteParticipant}'s {@link RemoteTrack} was subscribed to.
9407
+ * A {@link RemoteParticipant}'s {@link RemoteTrack} was switched off. The media server stops
9408
+ * sending media or data for the {@link RemoteTrack} until it is switched back on. Just before
9409
+ * the event is raised, <code>isSwitchedOff</code> is set to <code>true</code> and <code>switchOffReason</code>
9410
+ * is set to a {@link TrackSwitchOffReason}. Also, if the {@link RemoteTrack} receives either audio or video
9411
+ * media, the <code>mediaStreamTrack</code> property is set to <code>null</code>.
9100
9412
  * @param {RemoteTrack} track - The {@link RemoteTrack} that was switched off
9101
9413
  * @param {RemoteTrackPublication} publication - The {@link RemoteTrackPublication}
9102
9414
  * for the {@link RemoteTrack} that was switched off
9415
+ * @param {?TrackSwitchOffReason} switchOffReason - The reason the {@link RemoteMediaTrack}
9416
+ * was switched off
9103
9417
  * @event RemoteParticipant#trackSwitchedOff
9104
9418
  */
9105
9419
  /**
9106
- * A {@link RemoteParticipant}'s {@link RemoteTrack} was switched on.
9420
+ * A {@link RemoteParticipant}'s {@link RemoteTrack} was switched on. The media server starts
9421
+ * sending media for the {@link RemoteTrack} until it is switched off. Just before the event is raised,
9422
+ * <code>isSwitchedOff</code> is set to <code>false</code> and <code>switchOffReason</code>
9423
+ * is set to <code>null</code>. Also, if the {@link RemoteTrack} receives either audio or video media,
9424
+ * the <code>mediaStreamTrack</code> property is set to a MediaStreamTrack that is the source of the
9425
+ * {@link RemoteTrack}'s media.
9107
9426
  * @param {RemoteTrack} track - The {@link RemoteTrack} that was switched on.
9108
9427
  * @param {RemoteTrackPublication} publication - The {@link RemoteTrackPublication}
9109
9428
  * for the {@link RemoteTrack} that was switched on
@@ -9306,8 +9625,8 @@ var Room = /** @class */ (function (_super) {
9306
9625
  };
9307
9626
  /**
9308
9627
  * Get the {@link Room}'s media statistics. This is not supported in Safari 12.0 or below
9309
- * due to this bug : https://bugs.webkit.org/show_bug.cgi?id=192601
9310
- *
9628
+ * due to this bug : https://bugs.webkit.org/show_bug.cgi?id=192601. Note that the values
9629
+ * reported are best-effort approximations based off of the raw WebRTC statistics.
9311
9630
  * @returns {Promise.<Array<StatsReport>>}
9312
9631
  */
9313
9632
  Room.prototype.getStats = function () {
@@ -9527,16 +9846,27 @@ function rewriteLocalTrackIds(room, trackStats) {
9527
9846
  * });
9528
9847
  */
9529
9848
  /**
9530
- * A {@link RemoteParticipant}'s {@link RemoteTrack} was switched off.
9849
+ * A {@link RemoteParticipant}'s {@link RemoteTrack} was switched off. The media server stops
9850
+ * sending media or data for the {@link RemoteTrack} until it is switched back on. Just before
9851
+ * the event is raised, <code>isSwitchedOff</code> is set to <code>true</code> and <code>switchOffReason</code>
9852
+ * is set to a {@link TrackSwitchOffReason}. Also, if the {@link RemoteTrack} receives either audio or video
9853
+ * media, the <code>mediaStreamTrack</code> property is set to <code>null</code>.
9531
9854
  * @param {RemoteTrack} track - The {@link RemoteTrack} that was switched off
9532
9855
  * @param {RemoteTrackPublication} publication - The {@link RemoteTrackPublication}
9533
9856
  * for the {@link RemoteTrack} that was subscribed to
9534
9857
  * @param {RemoteParticipant} participant - The {@link RemoteParticipant} whose
9535
9858
  * {@link RemoteTrack} was switched off
9859
+ * @param {TrackSwitchOffReason} switchOffReason - The reason the {@link RemoteTrack}
9860
+ * was switched off
9536
9861
  * @event Room#trackSwitchedOff
9537
9862
  */
9538
9863
  /**
9539
- * A {@link RemoteParticipant}'s {@link RemoteTrack} was switched on.
9864
+ * A {@link RemoteParticipant}'s {@link RemoteTrack} was switched on. The media server starts
9865
+ * sending media for the {@link RemoteTrack} until it is switched off. Just before the event is raised,
9866
+ * <code>isSwitchedOff</code> is set to <code>false</code> and <code>switchOffReason</code>
9867
+ * is set to <code>null</code>. Also, if the {@link RemoteTrack} receives either audio or video media,
9868
+ * the <code>mediaStreamTrack</code> property is set to a MediaStreamTrack that is the source of the
9869
+ * {@link RemoteTrack}'s media.
9540
9870
  * @param {RemoteTrack} track - The {@link RemoteTrack} that was switched on
9541
9871
  * @param {RemoteTrackPublication} publication - The {@link RemoteTrackPublication}
9542
9872
  * for the {@link RemoteTrack} that was subscribed to
@@ -9653,7 +9983,13 @@ function connectParticipant(room, participantSignaling) {
9653
9983
  function reemit() {
9654
9984
  var args = [].slice.call(arguments);
9655
9985
  args.unshift(participantEvent);
9656
- args.push(participant);
9986
+ if (participantEvent === 'trackSwitchedOff') {
9987
+ var switchOffReason = args.pop();
9988
+ args.push(participant, switchOffReason);
9989
+ }
9990
+ else {
9991
+ args.push(participant);
9992
+ }
9657
9993
  room.emit.apply(room, __spreadArray([], __read(args)));
9658
9994
  }
9659
9995
  participant.on(event, reemit);
@@ -9739,7 +10075,7 @@ function handleSignalingEvents(room, signaling) {
9739
10075
  }
9740
10076
  module.exports = Room;
9741
10077
 
9742
- },{"./eventemitter":10,"./remoteparticipant":53,"./stats/statsreport":113,"./util":128}],55:[function(require,module,exports){
10078
+ },{"./eventemitter":10,"./remoteparticipant":53,"./stats/statsreport":117,"./util":132}],55:[function(require,module,exports){
9743
10079
  /* eslint consistent-return:0 */
9744
10080
  'use strict';
9745
10081
  var __extends = (this && this.__extends) || (function () {
@@ -9909,7 +10245,7 @@ var Signaling = /** @class */ (function (_super) {
9909
10245
  }(StateMachine));
9910
10246
  module.exports = Signaling;
9911
10247
 
9912
- },{"../statemachine":85,"./participant":58,"./room":62}],56:[function(require,module,exports){
10248
+ },{"../statemachine":89,"./participant":58,"./room":62}],56:[function(require,module,exports){
9913
10249
  'use strict';
9914
10250
  var __extends = (this && this.__extends) || (function () {
9915
10251
  var extendStatics = function (d, b) {
@@ -10345,7 +10681,7 @@ var ParticipantSignaling = /** @class */ (function (_super) {
10345
10681
  */
10346
10682
  module.exports = ParticipantSignaling;
10347
10683
 
10348
- },{"../statemachine":85,"../stats/networkqualitystats":100}],59:[function(require,module,exports){
10684
+ },{"../statemachine":89,"../stats/networkqualitystats":104}],59:[function(require,module,exports){
10349
10685
  'use strict';
10350
10686
  var __extends = (this && this.__extends) || (function () {
10351
10687
  var extendStatics = function (d, b) {
@@ -10418,7 +10754,7 @@ var RecordingSignaling = /** @class */ (function (_super) {
10418
10754
  */
10419
10755
  module.exports = RecordingSignaling;
10420
10756
 
10421
- },{"events":170}],60:[function(require,module,exports){
10757
+ },{"events":174}],60:[function(require,module,exports){
10422
10758
  'use strict';
10423
10759
  var __extends = (this && this.__extends) || (function () {
10424
10760
  var extendStatics = function (d, b) {
@@ -10490,36 +10826,41 @@ var RemoteTrackPublicationSignaling = /** @class */ (function (_super) {
10490
10826
  * @param {boolean} isEnabled
10491
10827
  * @param {Track.Priority} priority
10492
10828
  * @param {boolean} isSwitchedOff
10829
+ * @param {number} rspVersion
10493
10830
  */
10494
- function RemoteTrackPublicationSignaling(sid, name, kind, isEnabled, priority, isSwitchedOff) {
10831
+ function RemoteTrackPublicationSignaling(sid, name, kind, isEnabled, priority, isSwitchedOff, rspVersion) {
10495
10832
  var _this = _super.call(this, name, kind, isEnabled, priority) || this;
10496
10833
  Object.defineProperties(_this, {
10497
10834
  _isSwitchedOff: {
10498
10835
  value: isSwitchedOff,
10499
10836
  writable: true
10500
10837
  },
10838
+ _rspVersion: {
10839
+ value: rspVersion,
10840
+ writable: true
10841
+ }
10501
10842
  });
10502
10843
  _this.setSid(sid);
10503
10844
  return _this;
10504
10845
  }
10505
- Object.defineProperty(RemoteTrackPublicationSignaling.prototype, "isSubscribed", {
10846
+ Object.defineProperty(RemoteTrackPublicationSignaling.prototype, "isSwitchedOff", {
10506
10847
  /**
10507
- * Whether the {@link RemoteTrackPublicationSignaling} is subscribed to.
10848
+ * Whether the {@link RemoteTrackPublicationSignaling} is switched off.
10508
10849
  * @property {boolean}
10509
10850
  */
10510
10851
  get: function () {
10511
- return !!this.trackTransceiver;
10852
+ return this._isSwitchedOff;
10512
10853
  },
10513
10854
  enumerable: false,
10514
10855
  configurable: true
10515
10856
  });
10516
- Object.defineProperty(RemoteTrackPublicationSignaling.prototype, "isSwitchedOff", {
10857
+ Object.defineProperty(RemoteTrackPublicationSignaling.prototype, "rspVersion", {
10517
10858
  /**
10518
- * Whether the {@link RemoteTrackPublicationSignaling} is switched off.
10519
- * @property {boolean}
10859
+ * Return the RSP version of the {@link RemoteTrackPublicationSignaling} object.
10860
+ * @return {number}
10520
10861
  */
10521
10862
  get: function () {
10522
- return this._isSwitchedOff;
10863
+ return this._rspVersion;
10523
10864
  },
10524
10865
  enumerable: false,
10525
10866
  configurable: true
@@ -10844,7 +11185,7 @@ function maybeUpdateState(roomSignaling) {
10844
11185
  }
10845
11186
  module.exports = RoomSignaling;
10846
11187
 
10847
- },{"../statemachine":85,"../util":128,"../util/constants":122,"../util/log":132,"../util/timeout":142,"../util/twilio-video-errors":143,"./recording":59}],63:[function(require,module,exports){
11188
+ },{"../statemachine":89,"../util":132,"../util/constants":126,"../util/log":136,"../util/timeout":146,"../util/twilio-video-errors":147,"./recording":59}],63:[function(require,module,exports){
10848
11189
  'use strict';
10849
11190
  var __extends = (this && this.__extends) || (function () {
10850
11191
  var extendStatics = function (d, b) {
@@ -11027,11 +11368,12 @@ var TrackSignaling = /** @class */ (function (_super) {
11027
11368
  */
11028
11369
  module.exports = TrackSignaling;
11029
11370
 
11030
- },{"events":170}],64:[function(require,module,exports){
11371
+ },{"events":174}],64:[function(require,module,exports){
11031
11372
  'use strict';
11032
11373
  var CancelablePromise = require('../../util/cancelablepromise');
11033
11374
  var DefaultPeerConnectionManager = require('./peerconnectionmanager');
11034
11375
  var DefaultRoomV2 = require('./room');
11376
+ var DefaultRoomV3 = require('../v3/room');
11035
11377
  var DefaultTransport = require('./twilioconnectiontransport');
11036
11378
  var _a = require('../../util/twilio-video-errors'), SignalingConnectionDisconnectedError = _a.SignalingConnectionDisconnectedError, SignalingIncomingMessageInvalidError = _a.SignalingIncomingMessageInvalidError;
11037
11379
  var _b = require('../../util'), flatMap = _b.flatMap, createRoomConnectEventPayload = _b.createRoomConnectEventPayload;
@@ -11039,10 +11381,11 @@ function createCancelableRoomSignalingPromise(token, wsServer, localParticipant,
11039
11381
  options = Object.assign({
11040
11382
  PeerConnectionManager: DefaultPeerConnectionManager,
11041
11383
  RoomV2: DefaultRoomV2,
11384
+ RoomV3: DefaultRoomV3,
11042
11385
  Transport: DefaultTransport
11043
11386
  }, options);
11044
11387
  var adaptiveSimulcast = preferredCodecs.video[0] && preferredCodecs.video[0].adaptiveSimulcast === true;
11045
- var PeerConnectionManager = options.PeerConnectionManager, RoomV2 = options.RoomV2, Transport = options.Transport, iceServers = options.iceServers, log = options.log;
11388
+ var PeerConnectionManager = options.PeerConnectionManager, RoomV2 = options.RoomV2, RoomV3 = options.RoomV3, Transport = options.Transport, iceServers = options.iceServers, log = options.log;
11046
11389
  var peerConnectionManager = new PeerConnectionManager(encodingParameters, preferredCodecs, options);
11047
11390
  var trackSenders = flatMap(localParticipant.tracks, function (trackV2) { return [trackV2.trackTransceiver]; });
11048
11391
  peerConnectionManager.setTrackSenders(trackSenders);
@@ -11116,9 +11459,10 @@ function createCancelableRoomSignalingPromise(token, wsServer, localParticipant,
11116
11459
  reject(new SignalingIncomingMessageInvalidError());
11117
11460
  return;
11118
11461
  }
11119
- var signalingRegion = initialState.options.signaling_region;
11462
+ var signalingRegion = initialState.options.signaling_region, version = initialState.version;
11120
11463
  localParticipant.setSignalingRegion(signalingRegion);
11121
- resolve(new RoomV2(localParticipant, initialState, transport, peerConnectionManager, options));
11464
+ var RoomSignaling = version === 3 ? RoomV3 : RoomV2;
11465
+ resolve(new RoomSignaling(localParticipant, initialState, transport, peerConnectionManager, options));
11122
11466
  });
11123
11467
  transport.once('stateChanged', function (state, error) {
11124
11468
  if (state === 'disconnected') {
@@ -11146,7 +11490,7 @@ function createCancelableRoomSignalingPromise(token, wsServer, localParticipant,
11146
11490
  }
11147
11491
  module.exports = createCancelableRoomSignalingPromise;
11148
11492
 
11149
- },{"../../util":128,"../../util/cancelablepromise":121,"../../util/twilio-video-errors":143,"./peerconnectionmanager":75,"./room":81,"./twilioconnectiontransport":84}],65:[function(require,module,exports){
11493
+ },{"../../util":132,"../../util/cancelablepromise":125,"../../util/twilio-video-errors":147,"../v3/room":87,"./peerconnectionmanager":75,"./room":81,"./twilioconnectiontransport":84}],65:[function(require,module,exports){
11150
11494
  'use strict';
11151
11495
  var __extends = (this && this.__extends) || (function () {
11152
11496
  var extendStatics = function (d, b) {
@@ -11292,7 +11636,7 @@ var IceBox = /** @class */ (function () {
11292
11636
  }());
11293
11637
  module.exports = IceBox;
11294
11638
 
11295
- },{"../../util/filter":127}],67:[function(require,module,exports){
11639
+ },{"../../util/filter":131}],67:[function(require,module,exports){
11296
11640
  'use strict';
11297
11641
  var _a = require('../../util/constants'), ICE_ACTIVITY_CHECK_PERIOD_MS = _a.ICE_ACTIVITY_CHECK_PERIOD_MS, ICE_INACTIVITY_THRESHOLD_MS = _a.ICE_INACTIVITY_THRESHOLD_MS;
11298
11642
  /**
@@ -11425,7 +11769,7 @@ var IceConnectionMonitor = /** @class */ (function () {
11425
11769
  }());
11426
11770
  module.exports = IceConnectionMonitor;
11427
11771
 
11428
- },{"../../util/constants":122}],68:[function(require,module,exports){
11772
+ },{"../../util/constants":126}],68:[function(require,module,exports){
11429
11773
  'use strict';
11430
11774
  var __extends = (this && this.__extends) || (function () {
11431
11775
  var extendStatics = function (d, b) {
@@ -11514,7 +11858,7 @@ var Log = require('../../util/log');
11514
11858
  var _a = require('../../util'), buildLogLevels = _a.buildLogLevels, isDeepEqual = _a.isDeepEqual;
11515
11859
  /**
11516
11860
  * @extends ParticipantSignaling
11517
- * @property {BandwidthProfileOptions} bandwidthProfile
11861
+ * @property {BandwidthProfile} bandwidthProfile
11518
11862
  * @property {NetworkQualityConfigurationImpl} networkQualityConfiguration
11519
11863
  * @property {number} revision
11520
11864
  * @emits LocalParticipantV2#updated
@@ -11614,8 +11958,8 @@ var LocalParticipantV2 = /** @class */ (function (_super) {
11614
11958
  }
11615
11959
  };
11616
11960
  /**
11617
- * Update the {@link BandwidthProfileOptions}.
11618
- * @param {BandwidthProfileOptions} bandwidthProfile
11961
+ * Update the {@link BandwidthProfile}.
11962
+ * @param {BandwidthProfile} bandwidthProfile
11619
11963
  */
11620
11964
  LocalParticipantV2.prototype.setBandwidthProfile = function (bandwidthProfile) {
11621
11965
  if (!isDeepEqual(this._bandwidthProfile, bandwidthProfile)) {
@@ -11818,7 +12162,7 @@ var LocalParticipantV2 = /** @class */ (function (_super) {
11818
12162
  */
11819
12163
  module.exports = LocalParticipantV2;
11820
12164
 
11821
- },{"../../util":128,"../../util/constants":122,"../../util/log":132,"../localparticipant":56,"./localtrackpublication":70}],70:[function(require,module,exports){
12165
+ },{"../../util":132,"../../util/constants":126,"../../util/log":136,"../localparticipant":56,"./localtrackpublication":70}],70:[function(require,module,exports){
11822
12166
  'use strict';
11823
12167
  var __extends = (this && this.__extends) || (function () {
11824
12168
  var extendStatics = function (d, b) {
@@ -11936,7 +12280,7 @@ var LocalTrackPublicationV2 = /** @class */ (function (_super) {
11936
12280
  */
11937
12281
  module.exports = LocalTrackPublicationV2;
11938
12282
 
11939
- },{"../../util/twilio-video-errors":143,"../../util/twiliowarning":145,"../localtrackpublication":57}],71:[function(require,module,exports){
12283
+ },{"../../util/twilio-video-errors":147,"../../util/twiliowarning":149,"../localtrackpublication":57}],71:[function(require,module,exports){
11940
12284
  /* eslint callback-return:0 */
11941
12285
  'use strict';
11942
12286
  var __extends = (this && this.__extends) || (function () {
@@ -12033,7 +12377,7 @@ var MediaSignaling = /** @class */ (function (_super) {
12033
12377
  }(EventEmitter));
12034
12378
  module.exports = MediaSignaling;
12035
12379
 
12036
- },{"events":170}],72:[function(require,module,exports){
12380
+ },{"events":174}],72:[function(require,module,exports){
12037
12381
  /* eslint callback-return:0 */
12038
12382
  'use strict';
12039
12383
  var __extends = (this && this.__extends) || (function () {
@@ -12192,7 +12536,7 @@ function next(monitor) {
12192
12536
  */
12193
12537
  module.exports = NetworkQualityMonitor;
12194
12538
 
12195
- },{"../../stats/peerconnectionreportfactory":103,"events":170}],73:[function(require,module,exports){
12539
+ },{"../../stats/peerconnectionreportfactory":107,"events":174}],73:[function(require,module,exports){
12196
12540
  'use strict';
12197
12541
  var __extends = (this && this.__extends) || (function () {
12198
12542
  var extendStatics = function (d, b) {
@@ -12457,7 +12801,7 @@ function createNetworkQualityInputsMessage(networkQualityInputs, networkQualityR
12457
12801
  }
12458
12802
  module.exports = NetworkQualitySignaling;
12459
12803
 
12460
- },{"../../util/asyncvar":118,"../../util/timeout":142,"./mediasignaling":71}],74:[function(require,module,exports){
12804
+ },{"../../util/asyncvar":122,"../../util/timeout":146,"./mediasignaling":71}],74:[function(require,module,exports){
12461
12805
  'use strict';
12462
12806
  var __extends = (this && this.__extends) || (function () {
12463
12807
  var extendStatics = function (d, b) {
@@ -12496,7 +12840,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
12496
12840
  return to;
12497
12841
  };
12498
12842
  var DefaultBackoff = require('../../util/backoff');
12499
- var _a = require('../../webrtc'), DefaultRTCIceCandidate = _a.RTCIceCandidate, DefaultRTCPeerConnection = _a.RTCPeerConnection, DefaultRTCSessionDescription = _a.RTCSessionDescription, getStatistics = _a.getStats;
12843
+ var _a = require('../../webrtc'), DefaultRTCIceCandidate = _a.RTCIceCandidate, DefaultRTCPeerConnection = _a.RTCPeerConnection, DefaultRTCSessionDescription = _a.RTCSessionDescription, getStatistics = _a.getStats, getTrackStatistics = _a.getTrackStats;
12500
12844
  var util = require('../../webrtc/util');
12501
12845
  var _b = require('../../util/constants'), DEFAULT_ICE_GATHERING_TIMEOUT_MS = _b.DEFAULT_ICE_GATHERING_TIMEOUT_MS, DEFAULT_LOG_LEVEL = _b.DEFAULT_LOG_LEVEL, DEFAULT_SESSION_TIMEOUT_SEC = _b.DEFAULT_SESSION_TIMEOUT_SEC, iceRestartBackoffConfig = _b.iceRestartBackoffConfig;
12502
12846
  var _c = require('../../util/sdp'), addOrRewriteNewTrackIds = _c.addOrRewriteNewTrackIds, addOrRewriteTrackIds = _c.addOrRewriteTrackIds, createCodecMapForMediaSection = _c.createCodecMapForMediaSection, disableRtx = _c.disableRtx, enableDtxForOpus = _c.enableDtxForOpus, filterLocalCodecs = _c.filterLocalCodecs, getMediaSections = _c.getMediaSections, removeSSRCAttributes = _c.removeSSRCAttributes, revertSimulcast = _c.revertSimulcast, setCodecPreferences = _c.setCodecPreferences, setSimulcast = _c.setSimulcast;
@@ -13346,9 +13690,9 @@ var PeerConnectionV2 = /** @class */ (function (_super) {
13346
13690
  : null;
13347
13691
  this._trackMatcher = this._trackMatcher || new TrackMatcher();
13348
13692
  this._trackMatcher.update(sdp);
13349
- var mediaStreamTrack = event.track;
13693
+ var mediaStreamTrack = event.track, mid = event.transceiver.mid;
13350
13694
  var signaledTrackId = this._trackMatcher.match(event) || mediaStreamTrack.id;
13351
- var mediaTrackReceiver = new MediaTrackReceiver(signaledTrackId, mediaStreamTrack);
13695
+ var mediaTrackReceiver = new MediaTrackReceiver(signaledTrackId, mid, mediaStreamTrack);
13352
13696
  // NOTE(mmalavalli): "ended" is not fired on the remote MediaStreamTrack when
13353
13697
  // the remote peer removes a track. So, when this MediaStreamTrack is re-used
13354
13698
  // for a different track due to the remote peer calling RTCRtpSender.replaceTrack(),
@@ -14036,6 +14380,19 @@ var PeerConnectionV2 = /** @class */ (function (_super) {
14036
14380
  });
14037
14381
  });
14038
14382
  };
14383
+ /**
14384
+ * Get the statistics for a given remote MediaStreamTrack
14385
+ * @param {MediaStreamTrack} mediaStreamTrack
14386
+ * @returns {Promise<StandardizedTrackStatsReport>}
14387
+ */
14388
+ PeerConnectionV2.prototype.getRemoteTrackStats = function (mediaStreamTrack) {
14389
+ var _this = this;
14390
+ return getTrackStatistics(this._peerConnection, mediaStreamTrack, { isRemote: true })
14391
+ .then(function (_a) {
14392
+ var _b = __read(_a, 1), stats = _b[0];
14393
+ return rewriteTrackId(_this, stats);
14394
+ });
14395
+ };
14039
14396
  /**
14040
14397
  * Get the {@link PeerConnectionV2}'s media statistics.
14041
14398
  * @returns {Promise<StandardizedStatsResponse>}
@@ -14310,7 +14667,7 @@ function setMaxBitrate(params, maxBitrate) {
14310
14667
  }
14311
14668
  module.exports = PeerConnectionV2;
14312
14669
 
14313
- },{"../../data/receiver":5,"../../media/track/receiver":28,"../../statemachine":85,"../../util":128,"../../util/backoff":119,"../../util/constants":122,"../../util/log":132,"../../util/sdp":136,"../../util/sdp/issue8329":137,"../../util/sdp/trackmatcher":139,"../../util/timeout":142,"../../util/twilio-video-errors":143,"../../webrtc":154,"../../webrtc/util":167,"./icebox":66,"./iceconnectionmonitor.js":67}],75:[function(require,module,exports){
14670
+ },{"../../data/receiver":5,"../../media/track/receiver":28,"../../statemachine":89,"../../util":132,"../../util/backoff":123,"../../util/constants":126,"../../util/log":136,"../../util/sdp":140,"../../util/sdp/issue8329":141,"../../util/sdp/trackmatcher":143,"../../util/timeout":146,"../../util/twilio-video-errors":147,"../../webrtc":158,"../../webrtc/util":171,"./icebox":66,"./iceconnectionmonitor.js":67}],75:[function(require,module,exports){
14314
14671
  'use strict';
14315
14672
  var __extends = (this && this.__extends) || (function () {
14316
14673
  var extendStatics = function (d, b) {
@@ -14686,6 +15043,18 @@ var PeerConnectionManager = /** @class */ (function (_super) {
14686
15043
  return _this;
14687
15044
  });
14688
15045
  };
15046
+ /**
15047
+ * Get the statistics for a remote MediaStreamTrack.
15048
+ * @param {MediaStreamTrack} mediaStreamTrack
15049
+ * @returns {Promise<Map<PeerConnectionV2#id, StandardizedTrackStatsReport>>}
15050
+ */
15051
+ PeerConnectionManager.prototype.getRemoteTrackStats = function (mediaStreamTrack) {
15052
+ var peerConnections = Array.from(this._peerConnections.values());
15053
+ return Promise.all(peerConnections.map(function (peerConnection) { return peerConnection.getRemoteTrackStats(mediaStreamTrack).then(function (stats) { return [
15054
+ peerConnection.id,
15055
+ stats
15056
+ ]; }); })).then(function (reports) { return new Map(reports); });
15057
+ };
14689
15058
  /**
14690
15059
  * Get the {@link PeerConnectionManager}'s media statistics.
14691
15060
  * @returns {Promise.<Map<PeerConnectionV2#id, StandardizedStatsResponse>>}
@@ -14878,7 +15247,7 @@ function updateConnectionState(pcm) {
14878
15247
  }
14879
15248
  module.exports = PeerConnectionManager;
14880
15249
 
14881
- },{"../../media/track/sender":37,"../../queueingeventemitter":52,"../../util":128,"../../util/twilio-video-errors":143,"../../webaudio/audiocontext":149,"../../webrtc/util":167,"./peerconnection":74}],76:[function(require,module,exports){
15250
+ },{"../../media/track/sender":37,"../../queueingeventemitter":52,"../../util":132,"../../util/twilio-video-errors":147,"../../webaudio/audiocontext":153,"../../webrtc/util":171,"./peerconnection":74}],76:[function(require,module,exports){
14882
15251
  /* eslint callback-return:0 */
14883
15252
  'use strict';
14884
15253
  var __extends = (this && this.__extends) || (function () {
@@ -15061,19 +15430,26 @@ var RemoteParticipantV2 = /** @class */ (function (_super) {
15061
15430
  function RemoteParticipantV2(participantState, getInitialTrackSwitchOffState, setPriority, setRenderHint, clearTrackHint, options) {
15062
15431
  var _this = _super.call(this, participantState.sid, participantState.identity) || this;
15063
15432
  options = Object.assign({
15064
- RemoteTrackPublicationV2: RemoteTrackPublicationV2
15433
+ RemoteTrackPublicationSignaling: RemoteTrackPublicationV2,
15434
+ getPendingTrackReceiver: function () { return null; }
15065
15435
  }, options);
15066
15436
  Object.defineProperties(_this, {
15067
15437
  _revision: {
15068
15438
  writable: true,
15069
15439
  value: null
15070
15440
  },
15071
- _RemoteTrackPublicationV2: {
15072
- value: options.RemoteTrackPublicationV2
15441
+ _RemoteTrackPublicationSignaling: {
15442
+ value: options.RemoteTrackPublicationSignaling
15073
15443
  },
15074
15444
  _getInitialTrackSwitchOffState: {
15075
15445
  value: getInitialTrackSwitchOffState
15076
15446
  },
15447
+ _getPendingTrackReceiver: {
15448
+ value: options.getPendingTrackReceiver
15449
+ },
15450
+ _getTrackStats: {
15451
+ value: options.getTrackStats
15452
+ },
15077
15453
  updateSubscriberTrackPriority: {
15078
15454
  value: function (trackSid, priority) { return setPriority(trackSid, priority); }
15079
15455
  },
@@ -15090,13 +15466,14 @@ var RemoteParticipantV2 = /** @class */ (function (_super) {
15090
15466
  }
15091
15467
  }
15092
15468
  });
15093
- return _this.update(participantState);
15469
+ _this.update(participantState);
15470
+ return _this;
15094
15471
  }
15095
15472
  /**
15096
15473
  * @private
15097
15474
  */
15098
15475
  RemoteParticipantV2.prototype._getOrCreateTrack = function (trackState) {
15099
- var RemoteTrackPublicationV2 = this._RemoteTrackPublicationV2;
15476
+ var RemoteTrackPublicationV2 = this._RemoteTrackPublicationSignaling;
15100
15477
  var track = this.tracks.get(trackState.sid);
15101
15478
  if (!track) {
15102
15479
  var isSwitchedOff = this._getInitialTrackSwitchOffState(trackState.sid);
@@ -15174,8 +15551,19 @@ var RemoteTrackPublicationV2 = /** @class */ (function (_super) {
15174
15551
  *
15175
15552
  */
15176
15553
  function RemoteTrackPublicationV2(track, isSwitchedOff) {
15177
- return _super.call(this, track.sid, track.name, track.kind, track.enabled, track.priority, isSwitchedOff) || this;
15554
+ return _super.call(this, track.sid, track.name, track.kind, track.enabled, track.priority, isSwitchedOff, 2) || this;
15178
15555
  }
15556
+ Object.defineProperty(RemoteTrackPublicationV2.prototype, "isSubscribed", {
15557
+ /**
15558
+ * Whether the {@link RemoteTrackPublicationV2} is subscribed to.
15559
+ * @property {boolean}
15560
+ */
15561
+ get: function () {
15562
+ return !!this.trackTransceiver;
15563
+ },
15564
+ enumerable: false,
15565
+ configurable: true
15566
+ });
15179
15567
  /**
15180
15568
  * Compare the {@link RemoteTrackPublicationV2} to a
15181
15569
  * {@link RemoteTrackPublicationV2#Representation} of itself and perform any
@@ -15349,8 +15737,7 @@ var RenderHintsSignaling = /** @class */ (function (_super) {
15349
15737
  }(MediaSignaling));
15350
15738
  module.exports = RenderHintsSignaling;
15351
15739
 
15352
- },{"../../util":128,"../../util/timeout":142,"./mediasignaling":71}],81:[function(require,module,exports){
15353
- /* eslint-disable no-console */
15740
+ },{"../../util":132,"../../util/timeout":146,"./mediasignaling":71}],81:[function(require,module,exports){
15354
15741
  'use strict';
15355
15742
  var __extends = (this && this.__extends) || (function () {
15356
15743
  var extendStatics = function (d, b) {
@@ -15413,10 +15800,11 @@ var RoomV2 = /** @class */ (function (_super) {
15413
15800
  NetworkQualityMonitor: NetworkQualityMonitor,
15414
15801
  NetworkQualitySignaling: NetworkQualitySignaling,
15415
15802
  RecordingSignaling: RecordingV2,
15416
- RemoteParticipantV2: RemoteParticipantV2,
15803
+ RemoteParticipantSignaling: RemoteParticipantV2,
15417
15804
  TrackPrioritySignaling: TrackPrioritySignaling,
15418
15805
  TrackSwitchOffSignaling: TrackSwitchOffSignaling,
15419
15806
  bandwidthProfile: null,
15807
+ otherMediaSignalings: [],
15420
15808
  sessionTimeout: initialState.options.session_timeout * 1000,
15421
15809
  statsPublishIntervalMs: STATS_PUBLISH_INTERVAL_MS
15422
15810
  }, options);
@@ -15457,11 +15845,8 @@ var RoomV2 = /** @class */ (function (_super) {
15457
15845
  value: 0,
15458
15846
  writable: true
15459
15847
  },
15460
- _RemoteParticipantV2: {
15461
- value: options.RemoteParticipantV2
15462
- },
15463
- _subscribed: {
15464
- value: new Map()
15848
+ _RemoteParticipantSignaling: {
15849
+ value: options.RemoteParticipantSignaling
15465
15850
  },
15466
15851
  _subscribedRevision: {
15467
15852
  value: 0,
@@ -15470,6 +15855,9 @@ var RoomV2 = /** @class */ (function (_super) {
15470
15855
  _subscriptionFailures: {
15471
15856
  value: new Map()
15472
15857
  },
15858
+ _trackSidsToTrackIds: {
15859
+ value: new Map()
15860
+ },
15473
15861
  _dominantSpeakerSignaling: {
15474
15862
  value: new options.DominantSpeakerSignaling(getTrackReceiver, { log: log })
15475
15863
  },
@@ -15502,18 +15890,7 @@ var RoomV2 = /** @class */ (function (_super) {
15502
15890
  value: initialState.options.media_region || null
15503
15891
  }
15504
15892
  });
15505
- _this._initTrackSwitchOffSignaling();
15506
- _this._initDominantSpeakerSignaling();
15507
- _this._initNetworkQualityMonitorSignaling();
15508
- _this._initPublisherHintSignaling();
15509
- handleLocalParticipantEvents(_this, localParticipant);
15510
- handlePeerConnectionEvents(_this, peerConnectionManager);
15511
- handleTransportEvents(_this, transport);
15512
- periodicallyPublishStats(_this, transport, options.statsPublishIntervalMs);
15513
- _this._update(initialState);
15514
- // NOTE(mpatwardhan) after initial state we know if publisher_hints are enabled or not
15515
- // if they are not enabled. we need to undo simulcast that if it was enabled with initial offer.
15516
- _this._peerConnectionManager.setEffectiveAdaptiveSimulcast(_this._publisherHintsSignaling.isSetup);
15893
+ _this._init(localParticipant, peerConnectionManager, transport, options, initialState);
15517
15894
  return _this;
15518
15895
  }
15519
15896
  Object.defineProperty(RoomV2.prototype, "connectionState", {
@@ -15560,13 +15937,14 @@ var RoomV2 = /** @class */ (function (_super) {
15560
15937
  /**
15561
15938
  * @private
15562
15939
  */
15563
- RoomV2.prototype._getOrCreateTrackReceiverDeferred = function (id) {
15940
+ RoomV2.prototype._getOrCreateTrackReceiverDeferred = function (id, idOrMid) {
15941
+ if (idOrMid === void 0) { idOrMid = 'id'; }
15564
15942
  var deferred = this._trackReceiverDeferreds.get(id) || defer();
15565
15943
  var trackReceivers = this._peerConnectionManager.getTrackReceivers();
15566
15944
  // NOTE(mmalavalli): In Firefox, there can be instances where a MediaStreamTrack
15567
15945
  // for the given Track ID already exists, for example, when a Track is removed
15568
15946
  // and added back. If that is the case, then we should resolve 'deferred'.
15569
- var trackReceiver = trackReceivers.find(function (trackReceiver) { return trackReceiver.id === id && trackReceiver.readyState !== 'ended'; });
15947
+ var trackReceiver = trackReceivers.find(function (trackReceiver) { return trackReceiver[idOrMid] === id && trackReceiver.readyState !== 'ended'; });
15570
15948
  if (trackReceiver) {
15571
15949
  deferred.resolve(trackReceiver);
15572
15950
  }
@@ -15586,6 +15964,14 @@ var RoomV2 = /** @class */ (function (_super) {
15586
15964
  deferred.resolve(trackReceiver);
15587
15965
  return this;
15588
15966
  };
15967
+ /**
15968
+ * @private
15969
+ */
15970
+ RoomV2.prototype._createRemoteParticipant = function (participantState) {
15971
+ var _this = this;
15972
+ var RemoteParticipantV2 = this._RemoteParticipantSignaling;
15973
+ return new RemoteParticipantV2(participantState, function (trackSid) { return _this._getInitialTrackSwitchOffState(trackSid); }, function (trackSid, priority) { return _this._trackPrioritySignaling.sendTrackPriorityUpdate(trackSid, 'subscribe', priority); }, function (trackSid, hint) { return _this._renderHintsSignaling.setTrackHint(trackSid, hint); }, function (trackSid) { return _this._renderHintsSignaling.clearTrackHint(trackSid); });
15974
+ };
15589
15975
  /**
15590
15976
  * @private
15591
15977
  */
@@ -15604,9 +15990,10 @@ var RoomV2 = /** @class */ (function (_super) {
15604
15990
  /**
15605
15991
  * @private
15606
15992
  */
15607
- RoomV2.prototype._getTrackReceiver = function (id) {
15993
+ RoomV2.prototype._getTrackReceiver = function (id, idOrMid) {
15608
15994
  var _this = this;
15609
- return this._getOrCreateTrackReceiverDeferred(id).promise.then(function (trackReceiver) {
15995
+ if (idOrMid === void 0) { idOrMid = 'id'; }
15996
+ return this._getOrCreateTrackReceiverDeferred(id, idOrMid).promise.then(function (trackReceiver) {
15610
15997
  _this._deleteTrackReceiverDeferred(id);
15611
15998
  return trackReceiver;
15612
15999
  });
@@ -15633,12 +16020,10 @@ var RoomV2 = /** @class */ (function (_super) {
15633
16020
  * @private
15634
16021
  */
15635
16022
  RoomV2.prototype._getOrCreateRemoteParticipant = function (participantState) {
15636
- var _this = this;
15637
- var RemoteParticipantV2 = this._RemoteParticipantV2;
15638
16023
  var participant = this.participants.get(participantState.sid);
15639
16024
  var self = this;
15640
16025
  if (!participant) {
15641
- participant = new RemoteParticipantV2(participantState, function (trackSid) { return _this._getInitialTrackSwitchOffState(trackSid); }, function (trackSid, priority) { return _this._trackPrioritySignaling.sendTrackPriorityUpdate(trackSid, 'subscribe', priority); }, function (trackSid, hint) { return _this._renderHintsSignaling.setTrackHint(trackSid, hint); }, function (trackSid) { return _this._renderHintsSignaling.clearTrackHint(trackSid); });
16026
+ participant = this._createRemoteParticipant(participantState);
15642
16027
  participant.on('stateChanged', function stateChanged(state) {
15643
16028
  if (state === 'disconnected') {
15644
16029
  participant.removeListener('stateChanged', stateChanged);
@@ -15658,6 +16043,23 @@ var RoomV2 = /** @class */ (function (_super) {
15658
16043
  participant: this.localParticipant.getState()
15659
16044
  };
15660
16045
  };
16046
+ /**
16047
+ * @private
16048
+ */
16049
+ RoomV2.prototype._init = function (localParticipant, peerConnectionManager, transport, options, initialState) {
16050
+ this._initTrackSwitchOffSignaling();
16051
+ this._initDominantSpeakerSignaling();
16052
+ this._initNetworkQualityMonitorSignaling();
16053
+ this._initPublisherHintSignaling();
16054
+ handleLocalParticipantEvents(this, localParticipant);
16055
+ handlePeerConnectionEvents(this, peerConnectionManager);
16056
+ handleTransportEvents(this, transport);
16057
+ periodicallyPublishStats(this, transport, options.statsPublishIntervalMs);
16058
+ this._update(initialState);
16059
+ // NOTE(mpatwardhan) after initial state we can find out if we are connected to a P2P or group room by checking if there is a mediaRegion.
16060
+ // if we are not connected to group room, turn off adaptive simulcast.
16061
+ this._peerConnectionManager.setEffectiveAdaptiveSimulcast(!!this.mediaRegion);
16062
+ };
15661
16063
  /**
15662
16064
  * @private
15663
16065
  */
@@ -15690,31 +16092,86 @@ var RoomV2 = /** @class */ (function (_super) {
15690
16092
  * @private
15691
16093
  */
15692
16094
  RoomV2.prototype._update = function (roomState) {
15693
- var _this = this;
15694
- if (roomState.subscribed && roomState.subscribed.revision > this._subscribedRevision) {
15695
- this._subscribedRevision = roomState.subscribed.revision;
15696
- roomState.subscribed.tracks.forEach(function (trackState) {
15697
- if (trackState.id) {
15698
- _this._subscriptionFailures.delete(trackState.sid);
15699
- _this._subscribed.set(trackState.sid, trackState.id);
15700
- }
15701
- else if (trackState.error && !_this._subscriptionFailures.has(trackState.sid)) {
15702
- _this._subscriptionFailures.set(trackState.sid, trackState.error);
15703
- }
15704
- });
15705
- var subscribedTrackSids_1 = new Set(roomState.subscribed.tracks
15706
- .filter(function (trackState) { return !!trackState.id; })
15707
- .map(function (trackState) { return trackState.sid; }));
15708
- this._subscribed.forEach(function (trackId, trackSid) {
15709
- if (!subscribedTrackSids_1.has(trackSid)) {
15710
- _this._subscribed.delete(trackSid);
15711
- }
15712
- });
16095
+ var type = roomState.type;
16096
+ this._updateSubscribed(roomState);
16097
+ this._updateParticipants(roomState, type);
16098
+ this._handleSubscriptions();
16099
+ this._updatePeerConnections(roomState, type);
16100
+ this._updateRecording(roomState);
16101
+ this._updatePublished(roomState);
16102
+ this._connectLocalParticipant(roomState);
16103
+ this._setupMediaSignalings(roomState);
16104
+ this._updateMediaStates(roomState);
16105
+ return this;
16106
+ };
16107
+ /**
16108
+ * @private
16109
+ */
16110
+ RoomV2.prototype._connectLocalParticipant = function (_a) {
16111
+ var participant = _a.participant;
16112
+ if (!participant) {
16113
+ return;
15713
16114
  }
16115
+ var sid = participant.sid, identity = participant.identity;
16116
+ this.localParticipant.connect(sid, identity);
16117
+ };
16118
+ /**
16119
+ * @private
16120
+ */
16121
+ RoomV2.prototype._handleSubscriptions = function () {
16122
+ var _this = this;
16123
+ var trackSidsToTrackSignalings = this._getTrackSidsToTrackSignalings();
16124
+ this._subscriptionFailures.forEach(function (error, trackSid) {
16125
+ var trackSignaling = trackSidsToTrackSignalings.get(trackSid);
16126
+ if (trackSignaling) {
16127
+ _this._subscriptionFailures.delete(trackSid);
16128
+ trackSignaling.subscribeFailed(createTwilioError(error.code, error.message));
16129
+ }
16130
+ });
16131
+ trackSidsToTrackSignalings.forEach(function (trackSignaling) {
16132
+ var trackId = _this._trackSidsToTrackIds.get(trackSignaling.sid);
16133
+ if (!trackId || (trackSignaling.isSubscribed && trackSignaling.trackTransceiver.id !== trackId)) {
16134
+ trackSignaling.setTrackTransceiver(null);
16135
+ }
16136
+ if (trackId) {
16137
+ _this._getTrackReceiver(trackId).then(function (trackReceiver) { return trackSignaling.setTrackTransceiver(trackReceiver); });
16138
+ }
16139
+ });
16140
+ };
16141
+ /**
16142
+ * @private
16143
+ */
16144
+ RoomV2.prototype._setupMediaSignalings = function (_a) {
16145
+ var mediaSignalings = _a.media_signaling;
16146
+ var otherMediaSignalings = this._trackSubscriptionsSignaling
16147
+ ? [this._trackSubscriptionsSignaling]
16148
+ : [];
16149
+ [
16150
+ this._dominantSpeakerSignaling,
16151
+ this._networkQualitySignaling,
16152
+ this._trackPrioritySignaling,
16153
+ this._trackSwitchOffSignaling,
16154
+ this._renderHintsSignaling,
16155
+ this._publisherHintsSignaling,
16156
+ ].concat(otherMediaSignalings).forEach(function (mediaSignaling) {
16157
+ var channel = mediaSignaling.channel;
16158
+ if (!mediaSignaling.isSetup
16159
+ && mediaSignalings
16160
+ && mediaSignalings[channel]
16161
+ && mediaSignalings[channel].transport
16162
+ && mediaSignalings[channel].transport.type === 'data-channel') {
16163
+ mediaSignaling.setup(mediaSignalings[channel].transport.label);
16164
+ }
16165
+ });
16166
+ };
16167
+ /**
16168
+ * @private
16169
+ */
16170
+ RoomV2.prototype._updateParticipants = function (_a, roomStateType) {
16171
+ var _this = this;
16172
+ var _b = _a.participants, participants = _b === void 0 ? [] : _b;
15714
16173
  var participantsToKeep = new Set();
15715
- // eslint-disable-next-line no-warning-comments
15716
- // TODO(mroberts): Remove me once the Server is fixed.
15717
- (roomState.participants || []).forEach(function (participantState) {
16174
+ participants.forEach(function (participantState) {
15718
16175
  if (participantState.sid === _this.localParticipant.sid) {
15719
16176
  return;
15720
16177
  }
@@ -15733,58 +16190,86 @@ var RoomV2 = /** @class */ (function (_super) {
15733
16190
  participant.update(participantState);
15734
16191
  participantsToKeep.add(participant);
15735
16192
  });
15736
- if (roomState.type === 'synced') {
16193
+ if (roomStateType === 'synced') {
15737
16194
  this.participants.forEach(function (participant) {
15738
16195
  if (!participantsToKeep.has(participant)) {
15739
16196
  participant.disconnect();
15740
16197
  }
15741
16198
  });
15742
16199
  }
15743
- handleSubscriptions(this);
15744
- // eslint-disable-next-line no-warning-comments
15745
- // TODO(mroberts): Remove me once the Server is fixed.
15746
- /* eslint camelcase:0 */
15747
- if (roomState.peer_connections) {
15748
- this._peerConnectionManager.update(roomState.peer_connections, roomState.type === 'synced');
15749
- }
15750
- if (roomState.recording) {
15751
- this.recording.update(roomState.recording);
16200
+ };
16201
+ /**
16202
+ * @private
16203
+ */
16204
+ RoomV2.prototype._updatePeerConnections = function (_a, roomStateType) {
16205
+ var peerConnections = _a.peer_connections;
16206
+ if (peerConnections) {
16207
+ this._peerConnectionManager.update(peerConnections, roomStateType === 'synced');
15752
16208
  }
15753
- if (roomState.published && roomState.published.revision > this._publishedRevision) {
15754
- this._publishedRevision = roomState.published.revision;
15755
- roomState.published.tracks.forEach(function (track) {
15756
- if (track.sid) {
15757
- _this._published.set(track.id, track.sid);
15758
- }
15759
- });
15760
- this.localParticipant.update(roomState.published);
16209
+ };
16210
+ /**
16211
+ * @private
16212
+ */
16213
+ RoomV2.prototype._updateRecording = function (_a) {
16214
+ var recording = _a.recording;
16215
+ if (recording) {
16216
+ this.recording.update(recording);
15761
16217
  }
15762
- if (roomState.participant) {
15763
- this.localParticipant.connect(roomState.participant.sid, roomState.participant.identity);
16218
+ };
16219
+ /**
16220
+ * @private
16221
+ */
16222
+ RoomV2.prototype._updatePublished = function (_a) {
16223
+ var _this = this;
16224
+ var published = _a.published;
16225
+ if (!published || published.revision <= this._publishedRevision) {
16226
+ return;
15764
16227
  }
15765
- [
15766
- this._dominantSpeakerSignaling,
15767
- this._networkQualitySignaling,
15768
- this._trackPrioritySignaling,
15769
- this._trackSwitchOffSignaling,
15770
- this._renderHintsSignaling,
15771
- this._publisherHintsSignaling
15772
- ].forEach(function (mediaSignaling) {
15773
- var channel = mediaSignaling.channel;
15774
- if (!mediaSignaling.isSetup
15775
- && roomState.media_signaling
15776
- && roomState.media_signaling[channel]
15777
- && roomState.media_signaling[channel].transport
15778
- && roomState.media_signaling[channel].transport.type === 'data-channel') {
15779
- mediaSignaling.setup(roomState.media_signaling[channel].transport.label);
16228
+ this._publishedRevision = published.revision;
16229
+ published.tracks.forEach(function (track) {
16230
+ if (track.sid) {
16231
+ _this._published.set(track.id, track.sid);
15780
16232
  }
15781
16233
  });
16234
+ this.localParticipant.update(published);
16235
+ };
16236
+ /**
16237
+ * @private
16238
+ */
16239
+ RoomV2.prototype._updateMediaStates = function (roomState) {
15782
16240
  if (roomState.type === 'warning' && roomState.states &&
15783
16241
  roomState.states.revision > this._mediaStatesWarningsRevision) {
15784
16242
  this._mediaStatesWarningsRevision = roomState.states.revision;
15785
16243
  this.localParticipant.updateMediaStates(roomState.states);
15786
16244
  }
15787
- return this;
16245
+ };
16246
+ /**
16247
+ * @private
16248
+ */
16249
+ RoomV2.prototype._updateSubscribed = function (_a) {
16250
+ var _this = this;
16251
+ var subscribed = _a.subscribed;
16252
+ if (!subscribed || subscribed.revision <= this._subscribedRevision) {
16253
+ return;
16254
+ }
16255
+ this._subscribedRevision = subscribed.revision;
16256
+ subscribed.tracks.forEach(function (trackState) {
16257
+ if (trackState.id) {
16258
+ _this._subscriptionFailures.delete(trackState.sid);
16259
+ _this._trackSidsToTrackIds.set(trackState.sid, trackState.id);
16260
+ }
16261
+ else if (trackState.error && !_this._subscriptionFailures.has(trackState.sid)) {
16262
+ _this._subscriptionFailures.set(trackState.sid, trackState.error);
16263
+ }
16264
+ });
16265
+ var subscribedTrackSids = new Set(subscribed.tracks
16266
+ .filter(function (trackState) { return !!trackState.id; })
16267
+ .map(function (trackState) { return trackState.sid; }));
16268
+ this._trackSidsToTrackIds.forEach(function (trackId, trackSid) {
16269
+ if (!subscribedTrackSids.has(trackSid)) {
16270
+ _this._trackSidsToTrackIds.delete(trackSid);
16271
+ }
16272
+ });
15788
16273
  };
15789
16274
  RoomV2.prototype._initPublisherHintSignaling = function () {
15790
16275
  var _this = this;
@@ -15923,7 +16408,7 @@ function filterAndAddLocalTrackSids(roomV2, localTrackStats) {
15923
16408
  * @returns {Array<RemoteTrackStats>}
15924
16409
  */
15925
16410
  function filterAndAddRemoteTrackSids(roomV2, remoteTrackStats) {
15926
- var idToSid = new Map(Array.from(roomV2._subscribed.entries()).map(function (_a) {
16411
+ var idToSid = new Map(Array.from(roomV2._trackSidsToTrackIds.entries()).map(function (_a) {
15927
16412
  var _b = __read(_a, 2), sid = _b[0], id = _b[1];
15928
16413
  return [id, sid];
15929
16414
  }));
@@ -16078,25 +16563,6 @@ function periodicallyPublishStats(roomV2, transport, intervalMs) {
16078
16563
  }
16079
16564
  });
16080
16565
  }
16081
- function handleSubscriptions(room) {
16082
- var trackSidsToTrackSignalings = room._getTrackSidsToTrackSignalings();
16083
- room._subscriptionFailures.forEach(function (error, trackSid) {
16084
- var trackSignaling = trackSidsToTrackSignalings.get(trackSid);
16085
- if (trackSignaling) {
16086
- room._subscriptionFailures.delete(trackSid);
16087
- trackSignaling.subscribeFailed(createTwilioError(error.code, error.message));
16088
- }
16089
- });
16090
- trackSidsToTrackSignalings.forEach(function (trackSignaling) {
16091
- var trackId = room._subscribed.get(trackSignaling.sid);
16092
- if (!trackId || (trackSignaling.isSubscribed && trackSignaling.trackTransceiver.id !== trackId)) {
16093
- trackSignaling.setTrackTransceiver(null);
16094
- }
16095
- if (trackId) {
16096
- room._getTrackReceiver(trackId).then(function (trackReceiver) { return trackSignaling.setTrackTransceiver(trackReceiver); });
16097
- }
16098
- });
16099
- }
16100
16566
  /**
16101
16567
  * NOTE(mmalavalli): Since A/V sync metrics are not part of the public StatsReport class, we add them
16102
16568
  * only for reporting purposes.
@@ -16200,7 +16666,7 @@ function replaceNullsWithDefaults(activeIceCandidatePair, peerConnectionId) {
16200
16666
  }
16201
16667
  module.exports = RoomV2;
16202
16668
 
16203
- },{"../../stats/statsreport":113,"../../util":128,"../../util/movingaveragedelta":133,"../../util/twilio-video-errors":143,"../room":62,"./dominantspeakersignaling":65,"./networkqualitymonitor":72,"./networkqualitysignaling":73,"./publisherhintsignaling.js":76,"./recording":77,"./remoteparticipant":78,"./renderhintssignaling":80,"./trackprioritysignaling":82,"./trackswitchoffsignaling":83}],82:[function(require,module,exports){
16669
+ },{"../../stats/statsreport":117,"../../util":132,"../../util/movingaveragedelta":137,"../../util/twilio-video-errors":147,"../room":62,"./dominantspeakersignaling":65,"./networkqualitymonitor":72,"./networkqualitysignaling":73,"./publisherhintsignaling.js":76,"./recording":77,"./remoteparticipant":78,"./renderhintssignaling":80,"./trackprioritysignaling":82,"./trackswitchoffsignaling":83}],82:[function(require,module,exports){
16204
16670
  'use strict';
16205
16671
  var __extends = (this && this.__extends) || (function () {
16206
16672
  var extendStatics = function (d, b) {
@@ -16349,8 +16815,10 @@ var Timeout = require('../../util/timeout');
16349
16815
  var _a = require('../../util/constants'), SDK_NAME = _a.SDK_NAME, SDK_VERSION = _a.SDK_VERSION, SDP_FORMAT = _a.SDP_FORMAT;
16350
16816
  var _b = require('../../util'), createBandwidthProfilePayload = _b.createBandwidthProfilePayload, createMediaSignalingPayload = _b.createMediaSignalingPayload, createMediaWarningsPayload = _b.createMediaWarningsPayload, createSubscribePayload = _b.createSubscribePayload, getUserAgent = _b.getUserAgent, isNonArrayObject = _b.isNonArrayObject;
16351
16817
  var _c = require('../../util/twilio-video-errors'), createTwilioError = _c.createTwilioError, RoomCompletedError = _c.RoomCompletedError, SignalingConnectionError = _c.SignalingConnectionError, SignalingServerBusyError = _c.SignalingServerBusyError;
16818
+ // eslint-disable-next-line no-warning-comments
16819
+ // TODO(mmalavalli): Remove ICE version and use RSP_VERSION before Large Rooms GA.
16352
16820
  var ICE_VERSION = 1;
16353
- var RSP_VERSION = 2;
16821
+ var RSP_VERSION = 3;
16354
16822
  /*
16355
16823
  TwilioConnectionTransport States
16356
16824
  ----------------
@@ -16911,7 +17379,640 @@ function setupTransport(transport) {
16911
17379
  }
16912
17380
  module.exports = TwilioConnectionTransport;
16913
17381
 
16914
- },{"../../statemachine":85,"../../twilioconnection":117,"../../util":128,"../../util/backoff":119,"../../util/constants":122,"../../util/timeout":142,"../../util/twilio-video-errors":143}],85:[function(require,module,exports){
17382
+ },{"../../statemachine":89,"../../twilioconnection":121,"../../util":132,"../../util/backoff":123,"../../util/constants":126,"../../util/timeout":146,"../../util/twilio-video-errors":147}],85:[function(require,module,exports){
17383
+ 'use strict';
17384
+ var __extends = (this && this.__extends) || (function () {
17385
+ var extendStatics = function (d, b) {
17386
+ extendStatics = Object.setPrototypeOf ||
17387
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
17388
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
17389
+ return extendStatics(d, b);
17390
+ };
17391
+ return function (d, b) {
17392
+ if (typeof b !== "function" && b !== null)
17393
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
17394
+ extendStatics(d, b);
17395
+ function __() { this.constructor = d; }
17396
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17397
+ };
17398
+ })();
17399
+ var RemoteParticipantV2 = require('../v2/remoteparticipant');
17400
+ var RemoteTrackPublicationV3 = require('./remotetrackpublication');
17401
+ /**
17402
+ * @extends RemoteParticipantV2
17403
+ */
17404
+ var RemoteParticipantV3 = /** @class */ (function (_super) {
17405
+ __extends(RemoteParticipantV3, _super);
17406
+ /**
17407
+ * Construct a {@link RemoteParticipantV2}.
17408
+ * @param {object} participantState
17409
+ * @param {function(Track.SID): Promise<MediaTrackReceiver>} getPendingTrackReceiver
17410
+ * @param {function(Track.SID): boolean} getInitialTrackSwitchOffState
17411
+ * @param {function(Track.SID, Track.Priority): boolean} setPriority
17412
+ * @param {function(Track.SID, ClientRenderHint): Promise<void>} setRenderHint
17413
+ * @param {function(Track.SID): void} clearTrackHint
17414
+ * @param {function(MediaStreamTrack): Promise<Map<PeerConnectionV2#id, StandardizedTrackStatsReport>>} getTrackStats
17415
+ * @param {object} [options]
17416
+ */
17417
+ function RemoteParticipantV3(participantState, getPendingTrackReceiver, getInitialTrackSwitchOffState, setPriority, setRenderHint, clearTrackHint, getTrackStats, options) {
17418
+ var _this = this;
17419
+ options = Object.assign({
17420
+ RemoteTrackPublicationSignaling: RemoteTrackPublicationV3,
17421
+ getPendingTrackReceiver: getPendingTrackReceiver,
17422
+ getTrackStats: getTrackStats
17423
+ }, options);
17424
+ _this = _super.call(this, participantState, getInitialTrackSwitchOffState, setPriority, setRenderHint, clearTrackHint, options) || this;
17425
+ return _this;
17426
+ }
17427
+ /**
17428
+ * @private
17429
+ */
17430
+ RemoteParticipantV3.prototype._getOrCreateTrack = function (trackState) {
17431
+ var _a = this, RemoteTrackPublicationV3 = _a._RemoteTrackPublicationSignaling, getPendingTrackReceiver = _a._getPendingTrackReceiver, getTrackStats = _a._getTrackStats;
17432
+ var track = this.tracks.get(trackState.sid);
17433
+ if (!track) {
17434
+ var _b = this.kind === 'data'
17435
+ ? { state: 'ON', switchOffReason: null }
17436
+ : this._getInitialTrackSwitchOffState(trackState.sid), state = _b.state, _c = _b.switchOffReason, switchOffReason = _c === void 0 ? null : _c;
17437
+ track = new RemoteTrackPublicationV3(trackState, state === 'OFF', switchOffReason, getTrackStats);
17438
+ this.addTrack(track);
17439
+ getPendingTrackReceiver(track.sid).then(function (trackReceiver) {
17440
+ // NOTE(mmalavalli): DataTracks are subscribed to only if corresponding DataTrackReceivers
17441
+ // are available, whereas MediaTracks can be subscribed to irrespective of whether corresponding
17442
+ // MediaTrackReceivers are available. MediaTracks without MediaTrackReceivers are considered
17443
+ // switched off.
17444
+ track.setTrackTransceiver(trackReceiver, track.kind !== 'data' || !!trackReceiver);
17445
+ });
17446
+ }
17447
+ return track;
17448
+ };
17449
+ return RemoteParticipantV3;
17450
+ }(RemoteParticipantV2));
17451
+ module.exports = RemoteParticipantV3;
17452
+
17453
+ },{"../v2/remoteparticipant":78,"./remotetrackpublication":86}],86:[function(require,module,exports){
17454
+ 'use strict';
17455
+ var __extends = (this && this.__extends) || (function () {
17456
+ var extendStatics = function (d, b) {
17457
+ extendStatics = Object.setPrototypeOf ||
17458
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
17459
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
17460
+ return extendStatics(d, b);
17461
+ };
17462
+ return function (d, b) {
17463
+ if (typeof b !== "function" && b !== null)
17464
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
17465
+ extendStatics(d, b);
17466
+ function __() { this.constructor = d; }
17467
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17468
+ };
17469
+ })();
17470
+ var RemoteTrackPublicationSignaling = require('../remotetrackpublication');
17471
+ /**
17472
+ * @extends RemoteTrackPublicationSignaling
17473
+ */
17474
+ var RemoteTrackPublicationV3 = /** @class */ (function (_super) {
17475
+ __extends(RemoteTrackPublicationV3, _super);
17476
+ /**
17477
+ * Construct a {@link RemoteTrackPublicationV3}.
17478
+ * @param {RemoteTrackPublicationV3#Representation} track
17479
+ * @param {boolean} isSwitchedOff
17480
+ * @param {?string} switchOffReason
17481
+ * @param {function(MediaStreamTrack): Promise<Map<PeerConnectionV2#id, StandardizedTrackStatsReport>>} getTrackStats
17482
+ */
17483
+ function RemoteTrackPublicationV3(track, isSwitchedOff, switchOffReason, getTrackStats) {
17484
+ var _this = this;
17485
+ switchOffReason = isSwitchedOff ? switchOffReason : null;
17486
+ var enabled = isEnabled(isSwitchedOff, switchOffReason);
17487
+ var kind = track.kind, name = track.name, priority = track.priority, sid = track.sid;
17488
+ _this = _super.call(this, sid, name, kind, enabled, priority, isSwitchedOff, 3) || this;
17489
+ Object.defineProperties(_this, {
17490
+ _getTrackStats: {
17491
+ value: getTrackStats
17492
+ },
17493
+ _isSubscribed: {
17494
+ value: false,
17495
+ writable: true
17496
+ },
17497
+ _pendingGetTrackStatsPromise: {
17498
+ value: Promise.resolve(),
17499
+ writable: true
17500
+ },
17501
+ _switchOffReason: {
17502
+ value: switchOffReason,
17503
+ writable: true
17504
+ },
17505
+ _switchOffStateChangeStats: {
17506
+ value: initialTrackStats(sid, kind),
17507
+ writable: true
17508
+ },
17509
+ _switchOnMediaStreamTrackStats: {
17510
+ value: initialTrackStats(sid, kind),
17511
+ writable: true
17512
+ }
17513
+ });
17514
+ return _this;
17515
+ }
17516
+ Object.defineProperty(RemoteTrackPublicationV3.prototype, "isSubscribed", {
17517
+ /**
17518
+ * Whether the {@link RemoteTrackPublicationV3} is subscribed to.
17519
+ * @property {boolean}
17520
+ */
17521
+ get: function () {
17522
+ return this._isSubscribed;
17523
+ },
17524
+ enumerable: false,
17525
+ configurable: true
17526
+ });
17527
+ Object.defineProperty(RemoteTrackPublicationV3.prototype, "switchOffReason", {
17528
+ /**
17529
+ * The reason for the {@link RemoteTrackPublicationV3} being switched off.
17530
+ * @returns {?string}
17531
+ */
17532
+ get: function () {
17533
+ return this._switchOffReason;
17534
+ },
17535
+ enumerable: false,
17536
+ configurable: true
17537
+ });
17538
+ /**
17539
+ * Adjust Track statistics based on new stats. Returns the most recent switched
17540
+ * off state change Track statistics if no argument is provided.
17541
+ * @param {StandardizedTrackStatsReport} [newMediaStreamTrackStats]
17542
+ * @returns {StandardizedTrackStatsReport}
17543
+ */
17544
+ RemoteTrackPublicationV3.prototype.adjustTrackStats = function (newMediaStreamTrackStats) {
17545
+ var _this = this;
17546
+ if (newMediaStreamTrackStats === void 0) { newMediaStreamTrackStats = {}; }
17547
+ var cumulativeStatsProps = [
17548
+ 'bytesReceived',
17549
+ 'framesDecoded',
17550
+ 'packetsLost',
17551
+ 'packetsReceived',
17552
+ 'totalDecodeTime'
17553
+ ];
17554
+ var snapshotStatsProps = [
17555
+ 'audioOutputLevel',
17556
+ 'codecName',
17557
+ 'estimatedPlayoutTimestamp',
17558
+ 'frameHeightReceived',
17559
+ 'frameRateReceived',
17560
+ 'frameWidthReceived',
17561
+ 'jitter',
17562
+ 'jitterBufferDelay',
17563
+ 'jitterBufferEmittedCount',
17564
+ 'roundTripTime',
17565
+ 'ssrc',
17566
+ 'timestamp',
17567
+ 'trackId'
17568
+ ];
17569
+ var trackStats = Object.assign({}, this._switchOffStateChangeStats);
17570
+ cumulativeStatsProps.forEach(function (prop) {
17571
+ if (prop in newMediaStreamTrackStats) {
17572
+ trackStats[prop] = _this._switchOffStateChangeStats[prop] + newMediaStreamTrackStats[prop] - _this._switchOnMediaStreamTrackStats[prop];
17573
+ }
17574
+ });
17575
+ snapshotStatsProps.forEach(function (prop) {
17576
+ if (prop in newMediaStreamTrackStats) {
17577
+ trackStats[prop] = newMediaStreamTrackStats[prop];
17578
+ }
17579
+ });
17580
+ if (!this.isSubscribed || this.isSwitchedOff) {
17581
+ trackStats.ssrc = '';
17582
+ trackStats.timestamp = Date.now();
17583
+ trackStats.trackId = '';
17584
+ }
17585
+ return trackStats;
17586
+ };
17587
+ /**
17588
+ * Updates track switch on/off state.
17589
+ * @param {boolean} isSwitchedOff
17590
+ * @param {?string} switchOffReason
17591
+ * @returns {this}
17592
+ */
17593
+ RemoteTrackPublicationV3.prototype.setSwitchedOff = function (isSwitchedOff, switchOffReason) {
17594
+ switchOffReason = isSwitchedOff ? switchOffReason : null;
17595
+ var shouldEmitUpdated = isSwitchedOff !== this.isSwitchedOff
17596
+ || switchOffReason !== this.switchOffReason;
17597
+ this._isSwitchedOff = isSwitchedOff;
17598
+ this._switchOffReason = switchOffReason;
17599
+ if (shouldEmitUpdated) {
17600
+ this.emit('updated');
17601
+ }
17602
+ return this.enable(isEnabled(isSwitchedOff, switchOffReason));
17603
+ };
17604
+ /**
17605
+ * Set the {@link MediaTrackReceiver} on the {@link RemoteTrackPublicationV3}.
17606
+ * @override
17607
+ * @param {MediaTrackReceiver} trackReceiver
17608
+ * @param {boolean} isSubscribed
17609
+ * @returns {this}
17610
+ */
17611
+ RemoteTrackPublicationV3.prototype.setTrackTransceiver = function (trackReceiver, isSubscribed) {
17612
+ var _this = this;
17613
+ isSubscribed = !!trackReceiver || isSubscribed;
17614
+ var shouldEmitUpdated = trackReceiver !== this.trackTransceiver || isSubscribed !== this.isSubscribed;
17615
+ if (this.kind !== 'data' && trackReceiver !== this.trackTransceiver) {
17616
+ var track_1 = (trackReceiver || this.trackTransceiver).track;
17617
+ this._pendingGetTrackStatsPromise = this._pendingGetTrackStatsPromise.then(function () { return _this._getTrackStats(track_1); }).then(function (report) {
17618
+ // NOTE(mmalavalli): Because RSPv3 is associated with Large Rooms only, the statistics
17619
+ // map will contain an entry associated with only one RTCPeerConnection.
17620
+ var mediaStreamTrackStats = report.values().next().value;
17621
+ if (trackReceiver) {
17622
+ _this._switchOnMediaStreamTrackStats = mediaStreamTrackStats;
17623
+ }
17624
+ _this._switchOffStateChangeStats = _this.adjustTrackStats(mediaStreamTrackStats);
17625
+ _this._pendingGetTrackStatsPromise = Promise.resolve();
17626
+ });
17627
+ }
17628
+ this._trackTransceiver = trackReceiver;
17629
+ this._isSubscribed = isSubscribed;
17630
+ if (shouldEmitUpdated) {
17631
+ this.emit('updated');
17632
+ }
17633
+ return this;
17634
+ };
17635
+ /**
17636
+ * Compare the {@link RemoteTrackPublicationV3} to a
17637
+ * {@link RemoteTrackPublicationV3#Representation} of itself and perform any
17638
+ * updates necessary.
17639
+ * @param {RemoteTrackPublicationV3#Representation} track
17640
+ * @returns {this}
17641
+ * @fires TrackSignaling#updated
17642
+ */
17643
+ RemoteTrackPublicationV3.prototype.update = function (track) {
17644
+ this.setPriority(track.priority);
17645
+ return this;
17646
+ };
17647
+ return RemoteTrackPublicationV3;
17648
+ }(RemoteTrackPublicationSignaling));
17649
+ /**
17650
+ * @private
17651
+ * @param {boolean} isSwitchedOff
17652
+ * @param {?string} switchOffReason
17653
+ * @returns {boolean}
17654
+ */
17655
+ function isEnabled(isSwitchedOff, switchOffReason) {
17656
+ return !(isSwitchedOff && switchOffReason === 'DISABLED_BY_PUBLISHER');
17657
+ }
17658
+ /**
17659
+ * @private
17660
+ * @param {Track.SID} sid
17661
+ * @param {Track.Kind} kind
17662
+ * @returns {StandardizedTrackStatsReport}
17663
+ */
17664
+ function initialTrackStats(sid, kind) {
17665
+ return Object.assign({
17666
+ bytesReceived: 0,
17667
+ codecName: '',
17668
+ estimatedPlayoutTimestamp: 0,
17669
+ jitter: 0,
17670
+ jitterBufferDelay: 0,
17671
+ jitterBufferEmittedCount: 0,
17672
+ packetsLost: 0,
17673
+ packetsReceived: 0,
17674
+ roundTripTime: 0,
17675
+ ssrc: '',
17676
+ timestamp: 0,
17677
+ trackId: '',
17678
+ trackSid: sid
17679
+ }, {
17680
+ audio: {
17681
+ audioOutputLevel: 0
17682
+ },
17683
+ data: {},
17684
+ video: {
17685
+ frameHeightReceived: 0,
17686
+ frameRateReceived: 0,
17687
+ framesDecoded: 0,
17688
+ frameWidthReceived: 0,
17689
+ totalDecodeTime: 0
17690
+ }
17691
+ }[kind]);
17692
+ }
17693
+ /**
17694
+ * The Room Signaling Protocol (RSP) representation of a {@link RemoteTrackPublicationV3}.
17695
+ * @typedef {object} RemoteTrackPublicationV3#Representation
17696
+ * @property {Track.Kind} kind
17697
+ * @property {string} name
17698
+ * @priority {Track.Priority} priority
17699
+ * @property {Track.SID} sid
17700
+ */
17701
+ module.exports = RemoteTrackPublicationV3;
17702
+
17703
+ },{"../remotetrackpublication":61}],87:[function(require,module,exports){
17704
+ 'use strict';
17705
+ var __extends = (this && this.__extends) || (function () {
17706
+ var extendStatics = function (d, b) {
17707
+ extendStatics = Object.setPrototypeOf ||
17708
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
17709
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
17710
+ return extendStatics(d, b);
17711
+ };
17712
+ return function (d, b) {
17713
+ if (typeof b !== "function" && b !== null)
17714
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
17715
+ extendStatics(d, b);
17716
+ function __() { this.constructor = d; }
17717
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17718
+ };
17719
+ })();
17720
+ var createTwilioError = require('../../util/twilio-video-errors').createTwilioError;
17721
+ var RoomV2 = require('../v2/room');
17722
+ var RemoteParticipantV3 = require('../v3/remoteparticipant');
17723
+ var TrackSubscriptionsSignaling = require('./tracksubscriptionssignaling');
17724
+ /**
17725
+ * @extends RoomV2
17726
+ */
17727
+ var RoomV3 = /** @class */ (function (_super) {
17728
+ __extends(RoomV3, _super);
17729
+ function RoomV3(localParticipant, initialState, transport, peerConnectionManager, options) {
17730
+ var _this = this;
17731
+ options = Object.assign({
17732
+ RemoteParticipantSignaling: RemoteParticipantV3,
17733
+ TrackSubscriptionsSignaling: TrackSubscriptionsSignaling
17734
+ }, options);
17735
+ _this = _super.call(this, localParticipant, initialState, transport, peerConnectionManager, options) || this;
17736
+ return _this;
17737
+ }
17738
+ /**
17739
+ * @private
17740
+ * @override
17741
+ */
17742
+ RoomV3.prototype._addTrackReceiver = function (trackReceiver) {
17743
+ var idType = trackReceiver.kind === 'data' ? 'id' : 'mid';
17744
+ var deferred = this._getOrCreateTrackReceiverDeferred(trackReceiver[idType], idType);
17745
+ deferred.resolve(trackReceiver);
17746
+ return this;
17747
+ };
17748
+ /**
17749
+ * @private
17750
+ * @override
17751
+ */
17752
+ RoomV3.prototype._createRemoteParticipant = function (participantState) {
17753
+ var _this = this;
17754
+ var RemoteParticipantV3 = this._RemoteParticipantSignaling;
17755
+ return new RemoteParticipantV3(participantState, function (trackSid) { return _this._getPendingTrackReceiver(trackSid); }, function (trackSid) { return _this._getInitialTrackSwitchOffState(trackSid); }, function (trackSid, priority) { return _this._trackPrioritySignaling.sendTrackPriorityUpdate(trackSid, 'subscribe', priority); }, function (trackSid, hint) { return _this._renderHintsSignaling.setTrackHint(trackSid, hint); }, function (trackSid) { return _this._renderHintsSignaling.clearTrackHint(trackSid); }, function (track) { return _this._peerConnectionManager.getRemoteTrackStats(track); });
17756
+ };
17757
+ /**
17758
+ * @private
17759
+ * @override
17760
+ */
17761
+ RoomV3.prototype._getInitialTrackSwitchOffState = function (trackSid) {
17762
+ var switchOffState = this._pendingSwitchOffStates.get(trackSid)
17763
+ || { state: 'OFF', switchOffReason: 'DISABLED_BY_SUBSCRIBER' };
17764
+ this._pendingSwitchOffStates.delete(trackSid);
17765
+ return switchOffState;
17766
+ };
17767
+ /**
17768
+ * @private
17769
+ */
17770
+ RoomV3.prototype._getPendingTrackReceiver = function (trackSid) {
17771
+ var dataChannelLabel = this._pendingDataChannelLabels.get(trackSid);
17772
+ var mid = this._pendingTrackMids.get(trackSid);
17773
+ var promise = Promise.resolve(null);
17774
+ if (dataChannelLabel) {
17775
+ this._pendingDataChannelLabels.delete(trackSid);
17776
+ promise = this._getTrackReceiver(dataChannelLabel);
17777
+ }
17778
+ else if (mid) {
17779
+ this._pendingTrackMids.delete(trackSid);
17780
+ promise = this._getTrackReceiver(mid, 'mid');
17781
+ }
17782
+ return promise;
17783
+ };
17784
+ /**
17785
+ * @private
17786
+ * @override
17787
+ */
17788
+ RoomV3.prototype._handleSubscriptions = function () {
17789
+ /* Do nothing since RSP v3 messages will not contain the "subscribed" property. */
17790
+ };
17791
+ /**
17792
+ * @private
17793
+ * @override
17794
+ */
17795
+ RoomV3.prototype._init = function (localParticipant, peerConnectionManager, transport, options, initialState) {
17796
+ var _this = this;
17797
+ var getTrackReceiver = function (id) { return _this._getTrackReceiver(id); };
17798
+ var log = this._log;
17799
+ Object.defineProperties(this, {
17800
+ _pendingDataChannelLabels: {
17801
+ value: new Map()
17802
+ },
17803
+ _pendingTrackMids: {
17804
+ value: new Map()
17805
+ },
17806
+ _trackSubscriptionsSignaling: {
17807
+ value: new options.TrackSubscriptionsSignaling(getTrackReceiver, { log: log })
17808
+ }
17809
+ });
17810
+ this._initTrackSubscriptionsSignaling();
17811
+ _super.prototype._init.call(this, localParticipant, peerConnectionManager, transport, options, initialState);
17812
+ };
17813
+ /**
17814
+ * @private
17815
+ */
17816
+ RoomV3.prototype._initTrackSubscriptionsSignaling = function () {
17817
+ var _this = this;
17818
+ this._trackSubscriptionsSignaling.on('updated', function (media, data, errors) {
17819
+ var trackSidsToTrackSignalings = _this._getTrackSidsToTrackSignalings();
17820
+ var dataTrackSidsToTrackStates = new Map(Object.entries(data));
17821
+ var mediaTrackSidsToTrackStates = new Map(Object.entries(media));
17822
+ var trackSidsToErrors = new Map(Object.entries(errors));
17823
+ mediaTrackSidsToTrackStates.forEach(function (_a, sid) {
17824
+ var mid = _a.mid, _b = _a.off_reason, switchOffReason = _b === void 0 ? null : _b, state = _a.state;
17825
+ var trackSignaling = trackSidsToTrackSignalings.get(sid);
17826
+ var trackState = { state: state, switchOffReason: switchOffReason };
17827
+ if (!trackSignaling) {
17828
+ _this._pendingSwitchOffStates.set(sid, trackState);
17829
+ _this._pendingTrackMids.set(sid, mid);
17830
+ return;
17831
+ }
17832
+ var isSwitchedOff = state === 'OFF';
17833
+ if (isSwitchedOff || (trackSignaling.trackTransceiver && trackSignaling.trackTransceiver.mid !== mid)) {
17834
+ // NOTE(mmalavalli): If a RemoteTrackPublicationV3's MID changes, then we need to unsubscribe
17835
+ // from the RemoteTrack before subscribing to it again with the MediaTrackReceiver associated with the new
17836
+ // MID. If a RemoteTrackPublicationV3's RemoteTrack is switched off, then we should still be subscribed
17837
+ // to it, even though it no longer has an MID associated with it.
17838
+ trackSignaling.setTrackTransceiver(null, isSwitchedOff);
17839
+ _this._trackSidsToTrackIds.delete(trackSignaling.sid);
17840
+ }
17841
+ if (!isSwitchedOff) {
17842
+ _this._getTrackReceiver(mid, 'mid').then(function (trackReceiver) {
17843
+ trackSignaling.setTrackTransceiver(trackReceiver, true);
17844
+ _this._trackSidsToTrackIds.set(trackSignaling.sid, trackReceiver.id);
17845
+ // NOTE(mpatwardhan): when track is switched on, send the switchOn message
17846
+ // only after track receiver is set so that application can access (new) mediaStreamTrack
17847
+ trackSignaling.setSwitchedOff(isSwitchedOff, switchOffReason);
17848
+ });
17849
+ }
17850
+ else {
17851
+ trackSignaling.setSwitchedOff(isSwitchedOff, switchOffReason);
17852
+ }
17853
+ });
17854
+ dataTrackSidsToTrackStates.forEach(function (_a, sid) {
17855
+ var label = _a.label;
17856
+ var trackSignaling = trackSidsToTrackSignalings.get(sid);
17857
+ if (!trackSignaling) {
17858
+ _this._pendingDataChannelLabels.set(sid, label);
17859
+ return;
17860
+ }
17861
+ _this._getTrackReceiver(label).then(function (trackReceiver) { return trackSignaling.setTrackTransceiver(trackReceiver, true); });
17862
+ });
17863
+ trackSidsToErrors.forEach(function (_a, sid) {
17864
+ var code = _a.code, message = _a.message;
17865
+ var trackSignaling = trackSidsToTrackSignalings.get(sid);
17866
+ if (trackSignaling) {
17867
+ trackSignaling.subscribeFailed(createTwilioError(code, message));
17868
+ }
17869
+ });
17870
+ trackSidsToTrackSignalings.forEach(function (trackSignaling) {
17871
+ var sid = trackSignaling.sid;
17872
+ if (!mediaTrackSidsToTrackStates.has(sid) && !dataTrackSidsToTrackStates.has(sid)) {
17873
+ _this._pendingSwitchOffStates.delete(sid);
17874
+ _this._pendingTrackMids.delete(sid);
17875
+ trackSignaling.setTrackTransceiver(null, false);
17876
+ _this._trackSidsToTrackIds.delete(trackSignaling.sid);
17877
+ }
17878
+ });
17879
+ });
17880
+ };
17881
+ /**
17882
+ * @private
17883
+ * @override
17884
+ */
17885
+ RoomV3.prototype._updateSubscribed = function (roomState) {
17886
+ /* Do nothing since RSP v3 messages will not contain the "subscribed" property. */
17887
+ };
17888
+ /**
17889
+ * Get the {@link RoomV3}'s media statistics. Note that the values reported
17890
+ * are best-effort approximations based off of the raw WebRTC statistics.
17891
+ * @returns {Promise.<Map<PeerConnectionV2#id, StandardizedStatsResponse>>}
17892
+ */
17893
+ RoomV3.prototype.getStats = function () {
17894
+ var _this = this;
17895
+ return _super.prototype.getStats.call(this).then(function (responses) {
17896
+ var trackSidsToTrackSignalings = _this._getTrackSidsToTrackSignalings();
17897
+ var trackSignalings = Array.from(trackSidsToTrackSignalings.values());
17898
+ var switchedOffMediaTrackSignalings = trackSignalings.filter(function (_a) {
17899
+ var isSubscribed = _a.isSubscribed, isSwitchedOff = _a.isSwitchedOff, kind = _a.kind;
17900
+ return kind !== 'data' && isSubscribed && isSwitchedOff;
17901
+ });
17902
+ var switchedOffMediaTrackSidsToTrackStats = new Map(switchedOffMediaTrackSignalings.map(function (trackSignaling) { return [trackSignaling.sid, trackSignaling.adjustTrackStats()]; }));
17903
+ responses.forEach(function (response) {
17904
+ var remoteAudioTrackStats = response.remoteAudioTrackStats, remoteVideoTrackStats = response.remoteVideoTrackStats;
17905
+ // NOTE(mmalavalli): Adjust stats for switched on RemoteAudioTracks with respect
17906
+ // to its associated MediaStreamTrack.
17907
+ remoteAudioTrackStats.forEach(function (stats, i) {
17908
+ var trackSignaling = trackSidsToTrackSignalings.get(stats.trackSid);
17909
+ if (trackSignaling) {
17910
+ remoteAudioTrackStats[i] = trackSignaling.adjustTrackStats(stats);
17911
+ }
17912
+ });
17913
+ // NOTE(mmalavalli): Adjust stats for switched on RemoteVideoTracks with respect
17914
+ // to its associated MediaStreamTrack.
17915
+ remoteVideoTrackStats.forEach(function (stats, i) {
17916
+ var trackSignaling = trackSidsToTrackSignalings.get(stats.trackSid);
17917
+ if (trackSignaling) {
17918
+ remoteVideoTrackStats[i] = trackSignaling.adjustTrackStats(stats);
17919
+ }
17920
+ });
17921
+ // NOTE(mmalavalli): Add stats for switched off media RemoteTracks in
17922
+ // remoteAudioTrackStats and remoteVideoTrackStats respectively.
17923
+ switchedOffMediaTrackSidsToTrackStats.forEach(function (trackStats, trackSid) {
17924
+ var trackSignaling = trackSidsToTrackSignalings.get(trackSid) || {};
17925
+ var trackStatsWithTrackSid = Object.assign({ trackSid: trackSid }, trackStats);
17926
+ if (trackSignaling.kind === 'audio') {
17927
+ remoteAudioTrackStats.push(trackStatsWithTrackSid);
17928
+ }
17929
+ else if (trackSignaling.kind === 'video') {
17930
+ remoteVideoTrackStats.push(trackStatsWithTrackSid);
17931
+ }
17932
+ });
17933
+ });
17934
+ return responses;
17935
+ });
17936
+ };
17937
+ return RoomV3;
17938
+ }(RoomV2));
17939
+ module.exports = RoomV3;
17940
+
17941
+ },{"../../util/twilio-video-errors":147,"../v2/room":81,"../v3/remoteparticipant":85,"./tracksubscriptionssignaling":88}],88:[function(require,module,exports){
17942
+ 'use strict';
17943
+ var __extends = (this && this.__extends) || (function () {
17944
+ var extendStatics = function (d, b) {
17945
+ extendStatics = Object.setPrototypeOf ||
17946
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
17947
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
17948
+ return extendStatics(d, b);
17949
+ };
17950
+ return function (d, b) {
17951
+ if (typeof b !== "function" && b !== null)
17952
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
17953
+ extendStatics(d, b);
17954
+ function __() { this.constructor = d; }
17955
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17956
+ };
17957
+ })();
17958
+ var MediaSignaling = require('../v2/mediasignaling');
17959
+ var TrackSubscriptionsSignaling = /** @class */ (function (_super) {
17960
+ __extends(TrackSubscriptionsSignaling, _super);
17961
+ /**
17962
+ * Construct a {@link TrackSubscriptionsSignaling}.
17963
+ */
17964
+ function TrackSubscriptionsSignaling(getReceiver, options) {
17965
+ var _this = _super.call(this, getReceiver, 'track_subscriptions', options) || this;
17966
+ Object.defineProperties(_this, {
17967
+ _currentRevision: {
17968
+ value: null,
17969
+ writable: true
17970
+ }
17971
+ });
17972
+ var log = _this._log;
17973
+ _this.on('ready', function (transport) {
17974
+ log.debug(_this.channel + " transport ready");
17975
+ transport.on('message', function (message) {
17976
+ switch (message.type) {
17977
+ case _this.channel:
17978
+ _this._handleIncomingMessage(message);
17979
+ break;
17980
+ default:
17981
+ log.warn("Unknown " + _this.channel + " MSP message type:", message.type);
17982
+ break;
17983
+ }
17984
+ });
17985
+ // NOTE(mpatwardhan): we receive ready message every time
17986
+ // MSP channel is established. That means at startup and at every VMS-failover.
17987
+ if (_this._currentRevision !== null) {
17988
+ log.warn('resetting current version after VMS failover', _this._currentRevision);
17989
+ _this._currentRevision = null;
17990
+ }
17991
+ });
17992
+ return _this;
17993
+ }
17994
+ /**
17995
+ * @private
17996
+ */
17997
+ TrackSubscriptionsSignaling.prototype._handleIncomingMessage = function (message) {
17998
+ var _a = this, log = _a._log, currentRevision = _a._currentRevision;
17999
+ var _b = message.data, data = _b === void 0 ? {} : _b, _c = message.errors, errors = _c === void 0 ? {} : _c, _d = message.media, media = _d === void 0 ? {} : _d, revision = message.revision;
18000
+ // TODO(mmalavalli): Remove this once SFU sends revision as integer instead of string.
18001
+ var revisionNumber = Number(revision);
18002
+ if (currentRevision !== null && currentRevision >= revisionNumber) {
18003
+ log.warn("Ignoring incoming " + this.channel + " message as " + currentRevision + " (current revision) >= " + revision + " (incoming revision)");
18004
+ log.debug("Ignored incoming " + this.channel + " message:", message);
18005
+ return;
18006
+ }
18007
+ log.debug("Incoming " + this.channel + " MSP message:", message);
18008
+ this._currentRevision = revisionNumber;
18009
+ this.emit('updated', media, data, errors);
18010
+ };
18011
+ return TrackSubscriptionsSignaling;
18012
+ }(MediaSignaling));
18013
+ module.exports = TrackSubscriptionsSignaling;
18014
+
18015
+ },{"../v2/mediasignaling":71}],89:[function(require,module,exports){
16915
18016
  'use strict';
16916
18017
  var __extends = (this && this.__extends) || (function () {
16917
18018
  var extendStatics = function (d, b) {
@@ -17357,7 +18458,7 @@ function createUnreachableError(here, there) {
17357
18458
  }
17358
18459
  module.exports = StateMachine;
17359
18460
 
17360
- },{"./util":128,"events":170}],86:[function(require,module,exports){
18461
+ },{"./util":132,"events":174}],90:[function(require,module,exports){
17361
18462
  /* eslint no-undefined:0 */
17362
18463
  'use strict';
17363
18464
  /**
@@ -17370,7 +18471,7 @@ function average(xs) {
17370
18471
  }
17371
18472
  module.exports = average;
17372
18473
 
17373
- },{}],87:[function(require,module,exports){
18474
+ },{}],91:[function(require,module,exports){
17374
18475
  'use strict';
17375
18476
  /**
17376
18477
  * @property {number} [availableSend] - bps (undefined in Firefox)
@@ -17428,7 +18529,7 @@ var IceReport = /** @class */ (function () {
17428
18529
  }());
17429
18530
  module.exports = IceReport;
17430
18531
 
17431
- },{}],88:[function(require,module,exports){
18532
+ },{}],92:[function(require,module,exports){
17432
18533
  'use strict';
17433
18534
  var IceReport = require('./icereport');
17434
18535
  /**
@@ -17473,7 +18574,7 @@ var IceReportFactory = /** @class */ (function () {
17473
18574
  }());
17474
18575
  module.exports = IceReportFactory;
17475
18576
 
17476
- },{"./icereport":87}],89:[function(require,module,exports){
18577
+ },{"./icereport":91}],93:[function(require,module,exports){
17477
18578
  'use strict';
17478
18579
  var __extends = (this && this.__extends) || (function () {
17479
18580
  var extendStatics = function (d, b) {
@@ -17531,7 +18632,7 @@ var LocalAudioTrackStats = /** @class */ (function (_super) {
17531
18632
  */
17532
18633
  module.exports = LocalAudioTrackStats;
17533
18634
 
17534
- },{"./localtrackstats":90}],90:[function(require,module,exports){
18635
+ },{"./localtrackstats":94}],94:[function(require,module,exports){
17535
18636
  'use strict';
17536
18637
  var __extends = (this && this.__extends) || (function () {
17537
18638
  var extendStatics = function (d, b) {
@@ -17591,7 +18692,7 @@ var LocalTrackStats = /** @class */ (function (_super) {
17591
18692
  }(TrackStats));
17592
18693
  module.exports = LocalTrackStats;
17593
18694
 
17594
- },{"./trackstats":115}],91:[function(require,module,exports){
18695
+ },{"./trackstats":119}],95:[function(require,module,exports){
17595
18696
  'use strict';
17596
18697
  var __extends = (this && this.__extends) || (function () {
17597
18698
  var extendStatics = function (d, b) {
@@ -17684,7 +18785,7 @@ var LocalVideoTrackStats = /** @class */ (function (_super) {
17684
18785
  }(LocalTrackStats));
17685
18786
  module.exports = LocalVideoTrackStats;
17686
18787
 
17687
- },{"./localtrackstats":90}],92:[function(require,module,exports){
18788
+ },{"./localtrackstats":94}],96:[function(require,module,exports){
17688
18789
  'use strict';
17689
18790
  var __extends = (this && this.__extends) || (function () {
17690
18791
  var extendStatics = function (d, b) {
@@ -17718,7 +18819,7 @@ var NetworkQualityAudioStats = /** @class */ (function (_super) {
17718
18819
  }(NetworkQualityMediaStats));
17719
18820
  module.exports = NetworkQualityAudioStats;
17720
18821
 
17721
- },{"./networkqualitymediastats":96}],93:[function(require,module,exports){
18822
+ },{"./networkqualitymediastats":100}],97:[function(require,module,exports){
17722
18823
  'use strict';
17723
18824
  /**
17724
18825
  * Bandwidth network quality statistics.
@@ -17752,7 +18853,7 @@ var NetworkQualityBandwidthStats = /** @class */ (function () {
17752
18853
  }());
17753
18854
  module.exports = NetworkQualityBandwidthStats;
17754
18855
 
17755
- },{}],94:[function(require,module,exports){
18856
+ },{}],98:[function(require,module,exports){
17756
18857
  'use strict';
17757
18858
  /**
17758
18859
  * Fraction lost network quality statistics.
@@ -17781,7 +18882,7 @@ var NetworkQualityFractionLostStats = /** @class */ (function () {
17781
18882
  }());
17782
18883
  module.exports = NetworkQualityFractionLostStats;
17783
18884
 
17784
- },{}],95:[function(require,module,exports){
18885
+ },{}],99:[function(require,module,exports){
17785
18886
  'use strict';
17786
18887
  /**
17787
18888
  * Latency network quality statistics.
@@ -17815,7 +18916,7 @@ var NetworkQualityLatencyStats = /** @class */ (function () {
17815
18916
  }());
17816
18917
  module.exports = NetworkQualityLatencyStats;
17817
18918
 
17818
- },{}],96:[function(require,module,exports){
18919
+ },{}],100:[function(require,module,exports){
17819
18920
  'use strict';
17820
18921
  var NetworkQualitySendStats = require('./networkqualitysendstats');
17821
18922
  var NetworkQualityRecvStats = require('./networkqualityrecvstats');
@@ -17862,7 +18963,7 @@ var NetworkQualityMediaStats = /** @class */ (function () {
17862
18963
  }());
17863
18964
  module.exports = NetworkQualityMediaStats;
17864
18965
 
17865
- },{"./networkqualityrecvstats":97,"./networkqualitysendstats":99}],97:[function(require,module,exports){
18966
+ },{"./networkqualityrecvstats":101,"./networkqualitysendstats":103}],101:[function(require,module,exports){
17866
18967
  'use strict';
17867
18968
  var __extends = (this && this.__extends) || (function () {
17868
18969
  var extendStatics = function (d, b) {
@@ -17897,7 +18998,7 @@ var NetworkQualityRecvStats = /** @class */ (function (_super) {
17897
18998
  }(NetworkQualitySendOrRecvStats));
17898
18999
  module.exports = NetworkQualityRecvStats;
17899
19000
 
17900
- },{"./networkqualitysendorrecvstats":98}],98:[function(require,module,exports){
19001
+ },{"./networkqualitysendorrecvstats":102}],102:[function(require,module,exports){
17901
19002
  'use strict';
17902
19003
  var NetworkQualityBandwidthStats = require('./networkqualitybandwidthstats');
17903
19004
  var NetworkQualityFractionLostStats = require('./networkqualityfractionloststats');
@@ -17937,7 +19038,7 @@ var NetworkQualitySendOrRecvStats = /** @class */ (function () {
17937
19038
  }());
17938
19039
  module.exports = NetworkQualitySendOrRecvStats;
17939
19040
 
17940
- },{"./networkqualitybandwidthstats":93,"./networkqualityfractionloststats":94,"./networkqualitylatencystats":95}],99:[function(require,module,exports){
19041
+ },{"./networkqualitybandwidthstats":97,"./networkqualityfractionloststats":98,"./networkqualitylatencystats":99}],103:[function(require,module,exports){
17941
19042
  'use strict';
17942
19043
  var __extends = (this && this.__extends) || (function () {
17943
19044
  var extendStatics = function (d, b) {
@@ -17972,7 +19073,7 @@ var NetworkQualitySendStats = /** @class */ (function (_super) {
17972
19073
  }(NetworkQualitySendOrRecvStats));
17973
19074
  module.exports = NetworkQualitySendStats;
17974
19075
 
17975
- },{"./networkqualitysendorrecvstats":98}],100:[function(require,module,exports){
19076
+ },{"./networkqualitysendorrecvstats":102}],104:[function(require,module,exports){
17976
19077
  'use strict';
17977
19078
  var NetworkQualityAudioStats = require('./networkqualityaudiostats');
17978
19079
  var NetworkQualityVideoStats = require('./networkqualityvideostats');
@@ -18012,7 +19113,7 @@ var NetworkQualityStats = /** @class */ (function () {
18012
19113
  }());
18013
19114
  module.exports = NetworkQualityStats;
18014
19115
 
18015
- },{"./networkqualityaudiostats":92,"./networkqualityvideostats":101}],101:[function(require,module,exports){
19116
+ },{"./networkqualityaudiostats":96,"./networkqualityvideostats":105}],105:[function(require,module,exports){
18016
19117
  'use strict';
18017
19118
  var __extends = (this && this.__extends) || (function () {
18018
19119
  var extendStatics = function (d, b) {
@@ -18046,7 +19147,7 @@ var NetworkQualityVideoStats = /** @class */ (function (_super) {
18046
19147
  }(NetworkQualityMediaStats));
18047
19148
  module.exports = NetworkQualityVideoStats;
18048
19149
 
18049
- },{"./networkqualitymediastats":96}],102:[function(require,module,exports){
19150
+ },{"./networkqualitymediastats":100}],106:[function(require,module,exports){
18050
19151
  'use strict';
18051
19152
  var ReceiverReport = require('./receiverreport');
18052
19153
  var SenderReport = require('./senderreport');
@@ -18124,7 +19225,7 @@ var PeerConnectionReport = /** @class */ (function () {
18124
19225
  }());
18125
19226
  module.exports = PeerConnectionReport;
18126
19227
 
18127
- },{"./receiverreport":104,"./senderreport":111}],103:[function(require,module,exports){
19228
+ },{"./receiverreport":108,"./senderreport":115}],107:[function(require,module,exports){
18128
19229
  'use strict';
18129
19230
  var __read = (this && this.__read) || function (o, n) {
18130
19231
  var m = typeof Symbol === "function" && o[Symbol.iterator];
@@ -18554,7 +19655,7 @@ function updateChrome(factory) {
18554
19655
  }
18555
19656
  module.exports = PeerConnectionReportFactory;
18556
19657
 
18557
- },{"../webrtc/util":167,"./icereportfactory":88,"./peerconnectionreport":102,"./receiverreportfactory":105,"./senderreportfactory":112}],104:[function(require,module,exports){
19658
+ },{"../webrtc/util":171,"./icereportfactory":92,"./peerconnectionreport":106,"./receiverreportfactory":109,"./senderreportfactory":116}],108:[function(require,module,exports){
18558
19659
  'use strict';
18559
19660
  var __extends = (this && this.__extends) || (function () {
18560
19661
  var extendStatics = function (d, b) {
@@ -18680,7 +19781,7 @@ var ReceiverReport = /** @class */ (function (_super) {
18680
19781
  }(SenderOrReceiverReport));
18681
19782
  module.exports = ReceiverReport;
18682
19783
 
18683
- },{"./average":86,"./senderorreceiverreport":109,"./sum":114}],105:[function(require,module,exports){
19784
+ },{"./average":90,"./senderorreceiverreport":113,"./sum":118}],109:[function(require,module,exports){
18684
19785
  'use strict';
18685
19786
  var __extends = (this && this.__extends) || (function () {
18686
19787
  var extendStatics = function (d, b) {
@@ -18739,7 +19840,7 @@ var ReceiverReportFactory = /** @class */ (function (_super) {
18739
19840
  }(SenderOrReceiverReportFactory));
18740
19841
  module.exports = ReceiverReportFactory;
18741
19842
 
18742
- },{"./receiverreport":104,"./senderorreceiverreportfactory":110}],106:[function(require,module,exports){
19843
+ },{"./receiverreport":108,"./senderorreceiverreportfactory":114}],110:[function(require,module,exports){
18743
19844
  'use strict';
18744
19845
  var __extends = (this && this.__extends) || (function () {
18745
19846
  var extendStatics = function (d, b) {
@@ -18791,7 +19892,7 @@ var RemoteAudioTrackStats = /** @class */ (function (_super) {
18791
19892
  }(RemoteTrackStats));
18792
19893
  module.exports = RemoteAudioTrackStats;
18793
19894
 
18794
- },{"./remotetrackstats":107}],107:[function(require,module,exports){
19895
+ },{"./remotetrackstats":111}],111:[function(require,module,exports){
18795
19896
  'use strict';
18796
19897
  var __extends = (this && this.__extends) || (function () {
18797
19898
  var extendStatics = function (d, b) {
@@ -18843,7 +19944,7 @@ var RemoteTrackStats = /** @class */ (function (_super) {
18843
19944
  }(TrackStats));
18844
19945
  module.exports = RemoteTrackStats;
18845
19946
 
18846
- },{"./trackstats":115}],108:[function(require,module,exports){
19947
+ },{"./trackstats":119}],112:[function(require,module,exports){
18847
19948
  'use strict';
18848
19949
  var __extends = (this && this.__extends) || (function () {
18849
19950
  var extendStatics = function (d, b) {
@@ -18908,7 +20009,7 @@ var RemoteVideoTrackStats = /** @class */ (function (_super) {
18908
20009
  }(RemoteTrackStats));
18909
20010
  module.exports = RemoteVideoTrackStats;
18910
20011
 
18911
- },{"./remotetrackstats":107}],109:[function(require,module,exports){
20012
+ },{"./remotetrackstats":111}],113:[function(require,module,exports){
18912
20013
  'use strict';
18913
20014
  /**
18914
20015
  * @property {StatsId} id
@@ -18942,7 +20043,7 @@ var SenderOrReceiverReport = /** @class */ (function () {
18942
20043
  }());
18943
20044
  module.exports = SenderOrReceiverReport;
18944
20045
 
18945
- },{}],110:[function(require,module,exports){
20046
+ },{}],114:[function(require,module,exports){
18946
20047
  'use strict';
18947
20048
  /**
18948
20049
  * @property {StatsId} id
@@ -18978,7 +20079,7 @@ var SenderOrReceiverReportFactory = /** @class */ (function () {
18978
20079
  }());
18979
20080
  module.exports = SenderOrReceiverReportFactory;
18980
20081
 
18981
- },{}],111:[function(require,module,exports){
20082
+ },{}],115:[function(require,module,exports){
18982
20083
  /* eslint no-undefined:0 */
18983
20084
  'use strict';
18984
20085
  var __extends = (this && this.__extends) || (function () {
@@ -19066,7 +20167,7 @@ var SenderReport = /** @class */ (function (_super) {
19066
20167
  }(SenderOrReceiverReport));
19067
20168
  module.exports = SenderReport;
19068
20169
 
19069
- },{"./average":86,"./senderorreceiverreport":109,"./sum":114}],112:[function(require,module,exports){
20170
+ },{"./average":90,"./senderorreceiverreport":113,"./sum":118}],116:[function(require,module,exports){
19070
20171
  'use strict';
19071
20172
  var __extends = (this && this.__extends) || (function () {
19072
20173
  var extendStatics = function (d, b) {
@@ -19125,7 +20226,7 @@ var SenderReportFactory = /** @class */ (function (_super) {
19125
20226
  }(SenderOrReceiverReportFactory));
19126
20227
  module.exports = SenderReportFactory;
19127
20228
 
19128
- },{"./senderorreceiverreportfactory":110,"./senderreport":111}],113:[function(require,module,exports){
20229
+ },{"./senderorreceiverreportfactory":114,"./senderreport":115}],117:[function(require,module,exports){
19129
20230
  'use strict';
19130
20231
  var LocalAudioTrackStats = require('./localaudiotrackstats');
19131
20232
  var LocalVideoTrackStats = require('./localvideotrackstats');
@@ -19176,7 +20277,7 @@ var StatsReport = /** @class */ (function () {
19176
20277
  }());
19177
20278
  module.exports = StatsReport;
19178
20279
 
19179
- },{"./localaudiotrackstats":89,"./localvideotrackstats":91,"./remoteaudiotrackstats":106,"./remotevideotrackstats":108}],114:[function(require,module,exports){
20280
+ },{"./localaudiotrackstats":93,"./localvideotrackstats":95,"./remoteaudiotrackstats":110,"./remotevideotrackstats":112}],118:[function(require,module,exports){
19180
20281
  'use strict';
19181
20282
  /**
19182
20283
  * @param {Array<number|undefined>} xs
@@ -19187,7 +20288,7 @@ function sum(xs) {
19187
20288
  }
19188
20289
  module.exports = sum;
19189
20290
 
19190
- },{}],115:[function(require,module,exports){
20291
+ },{}],119:[function(require,module,exports){
19191
20292
  'use strict';
19192
20293
  /**
19193
20294
  * Statistics for a {@link Track}.
@@ -19246,7 +20347,7 @@ var TrackStats = /** @class */ (function () {
19246
20347
  }());
19247
20348
  module.exports = TrackStats;
19248
20349
 
19249
- },{}],116:[function(require,module,exports){
20350
+ },{}],120:[function(require,module,exports){
19250
20351
  'use strict';
19251
20352
  var __extends = (this && this.__extends) || (function () {
19252
20353
  var extendStatics = function (d, b) {
@@ -19308,7 +20409,7 @@ var TrackTransceiver = /** @class */ (function (_super) {
19308
20409
  */
19309
20410
  module.exports = TrackTransceiver;
19310
20411
 
19311
- },{"events":170}],117:[function(require,module,exports){
20412
+ },{"events":174}],121:[function(require,module,exports){
19312
20413
  'use strict';
19313
20414
  var __extends = (this && this.__extends) || (function () {
19314
20415
  var extendStatics = function (d, b) {
@@ -19961,7 +21062,7 @@ TwilioConnection.CloseReason = CloseReason;
19961
21062
  */
19962
21063
  module.exports = TwilioConnection;
19963
21064
 
19964
- },{"./statemachine":85,"./util":128,"./util/log":132,"./util/networkmonitor":134,"./util/timeout":142,"ws":172}],118:[function(require,module,exports){
21065
+ },{"./statemachine":89,"./util":132,"./util/log":136,"./util/networkmonitor":138,"./util/timeout":146,"ws":176}],122:[function(require,module,exports){
19965
21066
  'use strict';
19966
21067
  var defer = require('./').defer;
19967
21068
  /**
@@ -20026,7 +21127,7 @@ var AsyncVar = /** @class */ (function () {
20026
21127
  }());
20027
21128
  module.exports = AsyncVar;
20028
21129
 
20029
- },{"./":128}],119:[function(require,module,exports){
21130
+ },{"./":132}],123:[function(require,module,exports){
20030
21131
  /**
20031
21132
  * Expose `Backoff`.
20032
21133
  */
@@ -20110,7 +21211,7 @@ var Backoff = /** @class */ (function () {
20110
21211
  }());
20111
21212
  module.exports = Backoff;
20112
21213
 
20113
- },{}],120:[function(require,module,exports){
21214
+ },{}],124:[function(require,module,exports){
20114
21215
  /* globals chrome, navigator */
20115
21216
  'use strict';
20116
21217
  var __read = (this && this.__read) || function (o, n) {
@@ -20267,7 +21368,7 @@ module.exports = {
20267
21368
  rebrandedChromeBrowser: rebrandedChromeBrowser
20268
21369
  };
20269
21370
 
20270
- },{}],121:[function(require,module,exports){
21371
+ },{}],125:[function(require,module,exports){
20271
21372
  'use strict';
20272
21373
  var __read = (this && this.__read) || function (o, n) {
20273
21374
  var m = typeof Symbol === "function" && o[Symbol.iterator];
@@ -20410,7 +21511,7 @@ var CancelablePromise = /** @class */ (function () {
20410
21511
  }());
20411
21512
  module.exports = CancelablePromise;
20412
21513
 
20413
- },{}],122:[function(require,module,exports){
21514
+ },{}],126:[function(require,module,exports){
20414
21515
  'use strict';
20415
21516
  /* eslint-disable camelcase */
20416
21517
  var packageInfo = require('../../package.json');
@@ -20498,6 +21599,13 @@ module.exports.trackSwitchOffMode = {
20498
21599
  MODE_DETECTED: 'detected',
20499
21600
  MODE_PREDICTED: 'predicted'
20500
21601
  };
21602
+ module.exports.trackSwitchOffReason = {
21603
+ DISABLED_BY_PUBLISHER: 'disabled-by-publisher',
21604
+ DISABLED_BY_SUBSCRIBER: 'disabled-by-subscriber',
21605
+ MAX_BANDWIDTH_REACHED: 'max-bandwidth-reached',
21606
+ MAX_TRACKS_SWITCHED_ON: 'max-tracks-switched-on',
21607
+ NETWORK_CONGESTION: 'network-congestion'
21608
+ };
20501
21609
  module.exports.trackPriority = {
20502
21610
  PRIORITY_HIGH: 'high',
20503
21611
  PRIORITY_LOW: 'low',
@@ -20512,7 +21620,7 @@ module.exports.videoContentPreferencesMode = {
20512
21620
  MODE_MANUAL: 'manual'
20513
21621
  };
20514
21622
 
20515
- },{"../../package.json":171}],123:[function(require,module,exports){
21623
+ },{"../../package.json":175}],127:[function(require,module,exports){
20516
21624
  'use strict';
20517
21625
  var detectSilence = require('../webaudio/detectsilence');
20518
21626
  var N_ATTEMPTS = 3;
@@ -20553,7 +21661,7 @@ function detectSilentAudio(el) {
20553
21661
  }
20554
21662
  module.exports = detectSilentAudio;
20555
21663
 
20556
- },{"../webaudio/audiocontext":149,"../webaudio/detectsilence":150}],124:[function(require,module,exports){
21664
+ },{"../webaudio/audiocontext":153,"../webaudio/detectsilence":154}],128:[function(require,module,exports){
20557
21665
  'use strict';
20558
21666
  // Cached copy of the <canvas> used to check silent video frames.
20559
21667
  var canvas = null;
@@ -20612,7 +21720,7 @@ function detectSilentVideo(el) {
20612
21720
  }
20613
21721
  module.exports = detectSilentVideo;
20614
21722
 
20615
- },{}],125:[function(require,module,exports){
21723
+ },{}],129:[function(require,module,exports){
20616
21724
  'use strict';
20617
21725
  /**
20618
21726
  * The {@link DocumentVisibilityMonitor} monitors the visibility state of the DOM
@@ -20734,7 +21842,7 @@ var DocumentVisibilityMonitor = /** @class */ (function () {
20734
21842
  }());
20735
21843
  module.exports = new DocumentVisibilityMonitor(2);
20736
21844
 
20737
- },{}],126:[function(require,module,exports){
21845
+ },{}],130:[function(require,module,exports){
20738
21846
  /* eslint-disable no-console */
20739
21847
  'use strict';
20740
21848
  var __extends = (this && this.__extends) || (function () {
@@ -20832,7 +21940,7 @@ var EventObserver = /** @class */ (function (_super) {
20832
21940
  */
20833
21941
  module.exports = EventObserver;
20834
21942
 
20835
- },{"events":170}],127:[function(require,module,exports){
21943
+ },{"events":174}],131:[function(require,module,exports){
20836
21944
  'use strict';
20837
21945
  var Filter = /** @class */ (function () {
20838
21946
  function Filter(options) {
@@ -20876,7 +21984,7 @@ var Filter = /** @class */ (function () {
20876
21984
  }());
20877
21985
  module.exports = Filter;
20878
21986
 
20879
- },{}],128:[function(require,module,exports){
21987
+ },{}],132:[function(require,module,exports){
20880
21988
  'use strict';
20881
21989
  var __extends = (this && this.__extends) || (function () {
20882
21990
  var extendStatics = function (d, b) {
@@ -20975,7 +22083,7 @@ function deprecateEvents(name, emitter, events, log) {
20975
22083
  var warningsShown = new Set();
20976
22084
  emitter.on('newListener', function newListener(event) {
20977
22085
  if (events.has(event) && !warningsShown.has(event)) {
20978
- log.deprecated(name + "#" + event + " has been deprecated and scheduled for removal in twilio-video.js@2.0.0." + (events.get(event)
22086
+ log.deprecated(name + "#" + event + " has been deprecated and scheduled for removal." + (events.get(event)
20979
22087
  ? " Use " + name + "#" + events.get(event) + " instead."
20980
22088
  : ''));
20981
22089
  warningsShown.add(event);
@@ -21527,15 +22635,33 @@ function createRoomConnectEventPayload(connectOptions) {
21527
22635
  if (connectOptions.bandwidthProfile && connectOptions.bandwidthProfile.video) {
21528
22636
  var videoBPOptions_1 = connectOptions.bandwidthProfile.video || {};
21529
22637
  payload.bandwidthProfileOptions = {};
21530
- ['mode', 'maxTracks', 'trackSwitchOffMode', 'dominantSpeakerPriority', 'maxSubscriptionBitrate', 'renderDimensions', 'contentPreferencesMode', 'clientTrackSwitchOffControl'].forEach(function (prop) {
21531
- if (typeof videoBPOptions_1[prop] === 'number' || typeof videoBPOptions_1[prop] === 'string') {
21532
- payload.bandwidthProfileOptions[prop] = videoBPOptions_1[prop];
22638
+ ['mode', ['maxSwitchedOnTracks', 'maxVideoTracks'], 'trackSwitchOffMode', 'dominantSpeakerPriority', 'maxSubscriptionBitrate', 'renderDimensions', 'contentPreferencesMode', 'clientTrackSwitchOffControl'].forEach(function (prop) {
22639
+ var destProp = Array.isArray(prop) ? prop[1] : prop;
22640
+ var srcProp = Array.isArray(prop) ? prop[0] : prop;
22641
+ var srcPropValue = videoBPOptions_1[srcProp];
22642
+ if (typeof srcPropValue === 'number' || typeof srcPropValue === 'string') {
22643
+ payload.bandwidthProfileOptions[destProp] = srcPropValue;
21533
22644
  }
21534
- else if (typeof videoBPOptions_1[prop] === 'boolean') {
21535
- payload.bandwidthProfileOptions[prop] = boolToString(videoBPOptions_1[prop]);
22645
+ else if (typeof srcPropValue === 'boolean') {
22646
+ payload.bandwidthProfileOptions[destProp] = boolToString(srcPropValue);
21536
22647
  }
21537
- else if (typeof videoBPOptions_1[prop] === 'object') {
21538
- payload.bandwidthProfileOptions[prop] = JSON.stringify(videoBPOptions_1[prop]);
22648
+ else if (typeof videoBPOptions_1[destProp] === 'object') {
22649
+ payload.bandwidthProfileOptions[destProp] = JSON.stringify(srcPropValue);
22650
+ }
22651
+ });
22652
+ var audioBPOptions_1 = connectOptions.bandwidthProfile.audio || {};
22653
+ [['maxSwitchedOnTracks', 'maxAudioTracks']].forEach(function (prop) {
22654
+ var destProp = Array.isArray(prop) ? prop[1] : prop;
22655
+ var srcProp = Array.isArray(prop) ? prop[0] : prop;
22656
+ var srcPropValue = audioBPOptions_1[srcProp];
22657
+ if (typeof srcPropValue === 'number' || typeof srcPropValue === 'string') {
22658
+ payload.bandwidthProfileOptions[destProp] = srcPropValue;
22659
+ }
22660
+ else if (typeof srcPropValue === 'boolean') {
22661
+ payload.bandwidthProfileOptions[destProp] = boolToString(srcPropValue);
22662
+ }
22663
+ else if (typeof videoBPOptions_1[destProp] === 'object') {
22664
+ payload.bandwidthProfileOptions[destProp] = JSON.stringify(srcPropValue);
21539
22665
  }
21540
22666
  });
21541
22667
  }
@@ -21548,24 +22674,35 @@ function createRoomConnectEventPayload(connectOptions) {
21548
22674
  }
21549
22675
  /**
21550
22676
  * Create the bandwidth profile payload included in an RSP connect message.
21551
- * @param {BandwidthProfileOptions} bandwidthProfile
22677
+ * @param {BandwidthProfile} bandwidthProfile
21552
22678
  * @returns {object}
21553
22679
  */
21554
22680
  function createBandwidthProfilePayload(bandwidthProfile) {
21555
22681
  return createRSPPayload(bandwidthProfile, [
21556
- { prop: 'video', type: 'object', transform: createBandwidthProfileVideoPayload }
22682
+ { prop: 'video', type: 'object', transform: createBandwidthProfileVideoPayload },
22683
+ { prop: 'audio', type: 'object', transform: createBandwidthProfileAudioPayload }
22684
+ ]);
22685
+ }
22686
+ /**
22687
+ * Create the bandwidth profile audio payload included in an RSP connect message.
22688
+ * @param {AudioBandwidthProfile} bandwidthProfileAudio
22689
+ * @returns {object}
22690
+ */
22691
+ function createBandwidthProfileAudioPayload(bandwidthProfileAudio) {
22692
+ return createRSPPayload(bandwidthProfileAudio, [
22693
+ { prop: 'maxSwitchedOnTracks', type: 'number', payloadProp: 'max_tracks' }
21557
22694
  ]);
21558
22695
  }
21559
22696
  /**
21560
22697
  * Create the bandwidth profile video payload included in an RSP connect message.
21561
- * @param {VideoBandwidthProfileOptions} bandwidthProfileVideo
22698
+ * @param {VideoBandwidthProfile} bandwidthProfileVideo
21562
22699
  * @returns {object}
21563
22700
  */
21564
22701
  function createBandwidthProfileVideoPayload(bandwidthProfileVideo) {
21565
22702
  return createRSPPayload(bandwidthProfileVideo, [
21566
22703
  { prop: 'dominantSpeakerPriority', type: 'string', payloadProp: 'active_speaker_priority' },
21567
22704
  { prop: 'maxSubscriptionBitrate', type: 'number', payloadProp: 'max_subscription_bandwidth' },
21568
- { prop: 'maxTracks', type: 'number', payloadProp: 'max_tracks' },
22705
+ { prop: 'maxSwitchedOnTracks', type: 'number', payloadProp: 'max_tracks' },
21569
22706
  { prop: 'mode', type: 'string' },
21570
22707
  { prop: 'renderDimensions', type: 'object', payloadProp: 'render_dimensions', transform: createRenderDimensionsPayload },
21571
22708
  { prop: 'trackSwitchOffMode', type: 'string', payloadProp: 'track_switch_off' }
@@ -21605,7 +22742,9 @@ function createMediaSignalingPayload(dominantSpeaker, networkQuality, trackPrior
21605
22742
  : {}, trackSwitchOff
21606
22743
  // eslint-disable-next-line
21607
22744
  ? { track_switch_off: transports }
21608
- : {});
22745
+ : {},
22746
+ // eslint-disable-next-line
22747
+ { track_subscriptions: transports });
21609
22748
  }
21610
22749
  /**
21611
22750
  * Create {@link VideoTrack.Dimensions} RSP payload.
@@ -21735,6 +22874,36 @@ function waitForEvent(eventTarget, event) {
21735
22874
  });
21736
22875
  });
21737
22876
  }
22877
+ /**
22878
+ * Re-emit {@link TrackPublication} events.
22879
+ * @private
22880
+ * @param {Participant} participant
22881
+ * @param {TrackPublication} publication
22882
+ */
22883
+ function reemitTrackPublicationEvents(participant, publication) {
22884
+ var publicationEventReemitters = new Map();
22885
+ if (participant.state === 'disconnected') {
22886
+ return;
22887
+ }
22888
+ participant._getTrackPublicationEvents().forEach(function (_a) {
22889
+ var _b = __read(_a, 2), publicationEvent = _b[0], participantEvent = _b[1];
22890
+ publicationEventReemitters.set(publicationEvent, function () {
22891
+ var args = [];
22892
+ for (var _i = 0; _i < arguments.length; _i++) {
22893
+ args[_i] = arguments[_i];
22894
+ }
22895
+ if (publicationEvent === 'trackSwitchedOff') {
22896
+ var _a = __read(args, 2), track = _a[0], switchOffReason = _a[1];
22897
+ participant.emit(participantEvent, track, publication, switchOffReason);
22898
+ }
22899
+ else {
22900
+ participant.emit.apply(participant, __spreadArray(__spreadArray([participantEvent], __read(args)), [publication]));
22901
+ }
22902
+ });
22903
+ publication.on(publicationEvent, publicationEventReemitters.get(publicationEvent));
22904
+ });
22905
+ participant._trackPublicationEventReemitters.set(publication.trackSid, publicationEventReemitters);
22906
+ }
21738
22907
  exports.constants = constants;
21739
22908
  exports.createBandwidthProfilePayload = createBandwidthProfilePayload;
21740
22909
  exports.createMediaSignalingPayload = createMediaSignalingPayload;
@@ -21772,8 +22941,9 @@ exports.isChromeScreenShareTrack = isChromeScreenShareTrack;
21772
22941
  exports.isUserMediaTrack = isUserMediaTrack;
21773
22942
  exports.waitForSometime = waitForSometime;
21774
22943
  exports.waitForEvent = waitForEvent;
22944
+ exports.reemitTrackPublicationEvents = reemitTrackPublicationEvents;
21775
22945
 
21776
- },{"../webrtc/util":167,"./constants":122,"./sid":140,"./twiliowarning":145}],129:[function(require,module,exports){
22946
+ },{"../webrtc/util":171,"./constants":126,"./sid":144,"./twiliowarning":149}],133:[function(require,module,exports){
21777
22947
  /* eslint-disable camelcase */
21778
22948
  'use strict';
21779
22949
  var __extends = (this && this.__extends) || (function () {
@@ -22068,7 +23238,7 @@ function reconnect(publisher, token, sdkName, sdkVersion, roomSid, participantSi
22068
23238
  */
22069
23239
  module.exports = InsightsPublisher;
22070
23240
 
22071
- },{"..":128,"../../util":128,"../browserdetection":120,"../constants":122,"events":170,"ws":172}],130:[function(require,module,exports){
23241
+ },{"..":132,"../../util":132,"../browserdetection":124,"../constants":126,"events":174,"ws":176}],134:[function(require,module,exports){
22072
23242
  // eslint-disable-next-line no-warning-comments
22073
23243
  // TODO(mroberts): This should be described as implementing some
22074
23244
  // InsightsPublisher interface.
@@ -22113,7 +23283,7 @@ var InsightsPublisher = /** @class */ (function () {
22113
23283
  }());
22114
23284
  module.exports = InsightsPublisher;
22115
23285
 
22116
- },{}],131:[function(require,module,exports){
23286
+ },{}],135:[function(require,module,exports){
22117
23287
  'use strict';
22118
23288
  var defer = require('./').defer;
22119
23289
  /**
@@ -22175,7 +23345,7 @@ var LocalMediaRestartDeferreds = /** @class */ (function () {
22175
23345
  }());
22176
23346
  module.exports = new LocalMediaRestartDeferreds();
22177
23347
 
22178
- },{"./":128}],132:[function(require,module,exports){
23348
+ },{"./":132}],136:[function(require,module,exports){
22179
23349
  /* eslint new-cap:0 */
22180
23350
  'use strict';
22181
23351
  var __read = (this && this.__read) || function (o, n) {
@@ -22462,7 +23632,7 @@ function validateLogLevels(levels) {
22462
23632
  }
22463
23633
  module.exports = Log;
22464
23634
 
22465
- },{"../vendor/loglevel":148,"./constants":122}],133:[function(require,module,exports){
23635
+ },{"../vendor/loglevel":152,"./constants":126}],137:[function(require,module,exports){
22466
23636
  'use strict';
22467
23637
  /**
22468
23638
  * Calculates the moving average delta for the given pair ofsamples. A sample (S)
@@ -22509,7 +23679,7 @@ var MovingAverageDelta = /** @class */ (function () {
22509
23679
  }());
22510
23680
  module.exports = MovingAverageDelta;
22511
23681
 
22512
- },{}],134:[function(require,module,exports){
23682
+ },{}],138:[function(require,module,exports){
22513
23683
  'use strict';
22514
23684
  /**
22515
23685
  * Monitor the network connection status to detect interruptions and handoffs.
@@ -22598,7 +23768,7 @@ var NetworkMonitor = /** @class */ (function () {
22598
23768
  }());
22599
23769
  module.exports = NetworkMonitor;
22600
23770
 
22601
- },{}],135:[function(require,module,exports){
23771
+ },{}],139:[function(require,module,exports){
22602
23772
  /* eslint-disable no-console */
22603
23773
  'use strict';
22604
23774
  var __extends = (this && this.__extends) || (function () {
@@ -22661,7 +23831,7 @@ var NullResizeObserver = /** @class */ (function (_super) {
22661
23831
  }(NullObserver));
22662
23832
  module.exports = { NullIntersectionObserver: NullIntersectionObserver, NullResizeObserver: NullResizeObserver, NullObserver: NullObserver };
22663
23833
 
22664
- },{}],136:[function(require,module,exports){
23834
+ },{}],140:[function(require,module,exports){
22665
23835
  'use strict';
22666
23836
  var __read = (this && this.__read) || function (o, n) {
22667
23837
  var m = typeof Symbol === "function" && o[Symbol.iterator];
@@ -23199,7 +24369,7 @@ exports.revertSimulcast = revertSimulcast;
23199
24369
  exports.setCodecPreferences = setCodecPreferences;
23200
24370
  exports.setSimulcast = setSimulcast;
23201
24371
 
23202
- },{"../":128,"./simulcast":138}],137:[function(require,module,exports){
24372
+ },{"../":132,"./simulcast":142}],141:[function(require,module,exports){
23203
24373
  'use strict';
23204
24374
  var RTCSessionDescription = require('../../webrtc').RTCSessionDescription;
23205
24375
  var _a = require('./'), createPtToCodecName = _a.createPtToCodecName, getMediaSections = _a.getMediaSections;
@@ -23392,7 +24562,7 @@ function addFmtpAttributeForRtxPt(mediaSection, rtxPt, pt) {
23392
24562
  }
23393
24563
  module.exports = workaround;
23394
24564
 
23395
- },{"../../webrtc":154,"./":136}],138:[function(require,module,exports){
24565
+ },{"../../webrtc":158,"./":140}],142:[function(require,module,exports){
23396
24566
  'use strict';
23397
24567
  var __read = (this && this.__read) || function (o, n) {
23398
24568
  var m = typeof Symbol === "function" && o[Symbol.iterator];
@@ -23655,7 +24825,7 @@ function setSimulcastInMediaSection(section, trackIdsToAttributes) {
23655
24825
  */
23656
24826
  module.exports = setSimulcastInMediaSection;
23657
24827
 
23658
- },{"../":128}],139:[function(require,module,exports){
24828
+ },{"../":132}],143:[function(require,module,exports){
23659
24829
  'use strict';
23660
24830
  var getMediaSections = require('./').getMediaSections;
23661
24831
  /**
@@ -23700,7 +24870,7 @@ var TrackMatcher = /** @class */ (function () {
23700
24870
  }());
23701
24871
  module.exports = TrackMatcher;
23702
24872
 
23703
- },{"./":136}],140:[function(require,module,exports){
24873
+ },{"./":140}],144:[function(require,module,exports){
23704
24874
  var SID_CHARS = '1234567890abcdef';
23705
24875
  var SID_CHAR_LENGTH = 32;
23706
24876
  // copied from: https://code.hq.twilio.com/flex/monkey/blob/0fdce2b6c52d6be0b17a5cdb92f0c54f119b8ea8/src/client/lib/sid.ts#L39
@@ -23719,7 +24889,7 @@ function createSID(prefix) {
23719
24889
  exports.sessionSID = createSID('SS');
23720
24890
  exports.createSID = createSID;
23721
24891
 
23722
- },{}],141:[function(require,module,exports){
24892
+ },{}],145:[function(require,module,exports){
23723
24893
  'use strict';
23724
24894
  var _a = require('../webrtc/util'), guessBrowser = _a.guessBrowser, isWebRTCSupported = _a.support;
23725
24895
  var getSdpFormat = require('../webrtc/util/sdp').getSdpFormat;
@@ -23766,7 +24936,7 @@ function isSupported() {
23766
24936
  }
23767
24937
  module.exports = isSupported;
23768
24938
 
23769
- },{"../webrtc/util":167,"../webrtc/util/sdp":169,"./browserdetection":120}],142:[function(require,module,exports){
24939
+ },{"../webrtc/util":171,"../webrtc/util/sdp":173,"./browserdetection":124}],146:[function(require,module,exports){
23770
24940
  'use strict';
23771
24941
  /**
23772
24942
  * A {@link Timeout} represents a resettable and clearable timeout.
@@ -23861,7 +25031,7 @@ var Timeout = /** @class */ (function () {
23861
25031
  }());
23862
25032
  module.exports = Timeout;
23863
25033
 
23864
- },{}],143:[function(require,module,exports){
25034
+ },{}],147:[function(require,module,exports){
23865
25035
  // NOTE: Do not edit this file. This code is auto-generated. Contact the
23866
25036
  // Twilio SDK Team for more information.
23867
25037
  'use strict';
@@ -24885,7 +26055,7 @@ var ConfigurationAcquireTurnFailedError = /** @class */ (function (_super) {
24885
26055
  exports.ConfigurationAcquireTurnFailedError = ConfigurationAcquireTurnFailedError;
24886
26056
  Object.defineProperty(TwilioErrorByCode, 53501, { value: ConfigurationAcquireTurnFailedError });
24887
26057
 
24888
- },{"./twilioerror":144}],144:[function(require,module,exports){
26058
+ },{"./twilioerror":148}],148:[function(require,module,exports){
24889
26059
  'use strict';
24890
26060
  var __extends = (this && this.__extends) || (function () {
24891
26061
  var extendStatics = function (d, b) {
@@ -24967,7 +26137,7 @@ var TwilioError = /** @class */ (function (_super) {
24967
26137
  }(Error));
24968
26138
  module.exports = TwilioError;
24969
26139
 
24970
- },{}],145:[function(require,module,exports){
26140
+ },{}],149:[function(require,module,exports){
24971
26141
  'use strict';
24972
26142
  /**
24973
26143
  * @private
@@ -24980,13 +26150,13 @@ var TwilioWarning = {
24980
26150
  };
24981
26151
  module.exports = TwilioWarning;
24982
26152
 
24983
- },{}],146:[function(require,module,exports){
26153
+ },{}],150:[function(require,module,exports){
24984
26154
  'use strict';
24985
26155
  var isNonArrayObject = require('./').isNonArrayObject;
24986
26156
  var _a = require('./constants'), E = _a.typeErrors, clientTrackSwitchOffControl = _a.clientTrackSwitchOffControl, videoContentPreferencesMode = _a.videoContentPreferencesMode, subscriptionMode = _a.subscriptionMode, trackPriority = _a.trackPriority, trackSwitchOffMode = _a.trackSwitchOffMode;
24987
26157
  /**
24988
- * Validate the {@link BandwidthProfileOptions} object.
24989
- * @param {BandwidthProfileOptions} bandwidthProfile
26158
+ * Validate the {@link BandwidthProfile} object.
26159
+ * @param {BandwidthProfile} bandwidthProfile
24990
26160
  * @returns {?Error} - null if valid, Error if not.
24991
26161
  */
24992
26162
  function validateBandwidthProfile(bandwidthProfile) {
@@ -24999,6 +26169,7 @@ function validateBandwidthProfile(bandwidthProfile) {
24999
26169
  { prop: 'dominantSpeakerPriority', values: Object.values(trackPriority) },
25000
26170
  { prop: 'maxSubscriptionBitrate', type: 'number' },
25001
26171
  { prop: 'maxTracks', type: 'number' },
26172
+ { prop: 'maxSwitchedOnTracks', type: 'number' },
25002
26173
  { prop: 'mode', values: Object.values(subscriptionMode) },
25003
26174
  { prop: 'clientTrackSwitchOffControl', values: Object.values(clientTrackSwitchOffControl) },
25004
26175
  { prop: 'trackSwitchOffMode', values: Object.values(trackSwitchOffMode) }
@@ -25006,6 +26177,9 @@ function validateBandwidthProfile(bandwidthProfile) {
25006
26177
  if (error) {
25007
26178
  return error;
25008
26179
  }
26180
+ error = validateObject(bandwidthProfile.audio, 'options.bandwidthProfile.audio', [
26181
+ { prop: 'maxSwitchedOnTracks', type: 'number' }
26182
+ ]);
25009
26183
  if (bandwidthProfile.video) {
25010
26184
  // maxTracks is replaced by clientTrackSwitchOffControl.
25011
26185
  // throw an error if both are specified.
@@ -25017,6 +26191,10 @@ function validateBandwidthProfile(bandwidthProfile) {
25017
26191
  if ('renderDimensions' in bandwidthProfile.video && 'contentPreferencesMode' in bandwidthProfile.video) {
25018
26192
  return new TypeError('options.bandwidthProfile.video.renderDimensions is deprecated. Use options.bandwidthProfile.video.contentPreferencesMode instead.');
25019
26193
  }
26194
+ // maxSwitchedOnTracks and maxTracks are mutually exclusive.
26195
+ if ('maxSwitchedOnTracks' in bandwidthProfile.video && 'maxTracks' in bandwidthProfile.video) {
26196
+ return new TypeError('options.bandwidthProfile.video.maxTracks is deprecated. Use options.bandwidthProfile.video.clientTrackSwitchOffControl instead.');
26197
+ }
25020
26198
  return validateRenderDimensions(bandwidthProfile.video.renderDimensions);
25021
26199
  }
25022
26200
  return null;
@@ -25097,7 +26275,7 @@ exports.validateBandwidthProfile = validateBandwidthProfile;
25097
26275
  exports.validateLocalTrack = validateLocalTrack;
25098
26276
  exports.validateObject = validateObject;
25099
26277
 
25100
- },{"./":128,"./constants":122}],147:[function(require,module,exports){
26278
+ },{"./":132,"./constants":126}],151:[function(require,module,exports){
25101
26279
  /**
25102
26280
  * Copyright (c) 2011-2022 Isaac Z. Schlueter
25103
26281
  * Licensed under the ISC License.
@@ -25132,7 +26310,7 @@ module.exports = function inherits(ctor, superCtor) {
25132
26310
  }
25133
26311
  };
25134
26312
 
25135
- },{}],148:[function(require,module,exports){
26313
+ },{}],152:[function(require,module,exports){
25136
26314
  /**
25137
26315
  * Copyright (c) 2013 Tim Perry
25138
26316
  * Licensed under the MIT license.
@@ -25372,7 +26550,7 @@ defaultLogger.getLoggers = function getLoggers() {
25372
26550
  defaultLogger['default'] = defaultLogger;
25373
26551
  module.exports = defaultLogger;
25374
26552
 
25375
- },{}],149:[function(require,module,exports){
26553
+ },{}],153:[function(require,module,exports){
25376
26554
  /* globals webkitAudioContext, AudioContext */
25377
26555
  'use strict';
25378
26556
  var NativeAudioContext = typeof AudioContext !== 'undefined'
@@ -25455,7 +26633,7 @@ var AudioContextFactory = /** @class */ (function () {
25455
26633
  }());
25456
26634
  module.exports = new AudioContextFactory();
25457
26635
 
25458
- },{}],150:[function(require,module,exports){
26636
+ },{}],154:[function(require,module,exports){
25459
26637
  'use strict';
25460
26638
  /**
25461
26639
  * Return a Promise that resolves after `timeout` milliseconds.
@@ -25508,7 +26686,7 @@ function detectSilence(audioContext, stream, timeout) {
25508
26686
  }
25509
26687
  module.exports = detectSilence;
25510
26688
 
25511
- },{}],151:[function(require,module,exports){
26689
+ },{}],155:[function(require,module,exports){
25512
26690
  'use strict';
25513
26691
  var detectSilence = require('./detectsilence');
25514
26692
  /**
@@ -25578,7 +26756,7 @@ to get a new one, but we\'ve run out of retries; returning it anyway.');
25578
26756
  }
25579
26757
  module.exports = workaround;
25580
26758
 
25581
- },{"./audiocontext":149,"./detectsilence":150}],152:[function(require,module,exports){
26759
+ },{"./audiocontext":153,"./detectsilence":154}],156:[function(require,module,exports){
25582
26760
  'use strict';
25583
26761
  var flatMap = require('./util').flatMap;
25584
26762
  var guessBrowser = require('./util').guessBrowser;
@@ -25635,7 +26813,6 @@ function _getStats(peerConnection, options) {
25635
26813
  isRemote: isRemote
25636
26814
  }, options)).then(function (trackStatsArray) {
25637
26815
  trackStatsArray.forEach(function (trackStats) {
25638
- trackStats.trackId = track.id;
25639
26816
  statsResponse[statsArrayName].push(trackStats);
25640
26817
  });
25641
26818
  });
@@ -25896,7 +27073,7 @@ function chromeOrSafariGetTrackStats(peerConnection, track) {
25896
27073
  return;
25897
27074
  }
25898
27075
  peerConnection.getStats(track).then(function (response) {
25899
- resolve(standardizeChromeOrSafariStats(response));
27076
+ resolve(standardizeChromeOrSafariStats(response, track));
25900
27077
  }, reject);
25901
27078
  });
25902
27079
  }
@@ -25910,7 +27087,7 @@ function chromeOrSafariGetTrackStats(peerConnection, track) {
25910
27087
  function firefoxGetTrackStats(peerConnection, track, isRemote) {
25911
27088
  return new Promise(function (resolve, reject) {
25912
27089
  peerConnection.getStats(track).then(function (response) {
25913
- resolve([standardizeFirefoxStats(response, isRemote)]);
27090
+ resolve([standardizeFirefoxStats(response, track, isRemote)]);
25914
27091
  }, reject);
25915
27092
  });
25916
27093
  }
@@ -25924,7 +27101,7 @@ function standardizeChromeLegacyStats(response, track) {
25924
27101
  var ssrcReport = response.result().find(function (report) {
25925
27102
  return report.type === 'ssrc' && report.stat('googTrackId') === track.id;
25926
27103
  });
25927
- var standardizedStats = {};
27104
+ var standardizedStats = { trackId: track.id };
25928
27105
  if (ssrcReport) {
25929
27106
  standardizedStats.timestamp = Math.round(Number(ssrcReport.timestamp));
25930
27107
  standardizedStats = ssrcReport.names().reduce(function (stats, name) {
@@ -25986,9 +27163,10 @@ function standardizeChromeLegacyStats(response, track) {
25986
27163
  /**
25987
27164
  * Standardize the MediaStreamTrack's statistics in Chrome or Safari.
25988
27165
  * @param {RTCStatsResponse} response
27166
+ * @param {MediaStreamTrack} track
25989
27167
  * @returns {Array<StandardizedTrackStatsReport>}
25990
27168
  */
25991
- function standardizeChromeOrSafariStats(response) {
27169
+ function standardizeChromeOrSafariStats(response, mediaStreamTrack) {
25992
27170
  var inbound = null;
25993
27171
  // NOTE(mpatwardhan): We should expect more than one "outbound-rtp" stats for a
25994
27172
  // VP8 simulcast MediaStreamTrack.
@@ -26028,7 +27206,7 @@ function standardizeChromeOrSafariStats(response) {
26028
27206
  var stats = [];
26029
27207
  var remoteSource = isRemote ? remoteOutbound : remoteInbound; // remote rtp stats
26030
27208
  mainSources.forEach(function (source) {
26031
- var standardizedStats = {};
27209
+ var standardizedStats = { trackId: mediaStreamTrack.id };
26032
27210
  var statSources = [
26033
27211
  source,
26034
27212
  localMedia,
@@ -26154,10 +27332,11 @@ function standardizeChromeOrSafariStats(response) {
26154
27332
  /**
26155
27333
  * Standardize the MediaStreamTrack's statistics in Firefox.
26156
27334
  * @param {RTCStatsReport} response
27335
+ * @param {MediaStreamTrack} track
26157
27336
  * @param {boolean} isRemote
26158
27337
  * @returns {StandardizedTrackStatsReport}
26159
27338
  */
26160
- function standardizeFirefoxStats(response, isRemote) {
27339
+ function standardizeFirefoxStats(response, track, isRemote) {
26161
27340
  // NOTE(mroberts): If getStats is called on a closed RTCPeerConnection,
26162
27341
  // Firefox returns undefined instead of an RTCStatsReport. We workaround this
26163
27342
  // here. See the following bug for more details:
@@ -26202,7 +27381,7 @@ function standardizeFirefoxStats(response, isRemote) {
26202
27381
  }
26203
27382
  return null;
26204
27383
  }
26205
- var standardizedStats = {};
27384
+ var standardizedStats = { trackId: track.id };
26206
27385
  var timestamp = getStatValue('timestamp');
26207
27386
  standardizedStats.timestamp = Math.round(timestamp);
26208
27387
  var ssrc = getStatValue('ssrc');
@@ -26370,9 +27549,10 @@ function standardizeFirefoxStats(response, isRemote) {
26370
27549
  * @property {AudioLevel} [audioInputLevel] - The {@link AudioLevel} of the local audio MediaStreamTrack
26371
27550
  * @property {AudioLevel} [audioOutputLevel] - The {@link AudioLevel} of the remote video MediaStreamTrack
26372
27551
  */
26373
- module.exports = getStats;
27552
+ exports.getStats = getStats;
27553
+ exports.getTrackStats = getTrackStats;
26374
27554
 
26375
- },{"./util":167,"./util/sdp":169}],153:[function(require,module,exports){
27555
+ },{"./util":171,"./util/sdp":173}],157:[function(require,module,exports){
26376
27556
  /* globals navigator */
26377
27557
  'use strict';
26378
27558
  /**
@@ -26396,13 +27576,18 @@ function getUserMedia(constraints) {
26396
27576
  }
26397
27577
  module.exports = getUserMedia;
26398
27578
 
26399
- },{}],154:[function(require,module,exports){
27579
+ },{}],158:[function(require,module,exports){
26400
27580
  'use strict';
27581
+ var stats = require('./getstats');
26401
27582
  var WebRTC = {};
26402
27583
  Object.defineProperties(WebRTC, {
26403
27584
  getStats: {
26404
27585
  enumerable: true,
26405
- value: require('./getstats')
27586
+ value: stats.getStats
27587
+ },
27588
+ getTrackStats: {
27589
+ enumerable: true,
27590
+ value: stats.getTrackStats
26406
27591
  },
26407
27592
  getUserMedia: {
26408
27593
  enumerable: true,
@@ -26431,7 +27616,7 @@ Object.defineProperties(WebRTC, {
26431
27616
  });
26432
27617
  module.exports = WebRTC;
26433
27618
 
26434
- },{"./getstats":152,"./getusermedia":153,"./mediastream":155,"./mediastreamtrack":156,"./rtcicecandidate":157,"./rtcpeerconnection":160,"./rtcsessiondescription":165}],155:[function(require,module,exports){
27619
+ },{"./getstats":156,"./getusermedia":157,"./mediastream":159,"./mediastreamtrack":160,"./rtcicecandidate":161,"./rtcpeerconnection":164,"./rtcsessiondescription":169}],159:[function(require,module,exports){
26435
27620
  /* globals MediaStream */
26436
27621
  'use strict';
26437
27622
  if (typeof MediaStream === 'function') {
@@ -26443,7 +27628,7 @@ else {
26443
27628
  };
26444
27629
  }
26445
27630
 
26446
- },{}],156:[function(require,module,exports){
27631
+ },{}],160:[function(require,module,exports){
26447
27632
  /* global MediaStreamTrack */
26448
27633
  'use strict';
26449
27634
  if (typeof MediaStreamTrack === 'function') {
@@ -26455,7 +27640,7 @@ else {
26455
27640
  };
26456
27641
  }
26457
27642
 
26458
- },{}],157:[function(require,module,exports){
27643
+ },{}],161:[function(require,module,exports){
26459
27644
  /* global RTCIceCandidate */
26460
27645
  'use strict';
26461
27646
  if (typeof RTCIceCandidate === 'function') {
@@ -26467,7 +27652,7 @@ else {
26467
27652
  };
26468
27653
  }
26469
27654
 
26470
- },{}],158:[function(require,module,exports){
27655
+ },{}],162:[function(require,module,exports){
26471
27656
  /* globals RTCDataChannel, RTCPeerConnection, RTCSessionDescription */
26472
27657
  'use strict';
26473
27658
  var ChromeRTCSessionDescription = require('../rtcsessiondescription/chrome');
@@ -26978,7 +28163,7 @@ function updateTrackIdsToSSRCs(sdpFormat, tracksToSSRCs, sdp) {
26978
28163
  }
26979
28164
  module.exports = ChromeRTCPeerConnection;
26980
28165
 
26981
- },{"../../vendor/inherits":147,"../mediastream":155,"../rtcrtpsender":162,"../rtcsessiondescription/chrome":163,"../util":167,"../util/eventtarget":166,"../util/latch":168,"../util/sdp":169}],159:[function(require,module,exports){
28166
+ },{"../../vendor/inherits":151,"../mediastream":159,"../rtcrtpsender":166,"../rtcsessiondescription/chrome":167,"../util":171,"../util/eventtarget":170,"../util/latch":172,"../util/sdp":173}],163:[function(require,module,exports){
26982
28167
  /* globals RTCPeerConnection */
26983
28168
  'use strict';
26984
28169
  var EventTarget = require('../util/eventtarget');
@@ -27273,7 +28458,7 @@ function overwriteWithInitiallyNegotiatedDtlsRole(description, dtlsRole) {
27273
28458
  }
27274
28459
  module.exports = FirefoxRTCPeerConnection;
27275
28460
 
27276
- },{"../../vendor/inherits":147,"../rtcsessiondescription/firefox":164,"../util":167,"../util/eventtarget":166,"../util/sdp":169}],160:[function(require,module,exports){
28461
+ },{"../../vendor/inherits":151,"../rtcsessiondescription/firefox":168,"../util":171,"../util/eventtarget":170,"../util/sdp":173}],164:[function(require,module,exports){
27277
28462
  'use strict';
27278
28463
  if (typeof RTCPeerConnection === 'function') {
27279
28464
  var guessBrowser = require('../util').guessBrowser;
@@ -27298,7 +28483,7 @@ else {
27298
28483
  };
27299
28484
  }
27300
28485
 
27301
- },{"../util":167,"./chrome":158,"./firefox":159,"./safari":161}],161:[function(require,module,exports){
28486
+ },{"../util":171,"./chrome":162,"./firefox":163,"./safari":165}],165:[function(require,module,exports){
27302
28487
  /* globals RTCPeerConnection, RTCSessionDescription */
27303
28488
  'use strict';
27304
28489
  var EventTarget = require('../util/eventtarget');
@@ -27647,7 +28832,7 @@ function shimDataChannel(dataChannel) {
27647
28832
  }
27648
28833
  module.exports = SafariRTCPeerConnection;
27649
28834
 
27650
- },{"../../vendor/inherits":147,"../util":167,"../util/eventtarget":166,"../util/latch":168,"../util/sdp":169}],162:[function(require,module,exports){
28835
+ },{"../../vendor/inherits":151,"../util":171,"../util/eventtarget":170,"../util/latch":172,"../util/sdp":173}],166:[function(require,module,exports){
27651
28836
  'use strict';
27652
28837
  /**
27653
28838
  * RTCRtpSender shim.
@@ -27685,7 +28870,7 @@ function RTCRtpSenderShim(track) {
27685
28870
  // using the RTCRtpSender APIs.
27686
28871
  module.exports = RTCRtpSenderShim;
27687
28872
 
27688
- },{}],163:[function(require,module,exports){
28873
+ },{}],167:[function(require,module,exports){
27689
28874
  /* globals RTCSessionDescription */
27690
28875
  'use strict';
27691
28876
  // This class wraps Chrome's RTCSessionDescription implementation. It provides
@@ -27722,12 +28907,12 @@ function ChromeRTCSessionDescription(descriptionInitDict) {
27722
28907
  }
27723
28908
  module.exports = ChromeRTCSessionDescription;
27724
28909
 
27725
- },{}],164:[function(require,module,exports){
28910
+ },{}],168:[function(require,module,exports){
27726
28911
  /* globals RTCSessionDescription */
27727
28912
  'use strict';
27728
28913
  module.exports = RTCSessionDescription;
27729
28914
 
27730
- },{}],165:[function(require,module,exports){
28915
+ },{}],169:[function(require,module,exports){
27731
28916
  /* globals RTCSessionDescription */
27732
28917
  'use strict';
27733
28918
  if (typeof RTCSessionDescription === 'function') {
@@ -27750,7 +28935,7 @@ else {
27750
28935
  };
27751
28936
  }
27752
28937
 
27753
- },{"../util":167,"./chrome":163,"./firefox":164}],166:[function(require,module,exports){
28938
+ },{"../util":171,"./chrome":167,"./firefox":168}],170:[function(require,module,exports){
27754
28939
  'use strict';
27755
28940
  var EventEmitter = require('events').EventEmitter;
27756
28941
  /**
@@ -27785,7 +28970,7 @@ EventTarget.prototype.removeEventListener = function removeEventListener() {
27785
28970
  };
27786
28971
  module.exports = EventTarget;
27787
28972
 
27788
- },{"events":170}],167:[function(require,module,exports){
28973
+ },{"events":174}],171:[function(require,module,exports){
27789
28974
  'use strict';
27790
28975
  /**
27791
28976
  * Create a {@link Deferred}.
@@ -28094,7 +29279,7 @@ exports.makeUUID = makeUUID;
28094
29279
  exports.proxyProperties = proxyProperties;
28095
29280
  exports.support = support;
28096
29281
 
28097
- },{}],168:[function(require,module,exports){
29282
+ },{}],172:[function(require,module,exports){
28098
29283
  'use strict';
28099
29284
  var defer = require('./').defer;
28100
29285
  var states = {
@@ -28200,7 +29385,7 @@ function createUnreachableStateError(from, to) {
28200
29385
  }
28201
29386
  module.exports = Latch;
28202
29387
 
28203
- },{"./":167}],169:[function(require,module,exports){
29388
+ },{"./":171}],173:[function(require,module,exports){
28204
29389
  /* globals RTCPeerConnection, RTCRtpTransceiver */
28205
29390
  'use strict';
28206
29391
  var flatMap = require('./').flatMap;
@@ -28494,7 +29679,7 @@ exports.getUnifiedPlanSSRCs = getUnifiedPlanSSRCs;
28494
29679
  exports.updatePlanBTrackIdsToSSRCs = updatePlanBTrackIdsToSSRCs;
28495
29680
  exports.updateUnifiedPlanTrackIdsToSSRCs = updateUnifiedPlanTrackIdsToSSRCs;
28496
29681
 
28497
- },{"./":167}],170:[function(require,module,exports){
29682
+ },{"./":171}],174:[function(require,module,exports){
28498
29683
  // Copyright Joyent, Inc. and other Node contributors.
28499
29684
  //
28500
29685
  // Permission is hereby granted, free of charge, to any person obtaining a
@@ -28993,18 +30178,20 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
28993
30178
  }
28994
30179
  }
28995
30180
 
28996
- },{}],171:[function(require,module,exports){
30181
+ },{}],175:[function(require,module,exports){
28997
30182
  module.exports={
28998
30183
  "name": "twilio-video",
28999
30184
  "title": "Twilio Video",
29000
30185
  "description": "Twilio Video JavaScript Library",
29001
- "version": "2.22.2",
30186
+ "version": "3.0.0-preview.2",
29002
30187
  "homepage": "https://twilio.com",
29003
30188
  "author": "Mark Andrus Roberts <mroberts@twilio.com>",
29004
30189
  "contributors": [
29005
30190
  "Ryan Rowland <rrowland@twilio.com>",
29006
30191
  "Manjesh Malavalli <mmalavalli@twilio.com>",
29007
- "Makarand Patwardhan <mpatwardhan@twilio.com>"
30192
+ "Makarand Patwardhan <mpatwardhan@twilio.com>",
30193
+ "Charlemegne Santos <csantos@twilio.com>",
30194
+ "Joyce Ma <joma@twilio.com>"
29008
30195
  ],
29009
30196
  "keywords": [
29010
30197
  "twilio",
@@ -29152,7 +30339,7 @@ module.exports={
29152
30339
  }
29153
30340
  }
29154
30341
 
29155
- },{}],172:[function(require,module,exports){
30342
+ },{}],176:[function(require,module,exports){
29156
30343
  module.exports = WebSocket;
29157
30344
 
29158
30345
  },{}]},{},[11]);