openvidu-browser 2.27.0 → 2.28.0-beta1

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.
@@ -348,7 +348,9 @@ export class OpenVidu {
348
348
  platform.isSafariBrowser() ||
349
349
  platform.isAndroidBrowser() || // Android WebView & Ionic apps for Android
350
350
  platform.isElectron() ||
351
- platform.isNodeJs()
351
+ platform.isNodeJs() ||
352
+ // TODO: remove when updating platform detection library
353
+ platform.isMotorolaEdgeDevice()
352
354
  );
353
355
  }
354
356
 
@@ -512,107 +514,104 @@ export class OpenVidu {
512
514
  * });
513
515
  * ```
514
516
  */
515
- getUserMedia(options: PublisherProperties): Promise<MediaStream> {
516
- return new Promise<MediaStream>(async (resolve, reject) => {
517
- const askForAudioStreamOnly = async (previousMediaStream: MediaStream, constraints: MediaStreamConstraints) => {
518
- const definedAudioConstraint = constraints.audio === undefined ? true : constraints.audio;
519
- const constraintsAux: MediaStreamConstraints = { audio: definedAudioConstraint, video: false };
520
- try {
521
- const audioOnlyStream = await navigator.mediaDevices.getUserMedia(constraintsAux);
522
- previousMediaStream.addTrack(audioOnlyStream.getAudioTracks()[0]);
523
- return resolve(previousMediaStream);
524
- } catch (error) {
525
- previousMediaStream.getAudioTracks().forEach((track) => {
526
- track.stop();
527
- });
528
- previousMediaStream.getVideoTracks().forEach((track) => {
529
- track.stop();
530
- });
531
- return reject(this.generateAudioDeviceError(error, constraintsAux));
532
- }
533
- };
534
-
517
+ async getUserMedia(options: PublisherProperties): Promise<MediaStream> {
518
+ const askForAudioStreamOnly = async (previousMediaStream: MediaStream, constraints: MediaStreamConstraints) => {
519
+ const definedAudioConstraint = constraints.audio === undefined ? true : constraints.audio;
520
+ const constraintsAux: MediaStreamConstraints = { audio: definedAudioConstraint, video: false };
535
521
  try {
536
- const myConstraints = await this.generateMediaConstraints(options);
537
- if (
538
- (!!myConstraints.videoTrack && !!myConstraints.audioTrack) ||
539
- (!!myConstraints.audioTrack && myConstraints.constraints?.video === false) ||
540
- (!!myConstraints.videoTrack && myConstraints.constraints?.audio === false)
541
- ) {
542
- // No need to call getUserMedia at all. Both tracks provided, or only AUDIO track provided or only VIDEO track provided
543
- return resolve(this.addAlreadyProvidedTracks(myConstraints, new MediaStream()));
544
- } else {
545
- // getUserMedia must be called. AUDIO or VIDEO are requesting a new track
522
+ const audioOnlyStream = await navigator.mediaDevices.getUserMedia(constraintsAux);
523
+ previousMediaStream.addTrack(audioOnlyStream.getAudioTracks()[0]);
524
+ return previousMediaStream;
525
+ } catch (error) {
526
+ previousMediaStream.getAudioTracks().forEach((track) => {
527
+ track.stop();
528
+ });
529
+ previousMediaStream.getVideoTracks().forEach((track) => {
530
+ track.stop();
531
+ });
532
+ throw this.generateAudioDeviceError(error, constraintsAux);
533
+ }
534
+ };
546
535
 
547
- // Delete already provided constraints for audio or video
548
- if (!!myConstraints.videoTrack) {
549
- delete myConstraints.constraints!.video;
550
- }
551
- if (!!myConstraints.audioTrack) {
552
- delete myConstraints.constraints!.audio;
553
- }
536
+ try {
537
+ const myConstraints = await this.generateMediaConstraints(options);
538
+ if (
539
+ (!!myConstraints.videoTrack && !!myConstraints.audioTrack) ||
540
+ (!!myConstraints.audioTrack && myConstraints.constraints?.video === false) ||
541
+ (!!myConstraints.videoTrack && myConstraints.constraints?.audio === false)
542
+ ) {
543
+ // No need to call getUserMedia at all. Both tracks provided, or only AUDIO track provided or only VIDEO track provided
544
+ return this.addAlreadyProvidedTracks(myConstraints, new MediaStream());
545
+ } else {
546
+ // getUserMedia must be called. AUDIO or VIDEO are requesting a new track
554
547
 
555
- let mustAskForAudioTrackLater = false;
556
- if (typeof options.videoSource === 'string') {
557
- // Video is deviceId or screen sharing
558
- if (
559
- options.videoSource === 'screen' ||
560
- options.videoSource === 'window' ||
561
- (platform.isElectron() && options.videoSource.startsWith('screen:'))
562
- ) {
563
- // Video is screen sharing
564
- mustAskForAudioTrackLater =
565
- !myConstraints.audioTrack && options.audioSource !== null && options.audioSource !== false;
566
- if (navigator.mediaDevices['getDisplayMedia'] && !platform.isElectron()) {
567
- // getDisplayMedia supported
568
- try {
569
- const mediaStream = await navigator.mediaDevices['getDisplayMedia']({ video: true });
570
- this.addAlreadyProvidedTracks(myConstraints, mediaStream);
571
- if (mustAskForAudioTrackLater) {
572
- await askForAudioStreamOnly(mediaStream, <MediaStreamConstraints>myConstraints.constraints);
573
- return;
574
- } else {
575
- return resolve(mediaStream);
576
- }
577
- } catch (error) {
578
- let errorName: OpenViduErrorName = OpenViduErrorName.SCREEN_CAPTURE_DENIED;
579
- const errorMessage = error.toString();
580
- return reject(new OpenViduError(errorName, errorMessage));
548
+ // Delete already provided constraints for audio or video
549
+ if (!!myConstraints.videoTrack) {
550
+ delete myConstraints.constraints!.video;
551
+ }
552
+ if (!!myConstraints.audioTrack) {
553
+ delete myConstraints.constraints!.audio;
554
+ }
555
+
556
+ let mustAskForAudioTrackLater = false;
557
+ if (typeof options.videoSource === 'string') {
558
+ // Video is deviceId or screen sharing
559
+ if (
560
+ options.videoSource === 'screen' ||
561
+ options.videoSource === 'window' ||
562
+ (platform.isElectron() && options.videoSource.startsWith('screen:'))
563
+ ) {
564
+ // Video is screen sharing
565
+ mustAskForAudioTrackLater =
566
+ !myConstraints.audioTrack && options.audioSource !== null && options.audioSource !== false;
567
+ if (navigator.mediaDevices['getDisplayMedia'] && !platform.isElectron()) {
568
+ // getDisplayMedia supported
569
+ try {
570
+ const mediaStream = await navigator.mediaDevices['getDisplayMedia']({ video: true });
571
+ this.addAlreadyProvidedTracks(myConstraints, mediaStream);
572
+ if (mustAskForAudioTrackLater) {
573
+ return await askForAudioStreamOnly(mediaStream, <MediaStreamConstraints>myConstraints.constraints);
574
+ } else {
575
+ return mediaStream;
581
576
  }
582
- } else {
583
- // getDisplayMedia NOT supported. Can perform getUserMedia below with already calculated constraints
577
+ } catch (error) {
578
+ let errorName: OpenViduErrorName = OpenViduErrorName.SCREEN_CAPTURE_DENIED;
579
+ const errorMessage = error.toString();
580
+ throw new OpenViduError(errorName, errorMessage);
584
581
  }
585
582
  } else {
586
- // Video is deviceId. Can perform getUserMedia below with already calculated constraints
583
+ // getDisplayMedia NOT supported. Can perform getUserMedia below with already calculated constraints
587
584
  }
585
+ } else {
586
+ // Video is deviceId. Can perform getUserMedia below with already calculated constraints
588
587
  }
589
- // Use already calculated constraints
590
- const constraintsAux = mustAskForAudioTrackLater
591
- ? { video: myConstraints.constraints!.video }
592
- : myConstraints.constraints;
593
- try {
594
- const mediaStream = await navigator.mediaDevices.getUserMedia(constraintsAux);
595
- this.addAlreadyProvidedTracks(myConstraints, mediaStream);
596
- if (mustAskForAudioTrackLater) {
597
- await askForAudioStreamOnly(mediaStream, <MediaStreamConstraints>myConstraints.constraints);
598
- } else {
599
- return resolve(mediaStream);
600
- }
601
- } catch (error) {
602
- let errorName: OpenViduErrorName;
603
- const errorMessage = error.toString();
604
- if (!(options.videoSource === 'screen')) {
605
- errorName = OpenViduErrorName.DEVICE_ACCESS_DENIED;
606
- } else {
607
- errorName = OpenViduErrorName.SCREEN_CAPTURE_DENIED;
608
- }
609
- return reject(new OpenViduError(errorName, errorMessage));
588
+ }
589
+ // Use already calculated constraints
590
+ const constraintsAux = mustAskForAudioTrackLater
591
+ ? { video: myConstraints.constraints!.video }
592
+ : myConstraints.constraints;
593
+ try {
594
+ const mediaStream = await navigator.mediaDevices.getUserMedia(constraintsAux);
595
+ this.addAlreadyProvidedTracks(myConstraints, mediaStream);
596
+ if (mustAskForAudioTrackLater) {
597
+ return await askForAudioStreamOnly(mediaStream, <MediaStreamConstraints>myConstraints.constraints);
598
+ } else {
599
+ return mediaStream;
610
600
  }
601
+ } catch (error) {
602
+ let errorName: OpenViduErrorName;
603
+ const errorMessage = error.toString();
604
+ if (!(options.videoSource === 'screen')) {
605
+ errorName = OpenViduErrorName.DEVICE_ACCESS_DENIED;
606
+ } else {
607
+ errorName = OpenViduErrorName.SCREEN_CAPTURE_DENIED;
608
+ }
609
+ throw new OpenViduError(errorName, errorMessage);
611
610
  }
612
- } catch (error) {
613
- reject(error);
614
611
  }
615
- });
612
+ } catch (error) {
613
+ throw error;
614
+ }
616
615
  }
617
616
 
618
617
  /* tslint:disable:no-empty */
@@ -990,7 +989,7 @@ export class OpenVidu {
990
989
  /**
991
990
  * @hidden
992
991
  */
993
- addAlreadyProvidedTracks(myConstraints: CustomMediaStreamConstraints, mediaStream: MediaStream, stream?: Stream) {
992
+ addAlreadyProvidedTracks(myConstraints: CustomMediaStreamConstraints, mediaStream: MediaStream, stream?: Stream): MediaStream {
994
993
  if (!!myConstraints.videoTrack) {
995
994
  mediaStream.addTrack(myConstraints.videoTrack);
996
995
  if (!!stream) {
@@ -992,8 +992,8 @@ export class Session extends EventDispatcher {
992
992
  oldValue = stream.videoActive;
993
993
  event.newValue = event.newValue === 'true';
994
994
  stream.videoActive = event.newValue;
995
- const videoTrack = stream.getMediaStream().getVideoTracks()[0];
996
- if(!videoTrack.enabled && stream.videoActive){
995
+ const videoTrack = stream?.getMediaStream()?.getVideoTracks()?.[0];
996
+ if(videoTrack && !videoTrack.enabled && stream.videoActive){
997
997
  videoTrack.enabled = true;
998
998
  }
999
999
  break;
@@ -101,6 +101,14 @@ export class PlatformUtils {
101
101
  return platform.name === 'Samsung Internet Mobile' || platform.name === 'Samsung Internet';
102
102
  }
103
103
 
104
+ // TODO: This method exists to overcome bug https://github.com/bestiejs/platform.js/issues/184
105
+ /**
106
+ * @hidden
107
+ */
108
+ public isMotorolaEdgeDevice(): boolean {
109
+ return platform.product?.toLowerCase().includes('motorola edge') || false;
110
+ }
111
+
104
112
  /**
105
113
  * @hidden
106
114
  */
@@ -168,10 +176,14 @@ export class PlatformUtils {
168
176
  this.isSamsungBrowser() ||
169
177
  this.isIonicAndroid() ||
170
178
  this.isIonicIos() ||
171
- this.isElectron()
179
+ this.isElectron() ||
180
+ // TODO: remove when possible
181
+ this.isMotorolaEdgeDevice()
172
182
  );
173
183
  }
174
184
 
185
+
186
+
175
187
  /**
176
188
  * @hidden
177
189
  */
File without changes
@@ -0,0 +1,6 @@
1
+ projectKey=openvidu-browser
2
+ serverUrl=http://172.17.0.1:9000
3
+ serverVersion=10.0.0.68432
4
+ dashboardUrl=http://172.17.0.1:9000/dashboard?id=openvidu-browser
5
+ ceTaskId=AYfrl1uff-k_7mow8Cpd
6
+ ceTaskUrl=http://172.17.0.1:9000/api/ce/task?id=AYfrl1uff-k_7mow8Cpd