@livedigital/client 2.41.1 → 2.42.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.
@@ -36,6 +36,7 @@ export declare type ProducerData = {
36
36
  kind: MediaKind;
37
37
  peerId: string;
38
38
  label: TrackLabel;
39
+ paused: boolean;
39
40
  encodings: RtpEncodingParameters[];
40
41
  trackTransformParams: TrackTransformParams;
41
42
  maxSpatialLayer: number;
@@ -154,6 +155,7 @@ export declare type PayloadOfPublishedMedia = {
154
155
  producerId: string;
155
156
  kind: MediaKind;
156
157
  label: TrackLabel;
158
+ paused: boolean;
157
159
  };
158
160
  export declare type SubscribeOptions = {
159
161
  producerId: string;
@@ -301,6 +303,10 @@ export declare type CreateTracksPayload = {
301
303
  export declare type TrackPublishParams = {
302
304
  keyFrameRequestDelay?: number;
303
305
  };
306
+ export declare type ChangeProducerStatePayload = {
307
+ peerId: string;
308
+ producerId: string;
309
+ };
304
310
  export interface TrackWithEncodings {
305
311
  getCodecOptions(): ProducerCodecOptions;
306
312
  getEncodings(): RtpEncodingParameters[];
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@livedigital/client",
3
3
  "author": "vlprojects",
4
4
  "license": "MIT",
5
- "version": "2.41.1",
5
+ "version": "2.42.0",
6
6
  "private": false,
7
7
  "bugs": {
8
8
  "url": "https://github.com/vlprojects/livedigital-sdk/issues"
@@ -35,6 +35,8 @@ export const INTERNAL_CLIENT_EVENTS = {
35
35
  export const PEER_EVENTS = {
36
36
  mediaPublished: 'media-published',
37
37
  mediaUnPublished: 'media-unpublished',
38
+ publisherPaused: 'publisher-paused',
39
+ publisherResumed: 'publisher-resumed',
38
40
  connectionQualityChanged: 'connection-quality-changed',
39
41
  trackStart: 'track-start',
40
42
  trackEnd: 'track-end',
@@ -56,8 +58,10 @@ export enum SocketIOEvents {
56
58
  export const MEDIASOUP_EVENTS = {
57
59
  newProducer: 'peer.newProducer',
58
60
  producerClose: 'producer.close',
59
- pauseProducer: 'producer.pause',
60
- resumeProducer: 'producer.resume',
61
+ producerPause: 'producer.pause',
62
+ producerResume: 'producer.resume',
63
+ producerPaused: 'producer.paused',
64
+ producerResumed: 'producer.resumed',
61
65
  producerScoreChanged: 'producer.scoreChanged',
62
66
  producerSetMaxSpatialLayer: 'producer.setMaxSpatialLayer',
63
67
  producerRequestMaxSpatialLayer: 'producer.requestMaxSpatialLayer',
@@ -56,7 +56,7 @@ class Peer {
56
56
 
57
57
  public role: Role;
58
58
 
59
- private producers: Map<string, PeerProducer> = new Map();
59
+ producers: Map<string, PeerProducer> = new Map();
60
60
 
61
61
  public readonly tracks: Map<string, PeerTrack> = new Map();
62
62
 
@@ -116,6 +116,7 @@ class Peer {
116
116
  producerId: producer.id,
117
117
  kind: producer.kind,
118
118
  label: producer.label,
119
+ paused: producer.paused,
119
120
  }));
120
121
  }
121
122
 
@@ -215,6 +216,7 @@ class Peer {
215
216
  producerId: producer.id,
216
217
  kind: producer.kind,
217
218
  label: producer.label,
219
+ paused: producer.paused,
218
220
  } as PayloadOfPublishedMedia);
219
221
  }
220
222
 
@@ -228,6 +230,7 @@ class Peer {
228
230
  producerId: producer.id,
229
231
  kind: producer.kind,
230
232
  label: producer.label,
233
+ paused: producer.paused,
231
234
  } as PayloadOfUnpublishedMedia);
232
235
  });
233
236
 
@@ -11,6 +11,8 @@ class PeerProducer {
11
11
 
12
12
  readonly label: TrackLabel;
13
13
 
14
+ public paused: boolean;
15
+
14
16
  readonly encodings: RtpEncodingParameters[];
15
17
 
16
18
  readonly trackTransformParams: TrackTransformParams;
@@ -21,13 +23,14 @@ class PeerProducer {
21
23
 
22
24
  constructor(params: ProducerData) {
23
25
  const {
24
- id, kind, peerId, label,
26
+ id, kind, peerId, label, paused,
25
27
  } = params;
26
28
 
27
29
  this.id = id;
28
30
  this.kind = kind;
29
31
  this.peerId = peerId;
30
32
  this.label = label;
33
+ this.paused = paused;
31
34
  this.encodings = params.encodings;
32
35
  this.trackTransformParams = params.trackTransformParams;
33
36
  this.maxSpatialLayer = params.maxSpatialLayer;
@@ -1,8 +1,8 @@
1
1
  import { AwaitQueue } from 'awaitqueue';
2
2
  import {
3
- ChangePreferredLayersParams,
3
+ ChangePreferredLayersParams, ChangeProducerStatePayload,
4
4
  ConsumerScoreChangedPayload,
5
- LogMessageHandler,
5
+ LogMessageHandler, PayloadOfPublishedMedia,
6
6
  ProducerData,
7
7
  ProducerRequestMaxSpatialLayer,
8
8
  ProducerScoreChangedPayload,
@@ -10,7 +10,7 @@ import {
10
10
  TransportConnectionTimeoutPayload,
11
11
  } from '../../types/common';
12
12
  import Engine from '../index';
13
- import { CLIENT_EVENTS, MEDIASOUP_EVENTS } from '../../constants/events';
13
+ import { CLIENT_EVENTS, MEDIASOUP_EVENTS, PEER_EVENTS } from '../../constants/events';
14
14
  import Logger from '../Logger';
15
15
  import VideoTrack from '../media/tracks/VideoTrack';
16
16
 
@@ -49,7 +49,7 @@ class MediaSoupEventHandler {
49
49
 
50
50
  connection.on(MEDIASOUP_EVENTS.newProducer, (producer: ProducerData) => {
51
51
  const peer = this.engine.peers.find((item) => item.id === producer.peerId);
52
- if (!peer || peer.isMe) {
52
+ if (!peer) {
53
53
  return;
54
54
  }
55
55
 
@@ -167,6 +167,38 @@ class MediaSoupEventHandler {
167
167
  });
168
168
  this.engine.clientEventEmitter.emit(CLIENT_EVENTS.transportConnectionTimeout, { direction, reason });
169
169
  });
170
+
171
+ connection.on(MEDIASOUP_EVENTS.producerPaused, ({ peerId, producerId }: ChangeProducerStatePayload) => {
172
+ const peer = this.engine.peers.find((item) => item.id === peerId);
173
+ const producer = peer?.producers.get(producerId);
174
+ if (!peer || !producer) {
175
+ return;
176
+ }
177
+
178
+ producer.paused = true;
179
+ peer.observer.safeEmit(PEER_EVENTS.publisherPaused, {
180
+ producerId: producer.id,
181
+ kind: producer.kind,
182
+ label: producer.label,
183
+ paused: producer.paused,
184
+ } as PayloadOfPublishedMedia);
185
+ });
186
+
187
+ connection.on(MEDIASOUP_EVENTS.producerResumed, ({ peerId, producerId }: ChangeProducerStatePayload) => {
188
+ const peer = this.engine.peers.find((item) => item.id === peerId);
189
+ const producer = peer?.producers.get(producerId);
190
+ if (!peer || !producer) {
191
+ return;
192
+ }
193
+
194
+ producer.paused = false;
195
+ peer.observer.safeEmit(PEER_EVENTS.publisherResumed, {
196
+ producerId: producer.id,
197
+ kind: producer.kind,
198
+ label: producer.label,
199
+ paused: producer.paused,
200
+ } as PayloadOfPublishedMedia);
201
+ });
170
202
  }
171
203
 
172
204
  private async handleProducerSetMaxSpatialLayer({
@@ -393,11 +393,11 @@ class BaseTrack {
393
393
  }
394
394
 
395
395
  private async pauseRemoteProducer(producerId: string): Promise<SocketResponse> {
396
- return this.#engine.network.socket.request(MEDIASOUP_EVENTS.pauseProducer, { producerId });
396
+ return this.#engine.network.socket.request(MEDIASOUP_EVENTS.producerPause, { producerId });
397
397
  }
398
398
 
399
399
  private async resumeRemoteProducer(producerId: string): Promise<SocketResponse> {
400
- return this.#engine.network.socket.request(MEDIASOUP_EVENTS.resumeProducer, { producerId });
400
+ return this.#engine.network.socket.request(MEDIASOUP_EVENTS.producerResume, { producerId });
401
401
  }
402
402
 
403
403
  public async pause(): Promise<void> {
@@ -45,6 +45,7 @@ export type ProducerData = {
45
45
  kind: MediaKind,
46
46
  peerId: string,
47
47
  label: TrackLabel,
48
+ paused: boolean,
48
49
  encodings: RtpEncodingParameters[],
49
50
  trackTransformParams: TrackTransformParams,
50
51
  maxSpatialLayer: number,
@@ -189,6 +190,7 @@ export type PayloadOfPublishedMedia = {
189
190
  producerId: string,
190
191
  kind: MediaKind,
191
192
  label: TrackLabel,
193
+ paused: boolean,
192
194
  };
193
195
 
194
196
  export type SubscribeOptions = {
@@ -365,6 +367,11 @@ export type TrackPublishParams = {
365
367
  keyFrameRequestDelay?: number;
366
368
  };
367
369
 
370
+ export type ChangeProducerStatePayload = {
371
+ peerId: string,
372
+ producerId: string,
373
+ };
374
+
368
375
  export interface TrackWithEncodings {
369
376
  getCodecOptions(): ProducerCodecOptions;
370
377
  getEncodings(): RtpEncodingParameters[];