@livedigital/client 1.15.0 → 1.15.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.
@@ -125,9 +125,13 @@ export declare type CreateScreenVideoTrackOptions = CreateVideoTrackOptions & {
125
125
  export declare type CreateMicrophoneAudioTrackOptions = CreateTrackOptions & {
126
126
  encoderConfig?: AudioEncoderConfig;
127
127
  };
128
- export declare type CreateScreenAudioTrackOptions = CreateVideoTrackOptions & {
128
+ export declare type CreateScreenAudioTrackOptions = CreateMicrophoneAudioTrackOptions & {
129
129
  encoderConfig?: AudioEncoderConfig;
130
130
  };
131
+ export declare type CreateScreenMediaOptions = {
132
+ video: CreateScreenVideoTrackOptions;
133
+ audio: CreateScreenAudioTrackOptions;
134
+ };
131
135
  export declare type Track = VideoTrack | AudioTrack;
132
136
  export declare enum TrackLabel {
133
137
  Camera = "camera",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@livedigital/client",
3
3
  "author": "vlprojects",
4
4
  "license": "MIT",
5
- "version": "1.15.0",
5
+ "version": "1.15.1",
6
6
  "private": false,
7
7
  "bugs": {
8
8
  "url": "https://github.com/vlprojects/livedigital-sdk/issues"
@@ -2,8 +2,7 @@ import { RtpCapabilities } from 'mediasoup-client/lib/RtpParameters';
2
2
  import {
3
3
  CreateCameraVideoTrackOptions,
4
4
  CreateMicrophoneAudioTrackOptions,
5
- CreateScreenAudioTrackOptions,
6
- CreateScreenVideoTrackOptions,
5
+ CreateScreenMediaOptions,
7
6
  EndTrackPayload,
8
7
  JoinChannelParams,
9
8
  PeerResponse,
@@ -197,7 +196,7 @@ class Engine {
197
196
  async createCameraVideoTrack(options?: CreateCameraVideoTrackOptions): Promise<Track> {
198
197
  const trackParams = Media.getCameraVideoTrackParams(options);
199
198
  try {
200
- const track = await this.media.createUserMediaTrack({
199
+ const [track] = await this.media.createUserMediaTracks({
201
200
  audio: false,
202
201
  video: trackParams.videoTrackOptions,
203
202
  });
@@ -215,7 +214,7 @@ class Engine {
215
214
 
216
215
  async createMicrophoneAudioTrack(options?: CreateMicrophoneAudioTrackOptions): Promise<Track> {
217
216
  try {
218
- const track = await this.media.createUserMediaTrack({
217
+ const [track] = await this.media.createUserMediaTracks({
219
218
  video: false,
220
219
  audio: {
221
220
  deviceId: options?.deviceId,
@@ -235,50 +234,38 @@ class Engine {
235
234
  }
236
235
  }
237
236
 
238
- async createScreenVideoTrack(options?: CreateScreenVideoTrackOptions): Promise<Track> {
239
- const trackParams = Media.getScreenVideoTrackParams(options);
237
+ async createScreenMediaTracks(options?: CreateScreenMediaOptions): Promise<Track[]> {
238
+ const videoTrackParams = Media.getScreenVideoTrackParams(options?.video);
240
239
  try {
241
- const track = await this.media.createDisplayMediaTrack({
242
- audio: false,
243
- video: trackParams.videoTrackOptions,
240
+ const tracks = await this.media.createDisplayMediaTracks({
241
+ audio: options?.audio,
242
+ video: videoTrackParams.videoTrackOptions,
244
243
  });
245
244
 
246
- track.mediaStreamTrack.addEventListener('ended', () => {
247
- this.unpublish(track);
248
- });
249
-
250
- track.setLabel(TrackLabel.ScreenVideo);
251
- track.setEncoderConfig(trackParams.encoderConfig);
245
+ tracks.forEach((track) => {
246
+ track.mediaStreamTrack.addEventListener('ended', () => {
247
+ this.unpublish(track);
248
+ });
252
249
 
253
- this.logger.debug('createScreenVideoTrack()', { trackParams, track });
254
- return track;
255
- } catch (error) {
256
- this.logger.error('createScreenVideoTrack()', { error, trackParams });
257
- throw new Error(`Can not create screen video track: ${error.message}`);
258
- }
259
- }
250
+ if (track.kind === 'video') {
251
+ track.setLabel(TrackLabel.ScreenVideo);
252
+ track.setEncoderConfig(videoTrackParams.encoderConfig);
253
+ this.logger.debug('createScreenMediaTrack()', { trackParams: videoTrackParams, track });
254
+ return;
255
+ }
260
256
 
261
- async createScreenAudioTrack(options?: CreateScreenAudioTrackOptions): Promise<Track> {
262
- try {
263
- const track = await this.media.createDisplayMediaTrack({
264
- video: false,
265
- audio: true,
266
- });
257
+ track.setLabel(TrackLabel.ScreenAudio);
258
+ if (options?.audio) {
259
+ track.setEncoderConfig(options.audio);
260
+ }
267
261
 
268
- track.mediaStreamTrack.addEventListener('ended', () => {
269
- this.unpublish(track);
262
+ this.logger.debug('createScreenMediaTrack()', { trackParams: options?.audio, track });
270
263
  });
271
264
 
272
- track.setLabel(TrackLabel.ScreenAudio);
273
- if (options?.encoderConfig) {
274
- track.setEncoderConfig(options.encoderConfig);
275
- }
276
-
277
- this.logger.debug('createScreenAudioTrack()', { options, track });
278
- return track;
265
+ return tracks;
279
266
  } catch (error) {
280
- this.logger.error('createScreenAudioTrack()', { error, options });
281
- throw new Error(`Can not create screen audio track: ${error.message}`);
267
+ this.logger.error('createScreenMediaTrack()', { error, trackParams: videoTrackParams });
268
+ throw new Error(`Can not create screen media tracks: ${error.message}`);
282
269
  }
283
270
  }
284
271
 
@@ -46,28 +46,33 @@ class Media {
46
46
  .find((c) => c.mimeType.toLowerCase() === `video/${track.getPreferredCodec()}`);
47
47
  }
48
48
 
49
- private createTrack(stream: MediaStream): Track {
50
- const mediaStreamTrack = stream.getTracks()[0];
51
-
52
- const track = mediaStreamTrack.kind === 'audio'
53
- ? new AudioTrack(mediaStreamTrack)
54
- : new VideoTrack(mediaStreamTrack);
55
-
56
- this.tracks.set(track.id, track);
57
- this.#logger.debug('createTrack() track created', { streamId: stream.id, trackId: track.id, kind: track.kind });
58
-
59
- return track;
49
+ private createTracks(stream: MediaStream): Track[] {
50
+ const mediaStreamTracks = stream.getTracks();
51
+ return mediaStreamTracks.map((mediaStreamTrack) => {
52
+ const track = mediaStreamTrack.kind === 'audio'
53
+ ? new AudioTrack(mediaStreamTrack)
54
+ : new VideoTrack(mediaStreamTrack);
55
+
56
+ this.tracks.set(track.id, track);
57
+ this.#logger.debug('createTrack() track created', {
58
+ streamId: stream.id,
59
+ trackId: track.id,
60
+ kind: track.kind,
61
+ });
62
+
63
+ return track;
64
+ });
60
65
  }
61
66
 
62
- async createUserMediaTrack(constraints: MediaStreamConstraints): Promise<Track> {
67
+ async createUserMediaTracks(constraints: MediaStreamConstraints): Promise<Track[]> {
63
68
  const stream = await navigator.mediaDevices.getUserMedia(constraints);
64
69
  this.#logger.debug('createUserMediaTrack() stream created', { streamId: stream.id });
65
- return this.createTrack(stream);
70
+ return this.createTracks(stream);
66
71
  }
67
72
 
68
- async createDisplayMediaTrack(constraints: MediaStreamConstraints): Promise<Track> {
73
+ async createDisplayMediaTracks(constraints: MediaStreamConstraints): Promise<Track[]> {
69
74
  const stream = await navigator.mediaDevices.getDisplayMedia(constraints);
70
- return this.createTrack(stream);
75
+ return this.createTracks(stream);
71
76
  }
72
77
 
73
78
  deleteTrack(track: Track) {
package/src/index.ts CHANGED
@@ -2,8 +2,7 @@ import {
2
2
  AvailableMediaDevices,
3
3
  CreateCameraVideoTrackOptions,
4
4
  CreateMicrophoneAudioTrackOptions,
5
- CreateScreenAudioTrackOptions,
6
- CreateScreenVideoTrackOptions,
5
+ CreateScreenMediaOptions,
7
6
  JoinChannelParams,
8
7
  Track,
9
8
  } from './types/common';
@@ -96,12 +95,8 @@ class Client {
96
95
  return this.engine.createMicrophoneAudioTrack(options);
97
96
  }
98
97
 
99
- createScreenVideoTrack(options?: CreateScreenVideoTrackOptions): Promise<Track> {
100
- return this.engine.createScreenVideoTrack(options);
101
- }
102
-
103
- createScreenAudioTrack(options?: CreateScreenAudioTrackOptions): Promise<Track> {
104
- return this.engine.createScreenAudioTrack(options);
98
+ createScreenMediaTracks(options?: CreateScreenMediaOptions): Promise<Track[]> {
99
+ return this.engine.createScreenMediaTracks(options);
105
100
  }
106
101
 
107
102
  deleteTrack(track: Track): void {
@@ -152,10 +152,15 @@ export type CreateMicrophoneAudioTrackOptions = CreateTrackOptions & {
152
152
  encoderConfig?: AudioEncoderConfig,
153
153
  };
154
154
 
155
- export type CreateScreenAudioTrackOptions = CreateVideoTrackOptions & {
155
+ export type CreateScreenAudioTrackOptions = CreateMicrophoneAudioTrackOptions & {
156
156
  encoderConfig?: AudioEncoderConfig,
157
157
  };
158
158
 
159
+ export type CreateScreenMediaOptions = {
160
+ video: CreateScreenVideoTrackOptions,
161
+ audio: CreateScreenAudioTrackOptions,
162
+ };
163
+
159
164
  export type Track = VideoTrack | AudioTrack;
160
165
 
161
166
  export enum TrackLabel {