@stream-io/video-client 0.2.3 → 0.3.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/index.browser.es.js +982 -675
  3. package/dist/index.browser.es.js.map +1 -1
  4. package/dist/index.cjs.js +984 -673
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.es.js +982 -675
  7. package/dist/index.es.js.map +1 -1
  8. package/dist/src/Call.d.ts +21 -9
  9. package/dist/src/StreamVideoClient.d.ts +3 -1
  10. package/dist/src/devices/CameraManager.d.ts +31 -0
  11. package/dist/src/devices/CameraManagerState.d.ts +28 -0
  12. package/dist/src/devices/InputMediaDeviceManager.d.ts +47 -0
  13. package/dist/src/devices/InputMediaDeviceManagerState.d.ts +69 -0
  14. package/dist/src/devices/MicrophoneManager.d.ts +19 -0
  15. package/dist/src/devices/MicrophoneManagerState.d.ts +4 -0
  16. package/dist/src/devices/__tests__/mocks.d.ts +13 -0
  17. package/dist/src/devices/index.d.ts +4 -0
  18. package/dist/src/events/call-permissions.d.ts +0 -5
  19. package/dist/src/events/call.d.ts +0 -6
  20. package/dist/src/events/index.d.ts +0 -6
  21. package/dist/src/rtc/Dispatcher.d.ts +2 -2
  22. package/dist/src/rtc/Publisher.d.ts +0 -1
  23. package/dist/src/store/CallState.d.ts +164 -89
  24. package/dist/src/types.d.ts +5 -7
  25. package/dist/version.d.ts +1 -1
  26. package/package.json +1 -1
  27. package/src/Call.ts +130 -44
  28. package/src/StreamVideoClient.ts +14 -17
  29. package/src/__tests__/StreamVideoClient.test.ts +3 -0
  30. package/src/devices/CameraManager.ts +73 -0
  31. package/src/devices/CameraManagerState.ts +61 -0
  32. package/src/devices/InputMediaDeviceManager.ts +121 -0
  33. package/src/devices/InputMediaDeviceManagerState.ts +111 -0
  34. package/src/devices/MicrophoneManager.ts +45 -0
  35. package/src/devices/MicrophoneManagerState.ts +9 -0
  36. package/src/devices/__tests__/CameraManager.test.ts +150 -0
  37. package/src/devices/__tests__/InputMediaDeviceManager.test.ts +159 -0
  38. package/src/devices/__tests__/MicrophoneManager.test.ts +103 -0
  39. package/src/devices/__tests__/mocks.ts +98 -0
  40. package/src/devices/index.ts +4 -0
  41. package/src/events/__tests__/call-permissions.test.ts +1 -61
  42. package/src/events/__tests__/call.test.ts +5 -50
  43. package/src/events/call-permissions.ts +0 -14
  44. package/src/events/call.ts +5 -16
  45. package/src/events/callEventHandlers.ts +2 -57
  46. package/src/events/index.ts +0 -6
  47. package/src/rtc/Dispatcher.ts +2 -2
  48. package/src/rtc/Publisher.ts +4 -6
  49. package/src/store/CallState.ts +475 -119
  50. package/src/store/__tests__/CallState.test.ts +447 -1
  51. package/src/types.ts +4 -8
  52. package/dist/src/events/__tests__/sessions.test.d.ts +0 -1
  53. package/dist/src/events/backstage.d.ts +0 -6
  54. package/dist/src/events/members.d.ts +0 -18
  55. package/dist/src/events/moderation.d.ts +0 -14
  56. package/dist/src/events/reactions.d.ts +0 -8
  57. package/dist/src/events/recording.d.ts +0 -18
  58. package/dist/src/events/sessions.d.ts +0 -26
  59. package/src/events/__tests__/backstage.test.ts +0 -15
  60. package/src/events/__tests__/members.test.ts +0 -135
  61. package/src/events/__tests__/recording.test.ts +0 -65
  62. package/src/events/__tests__/sessions.test.ts +0 -135
  63. package/src/events/backstage.ts +0 -15
  64. package/src/events/members.ts +0 -62
  65. package/src/events/moderation.ts +0 -35
  66. package/src/events/reactions.ts +0 -30
  67. package/src/events/recording.ts +0 -64
  68. package/src/events/sessions.ts +0 -102
  69. /package/dist/src/{events/__tests__/backstage.test.d.ts → devices/__tests__/CameraManager.test.d.ts} +0 -0
  70. /package/dist/src/{events/__tests__/members.test.d.ts → devices/__tests__/InputMediaDeviceManager.test.d.ts} +0 -0
  71. /package/dist/src/{events/__tests__/recording.test.d.ts → devices/__tests__/MicrophoneManager.test.d.ts} +0 -0
