livekit-client 0.18.4-RC5 → 0.18.4-RC8

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.
@@ -5024,7 +5024,8 @@ function createBaseParticipantInfo() {
5024
5024
  name: '',
5025
5025
  version: 0,
5026
5026
  permission: undefined,
5027
- region: ''
5027
+ region: '',
5028
+ isPublisher: false
5028
5029
  };
5029
5030
  }
5030
5031
 
@@ -5072,6 +5073,10 @@ const ParticipantInfo = {
5072
5073
  writer.uint32(98).string(message.region);
5073
5074
  }
5074
5075
 
5076
+ if (message.isPublisher === true) {
5077
+ writer.uint32(104).bool(message.isPublisher);
5078
+ }
5079
+
5075
5080
  return writer;
5076
5081
  },
5077
5082
 
@@ -5124,6 +5129,10 @@ const ParticipantInfo = {
5124
5129
  message.region = reader.string();
5125
5130
  break;
5126
5131
 
5132
+ case 13:
5133
+ message.isPublisher = reader.bool();
5134
+ break;
5135
+
5127
5136
  default:
5128
5137
  reader.skipType(tag & 7);
5129
5138
  break;
@@ -5144,7 +5153,8 @@ const ParticipantInfo = {
5144
5153
  name: isSet$1(object.name) ? String(object.name) : '',
5145
5154
  version: isSet$1(object.version) ? Number(object.version) : 0,
5146
5155
  permission: isSet$1(object.permission) ? ParticipantPermission.fromJSON(object.permission) : undefined,
5147
- region: isSet$1(object.region) ? String(object.region) : ''
5156
+ region: isSet$1(object.region) ? String(object.region) : '',
5157
+ isPublisher: isSet$1(object.isPublisher) ? Boolean(object.isPublisher) : false
5148
5158
  };
5149
5159
  },
5150
5160
 
@@ -5166,11 +5176,12 @@ const ParticipantInfo = {
5166
5176
  message.version !== undefined && (obj.version = Math.round(message.version));
5167
5177
  message.permission !== undefined && (obj.permission = message.permission ? ParticipantPermission.toJSON(message.permission) : undefined);
5168
5178
  message.region !== undefined && (obj.region = message.region);
5179
+ message.isPublisher !== undefined && (obj.isPublisher = message.isPublisher);
5169
5180
  return obj;
5170
5181
  },
5171
5182
 
