@livedigital/client 2.21.0-update-app-data.1 → 2.21.0

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.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@livedigital/client",
3
3
  "author": "vlprojects",
4
4
  "license": "MIT",
5
- "version": "2.21.0-update-app-data.1",
5
+ "version": "2.21.0",
6
6
  "private": false,
7
7
  "bugs": {
8
8
  "url": "https://github.com/vlprojects/livedigital-sdk/issues"
@@ -12,7 +12,7 @@ export const LogLevels = {
12
12
  Debug: LOG_LEVEL_DEBUG,
13
13
  };
14
14
 
15
- export const CONSUMER_CHECK_STATE_TIMEOUT = 5000;
15
+ export const CONSUMER_CHECK_STATE_TIMEOUT = 4500;
16
16
  export const PRODUCER_CHECK_STATE_TIMEOUT = 3000;
17
17
 
18
18
  export const PEER_APP_DATA_MAX_SIZE_BYTES = 1024;
@@ -58,6 +58,7 @@ export const MEDIASOUP_EVENTS = {
58
58
  resumeConsumer: 'consumer.resume',
59
59
  consumerScoreChanged: 'consumer.scoreChanged',
60
60
  consumerChangePreferredLayers: 'consumer.changeConsumerPreferredLayers',
61
+ consumerRequestKeyFrame: 'consumer.requestKeyFrame',
61
62
  setConsumerPriority: 'consumer.setConsumerPriority',
62
63
  transportCreate: 'transport.create',
63
64
  transportClose: 'transport.close',
@@ -131,7 +131,7 @@ class Peer {
131
131
  return;
132
132
  }
133
133
 
134
- const { isProducerPaused, consumer } = await this.engine.network.createConsumer({
134
+ const { consumer } = await this.engine.network.createConsumer({
135
135
  producerId: producer.id,
136
136
  rtpCapabilities: this.engine.media.mediasoupDevice.rtpCapabilities,
137
137
  producerPeerId: this.id,
@@ -148,10 +148,7 @@ class Peer {
148
148
  peerEventEmitter: this.observer,
149
149
  });
150
150
 
151
- if (!isProducerPaused) {
152
- await track.resume();
153
- }
154
-
151
+ await track.resume();
155
152
  this.tracks.set(track.label, track);
156
153
  this.logger.debug(`Subscribed for ${producer.kind}`, { peer: this });
157
154
  } catch (error) {
@@ -172,7 +172,7 @@ class BaseTrack {
172
172
  }
173
173
 
174
174
  this.logger.debug('createSelfConsumer()', { track: this });
175
- const { isProducerPaused, consumer } = await this.#engine.network.createConsumer({
175
+ const { consumer } = await this.#engine.network.createConsumer({
176
176
  producerId: this.producer.id,
177
177
  rtpCapabilities: this.#engine.media.mediasoupDevice.rtpCapabilities,
178
178
  producerPeerId: this.producer.appData.peerId,
@@ -180,10 +180,8 @@ class BaseTrack {
180
180
  channelId: this.#engine.channelId,
181
181
  });
182
182
 
183
- if (!isProducerPaused) {
184
- await this.#engine.network.resumeRemoteConsumer(consumer.id);
185
- }
186
-
183
+ await this.#engine.network.resumeRemoteConsumer(consumer.id);
184
+ consumer.resume();
187
185
  this.#selfConsumer = new PeerConsumer({
188
186
  consumer,
189
187
  logLevel: this.#engine.logLevel,
@@ -1,6 +1,7 @@
1
1
  import { MediaKind } from 'mediasoup-client/lib/types';
2
2
  import {
3
- PreferredLayersParams, SetConsumerPriorityParams,
3
+ PreferredLayersParams,
4
+ SetConsumerPriorityParams,
4
5
  SpatialLayerParams,
5
6
  TrackLabel,
6
7
  } from '../../../types/common';
@@ -116,11 +117,12 @@ class PeerTrack {
116
117
  if (!this.consumer) {
117
118
  this.#paused = false;
118
119
  this.#peerEventEmitter.safeEmit(PEER_EVENTS.trackResumed, this);
120
+ this.#logger.debug('resume()', { track: this, peer: this });
119
121
  return;
120
122
  }
121
123
 
122
124
  if (!this.#paused) {
123
- this.#logger.debug('resume()', { message: 'Already playing', peer: this, consumer: this.consumer });
125
+ this.#logger.debug('resume()', { message: 'Already playing', track: this, peer: this });
124
126
  return;
125
127
  }
126
128
 
@@ -130,7 +132,7 @@ class PeerTrack {
130
132
  this.#paused = false;
131
133
  this.#peerEventEmitter.safeEmit(PEER_EVENTS.trackResumed, this);
132
134
  this.checkConsumerState();
133
- this.#logger.debug('resume()', { peer: this });
135
+ this.#logger.debug('resume()', { track: this, peer: this });
134
136
  } catch (error) {
135
137
  this.#logger.warn('resume()', { error });
136
138
  }
@@ -201,6 +203,28 @@ class PeerTrack {
201
203
  }
202
204
  }
203
205
 
206
+ public async requestKeyFrame(): Promise<void> {
207
+ if (!this.consumerId) {
208
+ return;
209
+ }
210
+
211
+ this.#logger.debug('requestKeyFrame()', { track: this });
212
+
213
+ try {
214
+ await this.#engine.network.socket.request(MEDIASOUP_EVENTS.consumerRequestKeyFrame, {
215
+ consumerId: this.consumerId,
216
+ });
217
+ } catch (error: unknown) {
218
+ this.#logger.error('requestKeyFrame()', {
219
+ error,
220
+ peer: this,
221
+ consumerId: this.consumerId,
222
+ });
223
+
224
+ throw new Error('Failed to request key frame');
225
+ }
226
+ }
227
+
204
228
  public getVideoAvailableLayers(): SpatialLayerParams[] | undefined {
205
229
  if (!this.consumer) {
206
230
  return undefined;
@@ -263,13 +287,21 @@ class PeerTrack {
263
287
 
264
288
  this.#logger.debug('checkConsumerState()', { track: this });
265
289
  const isInboundRTPStreamActive = await this.isInboundRTPStreamActive();
266
- if (this.#consumerRestarted && !isInboundRTPStreamActive) {
267
- this.#peerEventEmitter.emit(PEER_EVENTS.trackFailed, this);
268
- this.#logger.debug('trackFail()', { track: this });
290
+
291
+ if (isInboundRTPStreamActive || this.#closed) {
269
292
  return;
270
293
  }
271
294
 
272
- if (isInboundRTPStreamActive || this.#closed) {
295
+ await this.requestKeyFrame();
296
+ const isActiveAfterKeyFrameRequest = await this.isInboundRTPStreamActive();
297
+
298
+ if (isActiveAfterKeyFrameRequest || this.#closed) {
299
+ return;
300
+ }
301
+
302
+ if (this.#consumerRestarted) {
303
+ this.#peerEventEmitter.emit(PEER_EVENTS.trackFailed, this);
304
+ this.#logger.debug('trackFail()', { track: this });
273
305
  return;
274
306
  }
275
307
 
@@ -302,7 +334,7 @@ class PeerTrack {
302
334
  this.#peerEventEmitter.emit(PEER_EVENTS.trackEnd, this);
303
335
  this.#paused = true;
304
336
  await this.closeConsumer();
305
- const { isProducerPaused, consumer } = await this.#engine.network.createConsumer({
337
+ const { consumer } = await this.#engine.network.createConsumer({
306
338
  producerId: this.consumer.producerId,
307
339
  rtpCapabilities: this.#engine.media.mediasoupDevice.rtpCapabilities,
308
340
  producerPeerId: this.consumer.appData.producerData.peerId,
@@ -314,10 +346,7 @@ class PeerTrack {
314
346
  this.consumer = new PeerConsumer({ consumer, logLevel: this.#engine.logLevel });
315
347
  this.#mediaStreamTrack = consumer.track;
316
348
 
317
- if (!isProducerPaused) {
318
- await this.resume();
319
- }
320
-
349
+ await this.resume();
321
350
  this.#peerEventEmitter.emit(PEER_EVENTS.trackStart, this);
322
351
  } catch (error) {
323
352
  this.#consumerRestarted = true;
@@ -245,11 +245,12 @@ class Network {
245
245
  }) as RemoteConsumerOptions;
246
246
 
247
247
  const consumer = await transport.consume(consumerOptions);
248
- this.logger.debug('Consumer created', { consumer });
248
+ const { producerPaused: isProducerPaused } = consumerOptions;
249
+ this.logger.debug('Consumer created', { consumer, isProducerPaused });
249
250
 
250
251
  return {
251
252
  consumer,
252
- isProducerPaused: consumerOptions.producerPaused,
253
+ isProducerPaused,
253
254
  };
254
255
  }
255
256