@@ -5,7 +5,10 @@ import { AcceptCallResponse, BlockUserResponse, EndCallResponse, GetCallResponse
5
5
  import { CallConstructor, CallLeaveOptions, DebounceType, JoinCallData, PublishOptions, SubscriptionChanges } from './types';
6
6
  import { ViewportTracker } from './helpers/ViewportTracker';
7
7
  import { PermissionsContext } from './permissions';
8
- import { CallEventHandler, CallEventTypes, Logger } from './coordinator/connection/types';
8
+ import { StreamClient } from './coordinator/connection/client';
9
+ import { CallEventHandler, CallEventTypes, EventTypes, Logger } from './coordinator/connection/types';
10
+ import { CameraManager } from './devices/CameraManager';
11
+ import { MicrophoneManager } from './devices/MicrophoneManager';
9
12
  /**
10
13
  * An object representation of a `Call`.
11
14
  */
@@ -35,6 +38,14 @@ export declare class Call {
35
38
  * updates from the backend.
36
39
  */
37
40
  watching: boolean;
41
+ /**
42
+ * Device manager for the camera
43
+ */
44
+ readonly camera: CameraManager;
45
+ /**
46
+ * Device manager for the microhpone
47
+ */
48
+ readonly microphone: MicrophoneManager;
38
49
  /**
39
50
  * Flag telling whether this call is a "ringing" call.
40
51
  */
@@ -55,7 +66,7 @@ export declare class Call {
55
66
  private statsReporter?;
56
67
  private dropTimeout;
57
68
  private readonly clientStore;
58
- private readonly streamClient;
69
+ readonly streamClient: StreamClient;
59
70
  private sfuClient?;
60
71
  private reconnectAttempts;
61
72
  private maxReconnectAttempts;
@@ -74,7 +85,7 @@ export declare class Call {
74
85
  * Use the [`StreamVideoClient.call`](./StreamVideoClient.md/#call)
75
86
  * method to construct a `Call` instance.
76
87
  */
77
- constructor({ type, id, streamClient, metadata, members, ownCapabilities, sortParticipantsBy, clientStore, ringing, watching, }: CallConstructor);
88
+ constructor({ type, id, streamClient, members, ownCapabilities, sortParticipantsBy, clientStore, ringing, watching, }: CallConstructor);
78
89
  private registerEffects;
79
90
  /**
80
91
  * You can subscribe to WebSocket events provided by the API. To remove a subscription, call the `off` method.
@@ -84,7 +95,7 @@ export declare class Call {
84
95
  * @returns a function which can be called to unsubscribe from the given event(s)
85
96
  */
86
97
  on(eventName: SfuEventKinds, fn: SfuEventListener): () => void;
87
- on(eventName: CallEventTypes, fn: CallEventHandler): () => void;
98
+ on(eventName: EventTypes, fn: CallEventHandler): () => void;
88
99
  /**
89
100
  * Remove subscription for WebSocket events that were created by the `on` method.
90
101
  * @param eventName
@@ -97,10 +108,6 @@ export declare class Call {
97
108
  * Leave the call and stop the media streams that were published by the call.
98
109
  */
99
110
  leave: ({ reject }?: CallLeaveOptions) => Promise<void>;
100
- /**
101
- * A getter for the call metadata.
102
- */
103
- get data(): import("./gen/coordinator").CallResponse | undefined;
104
111
  /**
105
112
  * A flag indicating whether the call is "ringing" type of call.
106
113
  */
@@ -253,6 +260,8 @@ export declare class Call {
253
260
  *
254
261
  *
255
262
  * @param deviceId the selected device, pass `undefined` to clear the device selection
263
+ *
264
+ * @deprecated use call.microphone.select
256
265
  */
257
266
  setAudioDevice: (deviceId?: string) => void;
258
267
  /**
@@ -261,6 +270,8 @@ export declare class Call {
261
270
  * This method only stores the selection, if you want to start publishing a media stream call the [`publishVideoStream` method](#publishvideostream) that will set `videoDeviceId` as well.
262
271
  *
263
272
  * @param deviceId the selected device, pass `undefined` to clear the device selection
273
+ *
274
+ * @deprecated use call.camera.select
264
275
  */
265
276
  setVideoDevice: (deviceId?: string) => void;
266
277
  /**
@@ -448,7 +459,6 @@ export declare class Call {
448
459
  private scheduleAutoDrop;
449
460
  /**
450
461
  * Retrieves the list of recordings for the current call or call session.
451
- * Updates the call state with the returned array of CallRecording objects.
452
462
  *
453
463
  * If `callSessionId` is provided, it will return the recordings for that call session.
454
464
  * Otherwise, all recordings for the current call will be returned.
@@ -464,4 +474,6 @@ export declare class Call {
464
474
  sendCustomEvent: (payload: {
465
475
  [key: string]: any;
466
476
  }) => Promise<SendEventResponse>;
477
+ private initCamera;
478
+ private initMic;
467
479
  }
@@ -92,7 +92,9 @@ export declare class StreamVideoClient {
92
92
  next?: string | undefined;
93
93
  prev?: string | undefined;
94
94
  }>;
95
- queryUsers: () => Promise<void>;
95
+ /**
96
+ * Returns a list of available data centers available for hosting calls.
97
+ */
96
98
  edges: () => Promise<GetEdgesResponse>;
97
99
  /**
98
100
  * addDevice - Adds a push device for a user.
@@ -0,0 +1,31 @@
1
+ import { Observable } from 'rxjs';
2
+ import { Call } from '../Call';
3
+ import { CameraDirection, CameraManagerState } from './CameraManagerState';
4
+ import { InputMediaDeviceManager } from './InputMediaDeviceManager';
5
+ export declare class CameraManager extends InputMediaDeviceManager<CameraManagerState> {
6
+ constructor(call: Call);
7
+ /**
8
+ * Select the camera direaction
9
+ * @param direction
10
+ */
11
+ selectDirection(direction: Exclude<CameraDirection, undefined>): Promise<void>;
12
+ /**
13
+ * Flips the camera direction: if it's front it will change to back, if it's back, it will change to front.
14
+ *
15
+ * Note: if there is no available camera with the desired direction, this method will do nothing.
16
+ * @returns
17
+ */
18
+ flip(): Promise<void>;
19
+ protected getDevices(): Observable<MediaDeviceInfo[]>;
20
+ protected getStream(constraints: MediaTrackConstraints): Promise<MediaStream>;
21
+ protected publishStream(stream: MediaStream): Promise<void>;
22
+ protected stopPublishStream(): Promise<void>;
23
+ /**
24
+ * Disables the video tracks of the camera
25
+ */
26
+ pause(): void;
27
+ /**
28
+ * (Re)enables the video tracks of the camera
29
+ */
30
+ resume(): void;
31
+ }
@@ -0,0 +1,28 @@
1
+ import { Observable } from 'rxjs';
2
+ import { InputMediaDeviceManagerState } from './InputMediaDeviceManagerState';
3
+ export type CameraDirection = 'front' | 'back' | undefined;
4
+ export declare class CameraManagerState extends InputMediaDeviceManagerState {
5
+ private directionSubject;
6
+ /**
7
+ * Observable that emits the preferred camera direction
8
+ * front - means the camera facing the user
9
+ * back - means the camera facing the environment
10
+ */
11
+ direction$: Observable<CameraDirection>;
12
+ constructor();
13
+ /**
14
+ * The preferred camera direction
15
+ * front - means the camera facing the user
16
+ * back - means the camera facing the environment
17
+ */
18
+ get direction(): CameraDirection;
19
+ /**
20
+ * @internal
21
+ */
22
+ setDirection(direction: CameraDirection): void;
23
+ /**
24
+ * @internal
25
+ */
26
+ setMediaStream(stream: MediaStream | undefined): void;
27
+ protected getDeviceIdFromStream(stream: MediaStream): string | undefined;
28
+ }
@@ -0,0 +1,47 @@
1
+ import { Observable } from 'rxjs';
2
+ import { Call } from '../Call';
3
+ import { InputMediaDeviceManagerState } from './InputMediaDeviceManagerState';
4
+ export declare abstract class InputMediaDeviceManager<T extends InputMediaDeviceManagerState> {
5
+ protected readonly call: Call;
6
+ readonly state: T;
7
+ constructor(call: Call, state: T);
8
+ /**
9
+ * Lists the available audio/video devices
10
+ *
11
+ * Note: It prompts the user for a permission to use devices (if not already granted)
12
+ *
13
+ * @returns an Observable that will be updated if a device is connected or disconnected
14
+ */
15
+ listDevices(): Observable<MediaDeviceInfo[]>;
16
+ /**
17
+ * Starts camera/microphone
18
+ */
19
+ enable(): Promise<void>;
20
+ /**
21
+ * Stops camera/microphone
22
+ * @returns
23
+ */
24
+ disable(): Promise<void>;
25
+ /**
26
+ * If current device statis is disabled, it will enable the device, else it will disable it.
27
+ * @returns
28
+ */
29
+ toggle(): Promise<void>;
30
+ /**
31
+ * Select device
32
+ *
33
+ * Note: this method is not supported in React Native
34
+ *
35
+ * @param deviceId
36
+ */
37
+ select(deviceId: string | undefined): Promise<void>;
38
+ protected applySettingsToStream(): Promise<void>;
39
+ abstract pause(): void;
40
+ abstract resume(): void;
41
+ protected abstract getDevices(): Observable<MediaDeviceInfo[]>;
42
+ protected abstract getStream(constraints: MediaTrackConstraints): Promise<MediaStream>;
43
+ protected abstract publishStream(stream: MediaStream): Promise<void>;
44
+ protected abstract stopPublishStream(): Promise<void>;
45
+ private stopStream;
46
+ private startStream;
47
+ }
@@ -0,0 +1,69 @@
1
+ import { BehaviorSubject, Observable } from 'rxjs';
2
+ import { RxUtils } from '../store';
3
+ export type InputDeviceStatus = 'enabled' | 'disabled' | undefined;
4
+ export declare abstract class InputMediaDeviceManagerState {
5
+ protected statusSubject: BehaviorSubject<InputDeviceStatus>;
6
+ protected mediaStreamSubject: BehaviorSubject<MediaStream | undefined>;
7
+ protected selectedDeviceSubject: BehaviorSubject<string | undefined>;
8
+ /**
9
+ * An Observable that emits the current media stream, or `undefined` if the device is currently disabled.
10
+ *
11
+ */
12
+ mediaStream$: Observable<MediaStream | undefined>;
13
+ /**
14
+ * An Observable that emits the currently selected device
15
+ */
16
+ selectedDevice$: Observable<string | undefined>;
17
+ /**
18
+ * An Observable that emits the device status
19
+ */
20
+ status$: Observable<InputDeviceStatus>;
21
+ constructor();
22
+ /**
23
+ * The device status
24
+ */
25
+ get status(): InputDeviceStatus;
26
+ /**
27
+ * The currently selected device
28
+ */
29
+ get selectedDevice(): string | undefined;
30
+ /**
31
+ * The current media stream, or `undefined` if the device is currently disabled.
32
+ */
33
+ get mediaStream(): MediaStream | undefined;
34
+ /**
35
+ * Gets the current value of an observable, or undefined if the observable has
36
+ * not emitted a value yet.
37
+ *
38
+ * @param observable$ the observable to get the value from.
39
+ */
40
+ getCurrentValue: <T>(observable$: Observable<T>) => T;
41
+ /**
42
+ * @internal
43
+ * @param status
44
+ */
45
+ setStatus(status: InputDeviceStatus): void;
46
+ /**
47
+ * @internal
48
+ * @param stream
49
+ */
50
+ setMediaStream(stream: MediaStream | undefined): void;
51
+ /**
52
+ * @internal
53
+ * @param stream
54
+ */
55
+ setDevice(deviceId: string | undefined): void;
56
+ /**
57
+ * Updates the value of the provided Subject.
58
+ * An `update` can either be a new value or a function which takes
59
+ * the current value and returns a new value.
60
+ *
61
+ * @internal
62
+ *
63
+ * @param subject the subject to update.
64
+ * @param update the update to apply to the subject.
65
+ * @return the updated value.
66
+ */
67
+ protected setCurrentValue: <T>(subject: import("rxjs").Subject<T>, update: RxUtils.Patch<T>) => T;
68
+ protected abstract getDeviceIdFromStream(stream: MediaStream): string | undefined;
69
+ }
@@ -0,0 +1,19 @@
1
+ import { Observable } from 'rxjs';
2
+ import { Call } from '../Call';
3
+ import { InputMediaDeviceManager } from './InputMediaDeviceManager';
4
+ import { MicrophoneManagerState } from './MicrophoneManagerState';
5
+ export declare class MicrophoneManager extends InputMediaDeviceManager<MicrophoneManagerState> {
6
+ constructor(call: Call);
7
+ protected getDevices(): Observable<MediaDeviceInfo[]>;
8
+ protected getStream(constraints: MediaTrackConstraints): Promise<MediaStream>;
9
+ protected publishStream(stream: MediaStream): Promise<void>;
10
+ protected stopPublishStream(): Promise<void>;
11
+ /**
12
+ * Disables the audio tracks of the microphone
13
+ */
14
+ pause(): void;
15
+ /**
16
+ * (Re)enables the audio tracks of the microphone
17
+ */
18
+ resume(): void;
19
+ }
@@ -0,0 +1,4 @@
1
+ import { InputMediaDeviceManagerState } from './InputMediaDeviceManagerState';
2
+ export declare class MicrophoneManagerState extends InputMediaDeviceManagerState {
3
+ protected getDeviceIdFromStream(stream: MediaStream): string | undefined;
4
+ }
@@ -0,0 +1,13 @@
1
+ import { CallingState } from '../../store';
2
+ export declare const mockVideoDevices: MediaDeviceInfo[];
3
+ export declare const mockAudioDevices: MediaDeviceInfo[];
4
+ export declare const mockCall: () => {
5
+ state: {
6
+ callingState: CallingState;
7
+ };
8
+ publishVideoStream: import("@vitest/spy").Mock<any, any>;
9
+ publishAudioStream: import("@vitest/spy").Mock<any, any>;
10
+ stopPublish: import("@vitest/spy").Mock<any, any>;
11
+ };
12
+ export declare const mockAudioStream: () => MediaStream;
13
+ export declare const mockVideoStream: () => MediaStream;
@@ -1 +1,5 @@
1
1
  export * from './devices';
2
+ export * from './InputMediaDeviceManager';
3
+ export * from './InputMediaDeviceManagerState';
4
+ export * from './CameraManager';
5
+ export * from './MicrophoneManager';
@@ -1,10 +1,5 @@
1
- import { StreamVideoEvent } from '../coordinator/connection/types';
2
1
  import { CallState } from '../store';
3
2
  import { SfuEvent } from '../gen/video/sfu/event/events';
4
- /**
5
- * Event handler that watches for `call.permissions_updated` events
6
- */
7
- export declare const watchCallPermissionsUpdated: (state: CallState) => (event: StreamVideoEvent) => void;
8
3
  /**
9
4
  * Event handler that watches for `callGrantsUpdated` events.
10
5
  *
@@ -1,4 +1,3 @@
1
- import { CallState } from '../store';
2
1
  import { StreamVideoEvent } from '../coordinator/connection/types';
3
2
  import { Call } from '../Call';
4
3
  /**
@@ -15,8 +14,3 @@ export declare const watchCallRejected: (call: Call) => (event: StreamVideoEvent
15
14
  * Event handler that watches the delivery of `call.ended` Websocket event.
16
15
  */
17
16
  export declare const watchCallEnded: (call: Call) => (event: StreamVideoEvent) => Promise<void>;
18
- /**
19
- * An event handler which listens to `call.updated` events
20
- * and updates the given call state accordingly.
21
- */
22
- export declare const watchCallUpdated: (state: CallState) => (event: StreamVideoEvent) => void;
@@ -1,11 +1,5 @@
1
- export * from './backstage';
2
1
  export * from './call';
3
2
  export * from './call-permissions';
4
3
  export * from './internal';
5
- export * from './members';
6
4
  export * from './participant';
7
- export * from './reactions';
8
- export * from './recording';
9
5
  export * from './speaker';
10
- export * from './sessions';
11
- export * from './moderation';
@@ -1,7 +1,7 @@
1
- import { CallEventTypes } from '../coordinator/connection/types';
1
+ import { EventTypes } from '../coordinator/connection/types';
2
2
  import type { SfuEvent } from '../gen/video/sfu/event/events';
3
3
  export type SfuEventKinds = NonNullable<SfuEvent['eventPayload']['oneofKind']>;
4
- export declare const isSfuEvent: (eventName: SfuEventKinds | CallEventTypes) => eventName is SfuEventKinds;
4
+ export declare const isSfuEvent: (eventName: SfuEventKinds | EventTypes) => eventName is SfuEventKinds;
5
5
  export type SfuEventListener = (event: SfuEvent) => void;
6
6
  export declare class Dispatcher {
7
7
  private subscribers;
@@ -20,7 +20,6 @@ export type PublisherOpts = {
20
20
  export declare class Publisher {
21
21
  private pc;
22
22
  private readonly state;
23
- private readonly dispatcher;
24
23
  private readonly transceiverRegistry;
25
24
  /**
26
25
  * An array maintaining the order how transceivers were added to the peer connection.