5172
5183
  fromPartial(object) {
5173
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
5184
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
5174
5185
 
5175
5186
  const message = createBaseParticipantInfo();
5176
5187
  message.sid = (_a = object.sid) !== null && _a !== void 0 ? _a : '';
@@ -5183,6 +5194,7 @@ const ParticipantInfo = {
5183
5194
  message.version = (_h = object.version) !== null && _h !== void 0 ? _h : 0;
5184
5195
  message.permission = object.permission !== undefined && object.permission !== null ? ParticipantPermission.fromPartial(object.permission) : undefined;
5185
5196
  message.region = (_j = object.region) !== null && _j !== void 0 ? _j : '';
5197
+ message.isPublisher = (_k = object.isPublisher) !== null && _k !== void 0 ? _k : false;
5186
5198
  return message;
5187
5199
  }
5188
5200
 
@@ -6231,11 +6243,9 @@ const btoa = globalThis$1.btoa || (bin => globalThis$1.Buffer.from(bin, 'binary'
6231
6243
 
6232
6244
  function base64FromBytes(arr) {
6233
6245
  const bin = [];
6234
-
6235
- for (const byte of arr) {
6246
+ arr.forEach(byte => {
6236
6247
  bin.push(String.fromCharCode(byte));
6237
- }
6238
-
6248
+ });
6239
6249
  return btoa(bin.join(''));
6240
6250
  }
6241
6251
 
@@ -8585,7 +8595,8 @@ function createBaseTrackPermission() {
8585
8595
  return {
8586
8596
  participantSid: '',
8587
8597
  allTracks: false,
8588
- trackSids: []
8598
+ trackSids: [],
8599
+ participantIdentity: ''
8589
8600
  };
8590
8601
  }
8591
8602
 
@@ -8605,6 +8616,10 @@ const TrackPermission = {
8605
8616
  writer.uint32(26).string(v);
8606
8617
  }
8607
8618
 
8619
+ if (message.participantIdentity !== '') {
8620
+ writer.uint32(34).string(message.participantIdentity);
8621
+ }
8622
+
8608
8623
  return writer;
8609
8624
  },
8610
8625
 
@@ -8629,6 +8644,10 @@ const TrackPermission = {
8629
8644
  message.trackSids.push(reader.string());
8630
8645
  break;
8631
8646
 
8647
+ case 4:
8648
+ message.participantIdentity = reader.string();
8649
+ break;
8650
+
8632
8651
  default:
8633
8652
  reader.skipType(tag & 7);
8634
8653
  break;
@@ -8642,7 +8661,8 @@ const TrackPermission = {
8642
8661
  return {
8643
8662
  participantSid: isSet(object.participantSid) ? String(object.participantSid) : '',
8644
8663
  allTracks: isSet(object.allTracks) ? Boolean(object.allTracks) : false,
8645
- trackSids: Array.isArray(object === null || object === void 0 ? void 0 : object.trackSids) ? object.trackSids.map(e => String(e)) : []
8664
+ trackSids: Array.isArray(object === null || object === void 0 ? void 0 : object.trackSids) ? object.trackSids.map(e => String(e)) : [],
8665
+ participantIdentity: isSet(object.participantIdentity) ? String(object.participantIdentity) : ''
8646
8666
  };
8647
8667
  },
8648
8668
 
@@ -8657,16 +8677,18 @@ const TrackPermission = {
8657
8677
  obj.trackSids = [];
8658
8678
  }
8659
8679
 
8680
+ message.participantIdentity !== undefined && (obj.participantIdentity = message.participantIdentity);
8660
8681
  return obj;
8661
8682
  },
8662
8683
 
8663
8684
  fromPartial(object) {
8664
- var _a, _b, _c;
8685
+ var _a, _b, _c, _d;
8665
8686
 
8666
8687
  const message = createBaseTrackPermission();
8667
8688
  message.participantSid = (_a = object.participantSid) !== null && _a !== void 0 ? _a : '';
8668
8689
  message.allTracks = (_b = object.allTracks) !== null && _b !== void 0 ? _b : false;
8669
8690
  message.trackSids = ((_c = object.trackSids) === null || _c === void 0 ? void 0 : _c.map(e => e)) || [];
8691
+ message.participantIdentity = (_d = object.participantIdentity) !== null && _d !== void 0 ? _d : '';
8670
8692
  return message;
8671
8693
  }
8672
8694
 
@@ -9826,24 +9848,47 @@ function getClientInfo() {
9826
9848
  });
9827
9849
  return info;
9828
9850
  }
