@livedigital/client 2.24.0 → 2.24.1

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.
@@ -169,6 +169,10 @@ export declare type PayloadOfPublishedMedia = {
169
169
  kind: MediaKind;
170
170
  label: TrackLabel;
171
171
  };
172
+ export declare type SubscribeOptions = {
173
+ producerId: string;
174
+ paused?: boolean;
175
+ };
172
176
  export declare type PayloadOfUnpublishedMedia = PayloadOfPublishedMedia;
173
177
  export declare type ChangePreferredLayersPayload = PreferredLayersParams & {
174
178
  consumerId: string;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@livedigital/client",
3
3
  "author": "vlprojects",
4
4
  "license": "MIT",
5
- "version": "2.24.0",
5
+ "version": "2.24.1",
6
6
  "private": false,
7
7
  "bugs": {
8
8
  "url": "https://github.com/vlprojects/livedigital-sdk/issues"
@@ -9,6 +9,7 @@ import {
9
9
  Role,
10
10
  ProducerSetMaxSpatialLayer,
11
11
  PeerInfo,
12
+ SubscribeOptions,
12
13
  } from '../types/common';
13
14
  import EnhancedEventEmitter from '../EnhancedEventEmitter';
14
15
  import Engine from './index';
@@ -118,7 +119,7 @@ class Peer {
118
119
  }));
119
120
  }
120
121
 
121
- public async subscribe(producerId: string): Promise<void> {
122
+ public async subscribe({ producerId, paused = false }: SubscribeOptions): Promise<void> {
122
123
  try {
123
124
  const producer = this.producers.get(producerId);
124
125
  if (!producer) {
@@ -132,7 +133,7 @@ class Peer {
132
133
  return;
133
134
  }
134
135
 
135
- const { consumer } = await this.engine.network.createConsumer({
136
+ const { consumer, isProducerPaused } = await this.engine.network.createConsumer({
136
137
  producerId: producer.id,
137
138
  rtpCapabilities: this.engine.media.mediasoupDevice.rtpCapabilities,
138
139
  producerPeerId: this.id,
@@ -147,9 +148,13 @@ class Peer {
147
148
  engine: this.engine,
148
149
  isPaused: true,
149
150
  peerEventEmitter: this.observer,
151
+ isProducerPaused,
150
152
  });
151
153
 
152
- await track.resume();
154
+ if (!paused) {
155
+ await track.resume();
156
+ }
157
+
153
158
  this.tracks.set(track.label, track);
154
159
  this.logger.debug(`Subscribed for ${producer.kind}`, { peer: this });
155
160
  } catch (error) {
@@ -222,6 +227,7 @@ class Peer {
222
227
  return;
223
228
  }
224
229
 
230
+ track.setIsTrackProducerPaused(true);
225
231
  await track.pause();
226
232
  });
227
233
 
@@ -231,6 +237,7 @@ class Peer {
231
237
  return;
232
238
  }
233
239
 
240
+ track.setIsTrackProducerPaused(false);
234
241
  await track.resume();
235
242
  });
236
243
 
@@ -223,6 +223,12 @@ class Engine {
223
223
  }
224
224
 
225
225
  public removePeer(peerId: string): void {
226
+ const peer = this.peersRepository.get(peerId);
227
+ if (!peer) {
228
+ return;
229
+ }
230
+
231
+ peer.tracks.forEach((track) => track.close());
226
232
  this.peersRepository.delete(peerId);
227
233
  }
228
234
 
@@ -257,6 +257,7 @@ class BaseTrack {
257
257
  }
258
258
 
259
259
  private async cancelProducerCheckState(): Promise<void> {
260
+ this.logger.debug('cancelProducerCheckState()', { track: this });
260
261
  if (this.#checkStateTimeout) {
261
262
  clearTimeout(this.#checkStateTimeout);
262
263
  }
@@ -355,6 +356,7 @@ class BaseTrack {
355
356
  }
356
357
 
357
358
  try {
359
+ await this.cancelProducerCheckState();
358
360
  await this.pauseRemoteProducer(this.producer.id);
359
361
  this.producer.pause();
360
362
  this.clientEventEmitter.emit(INTERNAL_CLIENT_EVENTS.trackPaused, this);
@@ -375,7 +377,7 @@ class BaseTrack {
375
377
  await this.resumeRemoteProducer(this.producer.id);
376
378
  this.producer.resume();
377
379
  this.clientEventEmitter.emit(INTERNAL_CLIENT_EVENTS.trackResumed, this);
378
- this.logger.error('resume()', { track: this });
380
+ this.logger.debug('resume()', { track: this });
379
381
  } catch (error) {
380
382
  this.logger.error('resume()', { error, track: this });
381
383
  throw new Error('Can`t resume track');
@@ -20,6 +20,7 @@ interface PeerTrackConstructor {
20
20
  consumer?: PeerConsumer,
21
21
  engine: Engine,
22
22
  isPaused: boolean,
23
+ isProducerPaused?: boolean,
23
24
  peerEventEmitter: EnhancedEventEmitter,
24
25
  }
25
26
 
@@ -44,6 +45,8 @@ class PeerTrack {
44
45
 
45
46
  #closed = false;
46
47
 
48
+ #isTrackProducerPaused?: boolean;
49
+
47
50
  constructor(payload: PeerTrackConstructor) {
48
51
  this.#mediaStreamTrack = payload.mediaStreamTrack;
49
52
  this.label = payload.label;
@@ -55,6 +58,7 @@ class PeerTrack {
55
58
  });
56
59
  this.#peerEventEmitter = payload.peerEventEmitter;
57
60
  this.#paused = payload.isPaused;
61
+ this.#isTrackProducerPaused = payload.isProducerPaused;
58
62
  this.#peerEventEmitter.safeEmit(PEER_EVENTS.trackStart, this);
59
63
  }
60
64
 
@@ -131,6 +135,11 @@ class PeerTrack {
131
135
  return;
132
136
  }
133
137
 
138
+ if (this.#isTrackProducerPaused) {
139
+ this.#logger.debug('resume()', { message: 'Can not resume track, producer is paused', track: this, peer: this });
140
+ return;
141
+ }
142
+
134
143
  try {
135
144
  await this.#engine.network.resumeRemoteConsumer(this.consumer.id);
136
145
  this.consumer.resume();
@@ -428,6 +437,10 @@ class PeerTrack {
428
437
 
429
438
  clearTimeout(this.#checkStateTimeout);
430
439
  }
440
+
441
+ setIsTrackProducerPaused(value: boolean): void {
442
+ this.#isTrackProducerPaused = value;
443
+ }
431
444
  }
432
445
 
433
446
  export default PeerTrack;
@@ -205,6 +205,11 @@ export type PayloadOfPublishedMedia = {
205
205
  label: TrackLabel,
206
206
  };
207
207
 
208
+ export type SubscribeOptions = {
209
+ producerId: string,
210
+ paused?: boolean,
211
+ };
212
+
208
213
  export type PayloadOfUnpublishedMedia = PayloadOfPublishedMedia;
209
214
 
210
215
  export type ChangePreferredLayersPayload = PreferredLayersParams & {