@livedigital/client 2.41.0 → 2.41.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.
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.0",
5
+ "version": "2.41.1",
6
6
  "private": false,
7
7
  "bugs": {
8
8
  "url": "https://github.com/vlprojects/livedigital-sdk/issues"
@@ -4,6 +4,16 @@ import EnhancedEventEmitter from '../../EnhancedEventEmitter';
4
4
  import { AvailableMediaDevices, DeviceErrors } from '../../types/common';
5
5
  import Logger from '../Logger';
6
6
 
7
+ const isUnexpectedError = (errorMessage: string) => {
8
+ const errors: string[] = [
9
+ DeviceErrors.NotFoundError,
10
+ DeviceErrors.NotAllowedError,
11
+ DeviceErrors.DeviceIsBusy,
12
+ ];
13
+
14
+ return !errors.includes(errorMessage);
15
+ };
16
+
7
17
  class System {
8
18
  public isEnableVideoDevicesLock = false;
9
19
 
@@ -113,18 +123,14 @@ class System {
113
123
  try {
114
124
  tracks = await this.requestMediaDevicesAccess();
115
125
  } catch (errorVideoAndAudio) {
116
- if (![DeviceErrors.NotFoundError, DeviceErrors.NotAllowedError].includes(errorVideoAndAudio.message)) {
126
+ if (isUnexpectedError(errorVideoAndAudio.message)) {
117
127
  throw errorVideoAndAudio;
118
128
  }
119
129
 
120
- try {
121
- tracks = await this.requestMediaDevicesAccess({ audio: true });
122
- } catch (errorAudioOnly) {
123
- if (![DeviceErrors.NotFoundError, DeviceErrors.NotAllowedError].includes(errorAudioOnly.message)) {
124
- throw errorAudioOnly;
125
- }
126
-
127
- tracks = await this.requestMediaDevicesAccess({ video: true });
130
+ /* if device is busy that means we have permissions */
131
+ if (errorVideoAndAudio.message !== DeviceErrors.DeviceIsBusy) {
132
+ await this.assertHasAccessToMediaDevices({ audio: true });
133
+ await this.assertHasAccessToMediaDevices({ video: true });
128
134
  }
129
135
  }
130
136
 
@@ -158,6 +164,19 @@ class System {
158
164
  listenDevices(): void {
159
165
  navigator.mediaDevices.addEventListener('devicechange', this.deviceChangeHandler);
160
166
  }
167
+
168
+ private async assertHasAccessToMediaDevices(
169
+ constraints: MediaStreamConstraints = { video: true, audio: true },
170
+ ): Promise<void> {
171
+ try {
172
+ const tracks = await this.requestMediaDevicesAccess(constraints);
173
+ tracks.forEach((track) => track.stop());
174
+ } catch (accessError) {
175
+ if (isUnexpectedError(accessError.message)) {
176
+ throw accessError;
177
+ }
178
+ }
179
+ }
161
180
  }
162
181
 
163
182
  export default System;