9829
- let emptyMediaStreamTrack;
9830
- function getEmptyMediaStreamTrack() {
9831
- if (!emptyMediaStreamTrack) {
9851
+ let emptyVideoStreamTrack;
9852
+ function getEmptyVideoStreamTrack() {
9853
+ var _a;
9854
+
9855
+ if (!emptyVideoStreamTrack) {
9832
9856
  const canvas = document.createElement('canvas');
9833
9857
  canvas.width = 2;
9834
- canvas.height = 2; // @ts-ignore
9858
+ canvas.height = 2;
9859
+ (_a = canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.fillRect(0, 0, canvas.width, canvas.height); // @ts-ignore
9835
9860
 
9836
9861
  const emptyStream = canvas.captureStream();
9837
- [emptyMediaStreamTrack] = emptyStream.getTracks();
9862
+ [emptyVideoStreamTrack] = emptyStream.getTracks();
9863
+
9864
+ if (!emptyVideoStreamTrack) {
9865
+ throw Error('Could not get empty media stream video track');
9866
+ }
9867
+
9868
+ emptyVideoStreamTrack.enabled = false;
9869
+ }
9838
9870
 
9839
- if (!emptyMediaStreamTrack) {
9840
- throw Error('Could not get empty media stream track');
9871
+ return emptyVideoStreamTrack;
9872
+ }
9873
+ let emptyAudioStreamTrack;
9874
+ function getEmptyAudioStreamTrack() {
9875
+ if (!emptyAudioStreamTrack) {
9876
+ // implementation adapted from https://blog.mozilla.org/webrtc/warm-up-with-replacetrack/
9877
+ const ctx = new AudioContext();
9878
+ const oscillator = ctx.createOscillator();
9879
+ const dst = ctx.createMediaStreamDestination();
9880
+ oscillator.connect(dst);
9881
+ oscillator.start();
9882
+ [emptyAudioStreamTrack] = dst.stream.getAudioTracks();
9883
+
9884
+ if (!emptyAudioStreamTrack) {
9885
+ throw Error('Could not get empty media stream audio track');
9841
9886
  }
9842
9887
 
9843
- emptyMediaStreamTrack.enabled = false;
9888
+ emptyAudioStreamTrack.enabled = false;
9844
9889
  }
9845
9890
 
9846
- return emptyMediaStreamTrack;
9891
+ return emptyAudioStreamTrack;
9847
9892
  }
9848
9893
 
9849
9894
  var events = {exports: {}};
@@ -10818,7 +10863,8 @@ class LocalTrack extends Track {
10818
10863
 
10819
10864
  this._isUpstreamPaused = true;
10820
10865
  this.emit(TrackEvent.UpstreamPaused, this);
10821
- await this.sender.replaceTrack(getEmptyMediaStreamTrack());
10866
+ const emptyTrack = this.kind === Track.Kind.Audio ? getEmptyAudioStreamTrack() : getEmptyVideoStreamTrack();
10867
+ await this.sender.replaceTrack(emptyTrack);
10822
10868
  }
10823
10869
 
10824
10870
  async resumeUpstream() {
@@ -11617,6 +11663,10 @@ class RemoteVideoTrack extends RemoteTrack {
11617
11663
  this.updateDimensions();
11618
11664
  }, REACTION_DELAY);
11619
11665
  this.adaptiveStreamSettings = adaptiveStreamSettings;
11666
+
11667
+ if (this.isAdaptiveStream) {
11668
+ this.streamState = Track.StreamState.Paused;
11669
+ }
11620
11670
  }
11621
11671
 
11622
11672
  get isAdaptiveStream() {
@@ -12313,15 +12363,16 @@ class Participant extends events.exports.EventEmitter {
12313
12363
  }
12314
12364
 
12315
12365
  function trackPermissionToProto(perms) {
12316
- var _a;
12366
+ var _a, _b, _c;
12317
12367
 
12318
- if (!perms.participantSid) {
12319
- throw new Error('Invalid track permission, missing participantSid');
12368
+ if (!perms.participantSid && !perms.participantIdentity) {
12369
+ throw new Error('Invalid track permission, must provide at least one of participantIdentity and participantSid');
12320
12370
  }
12321
12371
 
12322
12372
  return {
12323
- participantSid: perms.participantSid,
12324
- allTracks: (_a = perms.allowAll) !== null && _a !== void 0 ? _a : false,
12373
+ participantIdentity: (_a = perms.participantIdentity) !== null && _a !== void 0 ? _a : '',
12374
+ participantSid: (_b = perms.participantSid) !== null && _b !== void 0 ? _b : '',
12375
+ allTracks: (_c = perms.allowAll) !== null && _c !== void 0 ? _c : false,
12325
12376
  trackSids: perms.allowedTrackSids || []
12326
12377
  };
12327
12378
  }
@@ -18074,9 +18125,11 @@ class RTCEngine extends events.exports.EventEmitter {
18074
18125
  };
18075
18126
 
18076
18127
  let primaryPC = this.publisher.pc;
18128
+ let secondaryPC = this.subscriber.pc;
18077
18129
 
18078
18130
  if (joinResponse.subscriberPrimary) {
18079
- primaryPC = this.subscriber.pc; // in subscriber primary mode, server side opens sub data channels.
18131
+ primaryPC = this.subscriber.pc;
18132
+ secondaryPC = this.publisher.pc; // in subscriber primary mode, server side opens sub data channels.
18080
18133
 
18081
18134
  this.subscriber.pc.ondatachannel = this.handleDataChannel;
18082
18135
  }
@@ -18107,11 +18160,18 @@ class RTCEngine extends events.exports.EventEmitter {
18107
18160
  // on Safari, PeerConnection will switch to 'disconnected' during renegotiation
18108
18161
  if (this.pcState === PCState.Connected) {
18109
18162
  this.pcState = PCState.Disconnected;
18110
- this.handleDisconnect('peerconnection');
18163
+ this.handleDisconnect('primary peerconnection');
18111
18164
  }
18112
18165
  }
18113
18166
  };
18114
18167
 
18168
+ secondaryPC.onconnectionstatechange = async () => {
18169
+ // also reconnect if secondary peerconnection fails
18170
+ if (secondaryPC.connectionState === 'failed') {
18171
+ this.handleDisconnect('secondary peerconnection');
18172
+ }
18173
+ };
18174
+
18115
18175
  if (isWeb()) {
18116
18176
  this.subscriber.pc.ontrack = ev => {
18117
18177
  this.emit(EngineEvent.MediaTrackAdded, ev.track, ev.streams[0], ev.receiver);