@whereby.com/browser-sdk 2.0.0-alpha2 → 2.0.0-alpha21

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/dist/types.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import React from 'react';
2
+ import RtcManager from '@whereby/jslib-media/src/webrtc/RtcManager';
3
+ import { ChatMessage as ChatMessage$1 } from '@whereby/jslib-media/src/utils/ServerSocket';
2
4
 
3
5
  interface WherebyEmbedAttributes {
4
6
  audio: string;
@@ -31,11 +33,97 @@ declare global {
31
33
  }
32
34
  }
33
35
 
34
- interface VideoElProps {
36
+ interface VideoViewSelfProps {
35
37
  stream: MediaStream;
38
+ muted?: boolean;
36
39
  style?: React.CSSProperties;
40
+ onResize?: ({ width, height, stream }: {
41
+ width: number;
42
+ height: number;
43
+ stream: MediaStream;
44
+ }) => void;
37
45
  }
38
- declare const _default: ({ stream, style }: VideoElProps) => JSX.Element;
46
+ type VideoViewProps = VideoViewSelfProps & React.DetailedHTMLProps<React.VideoHTMLAttributes<HTMLVideoElement>, HTMLVideoElement>;
47
+ declare const _default: ({ muted, stream, onResize, ...rest }: VideoViewProps) => JSX.Element;
48
+
49
+ type CameraEnabledEvent = {
50
+ enabled: boolean;
51
+ };
52
+ type MicrophoneEnabledEvent = {
53
+ enabled: boolean;
54
+ };
55
+ type DeviceListUpdatedEvent = {
56
+ cameraDevices: MediaDeviceInfo[];
57
+ microphoneDevices: MediaDeviceInfo[];
58
+ speakerDevices: MediaDeviceInfo[];
59
+ };
60
+ type DeviceListUpdateErrorEvent = {
61
+ error: unknown;
62
+ };
63
+ type StreamUpdatedEvent = {
64
+ stream: MediaStream;
65
+ };
66
+ interface LocalMediaEventsMap {
67
+ camera_enabled: CustomEvent<CameraEnabledEvent>;
68
+ device_list_updated: CustomEvent<DeviceListUpdatedEvent>;
69
+ device_list_update_error: CustomEvent<DeviceListUpdateErrorEvent>;
70
+ microphone_enabled: CustomEvent<MicrophoneEnabledEvent>;
71
+ stream_updated: CustomEvent<StreamUpdatedEvent>;
72
+ }
73
+ interface LocalMediaEventTarget extends EventTarget {
74
+ addEventListener<K extends keyof LocalMediaEventsMap>(type: K, listener: (ev: LocalMediaEventsMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
75
+ addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
76
+ }
77
+ declare const TypedLocalMediaEventTarget: new () => LocalMediaEventTarget;
78
+ declare class LocalMedia extends TypedLocalMediaEventTarget {
79
+ private _constraints;
80
+ _rtcManagers: RtcManager[];
81
+ stream: MediaStream;
82
+ screenshareStream?: MediaStream;
83
+ constructor(constraints: MediaStreamConstraints);
84
+ addRtcManager(rtcManager: RtcManager): void;
85
+ removeRtcManager(rtcManager: RtcManager): void;
86
+ getCameraDeviceId(): string | undefined;
87
+ getMicrophoneDeviceId(): string | undefined;
88
+ isCameraEnabled(): boolean;
89
+ isMicrophoneEnabled(): boolean;
90
+ toggleCameraEnabled(enabled?: boolean): void;
91
+ toggleMichrophoneEnabled(enabled?: boolean): void;
92
+ startScreenshare(): Promise<MediaStream>;
93
+ stopScreenshare(): void;
94
+ setCameraDevice(deviceId: string): Promise<void>;
95
+ setMicrophoneDevice(deviceId: string): Promise<void>;
96
+ private _updateDeviceList;
97
+ start(): Promise<MediaStream>;
98
+ stop(): void;
99
+ }
100
+
101
+ interface LocalMediaState {
102
+ currentCameraDeviceId?: string;
103
+ currentMicrophoneDeviceId?: string;
104
+ cameraDeviceError: unknown;
105
+ cameraDevices: MediaDeviceInfo[];
106
+ isSettingCameraDevice: boolean;
107
+ isSettingMicrophoneDevice: boolean;
108
+ isStarting: boolean;
109
+ localStream?: MediaStream;
110
+ microphoneDeviceError: unknown;
111
+ microphoneDevices: MediaDeviceInfo[];
112
+ speakerDevices: MediaDeviceInfo[];
113
+ startError: unknown;
114
+ }
115
+ interface LocalMediaActions {
116
+ setCameraDevice: InstanceType<typeof LocalMedia>["setCameraDevice"];
117
+ setMicrophoneDevice: InstanceType<typeof LocalMedia>["setMicrophoneDevice"];
118
+ toggleCameraEnabled: InstanceType<typeof LocalMedia>["toggleCameraEnabled"];
119
+ toggleMicrophoneEnabled: InstanceType<typeof LocalMedia>["toggleMichrophoneEnabled"];
120
+ }
121
+ type LocalMediaRef = {
122
+ state: LocalMediaState;
123
+ actions: LocalMediaActions;
124
+ _ref: LocalMedia;
125
+ };
126
+ declare function useLocalMedia(constraints?: MediaStreamConstraints): LocalMediaRef;
39
127
 
40
128
  interface RoomParticipantData {
41
129
  displayName: string;
@@ -66,39 +154,229 @@ declare class RemoteParticipant extends RoomParticipant {
66
154
  readonly newJoiner: boolean;
67
155
  readonly streams: Stream[];
68
156
  constructor({ displayName, id, newJoiner, streams, isAudioEnabled, isVideoEnabled, }: RoomParticipantData & RemoteParticipantData);
157
+ addStream(streamId: string, state: StreamState): void;
158
+ removeStream(streamId: string): void;
69
159
  updateStreamState(streamId: string, state: StreamState): void;
70
160
  }
71
161
  declare class LocalParticipant extends RoomParticipant {
72
162
  readonly isLocalParticipant = true;
73
163
  constructor({ displayName, id, stream, isAudioEnabled, isVideoEnabled }: RoomParticipantData);
164
+ }
165
+ interface WaitingParticipant {
166
+ id: string;
167
+ displayName: string | null;
168
+ }
169
+ declare class Screenshare {
170
+ readonly participantId: string;
171
+ readonly id: string;
172
+ readonly hasAudioTrack: boolean;
173
+ readonly stream?: MediaStream;
174
+ readonly isLocal: boolean;
175
+ constructor({ participantId, id, hasAudioTrack, stream, isLocal }: Screenshare);
74
176
  }
75
177
 
76
178
  type Logger = Pick<Console, "debug" | "error" | "log" | "warn">;
77
179
  interface RoomConnectionOptions {
78
180
  displayName?: string;
79
- localStream?: MediaStream;
80
181
  localMediaConstraints?: MediaStreamConstraints;
81
182
  roomKey?: string;
82
183
  logger?: Logger;
184
+ localMedia?: LocalMedia;
185
+ }
186
+ type ChatMessage = Pick<ChatMessage$1, "senderId" | "timestamp" | "text">;
187
+ type RoomConnectionStatus = "" | "connecting" | "connected" | "room_locked" | "knocking" | "disconnecting" | "disconnected" | "accepted" | "rejected";
188
+ type CloudRecordingState = {
189
+ status: "" | "recording";
190
+ startedAt: number | null;
191
+ };
192
+ type StreamingState = {
193
+ status: "" | "streaming";
194
+ startedAt: number | null;
195
+ };
196
+ type RoomJoinedEvent = {
197
+ localParticipant: LocalParticipant;
198
+ remoteParticipants: RemoteParticipant[];
199
+ waitingParticipants: WaitingParticipant[];
200
+ };
201
+ type RoomConnectionStatusChangedEvent = {
202
+ roomConnectionStatus: RoomConnectionStatus;
203
+ };
204
+ type ParticipantJoinedEvent = {
205
+ remoteParticipant: RemoteParticipant;
206
+ };
207
+ type ParticipantLeftEvent = {
208
+ participantId: string;
209
+ };
210
+ type ParticipantStreamAddedEvent = {
211
+ participantId: string;
212
+ stream: MediaStream;
213
+ };
214
+ type ParticipantAudioEnabledEvent = {
215
+ participantId: string;
216
+ isAudioEnabled: boolean;
217
+ };
218
+ type ParticipantVideoEnabledEvent = {
219
+ participantId: string;
220
+ isVideoEnabled: boolean;
221
+ };
222
+ type ParticipantMetadataChangedEvent = {
223
+ participantId: string;
224
+ displayName: string;
225
+ };
226
+ type ScreenshareStartedEvent = {
227
+ participantId: string;
228
+ id: string;
229
+ hasAudioTrack: boolean;
230
+ stream: MediaStream;
231
+ isLocal: boolean;
232
+ };
233
+ type ScreenshareStoppedEvent = {
234
+ participantId: string;
235
+ id: string;
236
+ };
237
+ type WaitingParticipantJoinedEvent = {
238
+ participantId: string;
239
+ displayName: string | null;
240
+ };
241
+ type WaitingParticipantLeftEvent = {
242
+ participantId: string;
243
+ };
244
+ interface RoomEventsMap {
245
+ chat_message: (e: CustomEvent<ChatMessage>) => void;
246
+ cloud_recording_started: (e: CustomEvent<CloudRecordingState>) => void;
247
+ cloud_recording_stopped: (e: CustomEvent<CloudRecordingState>) => void;
248
+ participant_audio_enabled: (e: CustomEvent<ParticipantAudioEnabledEvent>) => void;
249
+ participant_joined: (e: CustomEvent<ParticipantJoinedEvent>) => void;
250
+ participant_left: (e: CustomEvent<ParticipantLeftEvent>) => void;
251
+ participant_metadata_changed: (e: CustomEvent<ParticipantMetadataChangedEvent>) => void;
252
+ participant_stream_added: (e: CustomEvent<ParticipantStreamAddedEvent>) => void;
253
+ participant_video_enabled: (e: CustomEvent<ParticipantVideoEnabledEvent>) => void;
254
+ room_connection_status_changed: (e: CustomEvent<RoomConnectionStatusChangedEvent>) => void;
255
+ room_joined: (e: CustomEvent<RoomJoinedEvent>) => void;
256
+ screenshare_started: (e: CustomEvent<ScreenshareStartedEvent>) => void;
257
+ screenshare_stopped: (e: CustomEvent<ScreenshareStoppedEvent>) => void;
258
+ streaming_started: (e: CustomEvent<StreamingState>) => void;
259
+ streaming_stopped: (e: CustomEvent<StreamingState>) => void;
260
+ waiting_participant_joined: (e: CustomEvent<WaitingParticipantJoinedEvent>) => void;
261
+ waiting_participant_left: (e: CustomEvent<WaitingParticipantLeftEvent>) => void;
262
+ }
263
+ interface RoomEventTarget extends EventTarget {
264
+ addEventListener<K extends keyof RoomEventsMap>(type: K, listener: RoomEventsMap[K], options?: boolean | AddEventListenerOptions): void;
265
+ addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
266
+ removeEventListener<K extends keyof RoomEventsMap>(type: K, listener: RoomEventsMap[K], options?: boolean | EventListenerOptions): void;
267
+ removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
268
+ }
269
+ declare const TypedEventTarget: new () => RoomEventTarget;
270
+ declare class RoomConnection extends TypedEventTarget {
271
+ localMedia: LocalMedia;
272
+ localParticipant: LocalParticipant | null;
273
+ roomUrl: URL;
274
+ remoteParticipants: RemoteParticipant[];
275
+ screenshares: Screenshare[];
276
+ readonly localMediaConstraints?: MediaStreamConstraints;
277
+ readonly roomName: string;
278
+ private organizationId;
279
+ private credentialsService;
280
+ private apiClient;
281
+ private organizationService;
282
+ private organizationServiceCache;
283
+ private organizationApiClient;
284
+ private roomService;
285
+ private _deviceCredentials;
286
+ private signalSocket;
287
+ private signalSocketManager;
288
+ private rtcManagerDispatcher?;
289
+ private rtcManager?;
290
+ private roomConnectionStatus;
291
+ private selfId;
292
+ private logger;
293
+ private _ownsLocalMedia;
294
+ private displayName?;
295
+ private _roomKey;
296
+ constructor(roomUrl: string, { displayName, localMedia, localMediaConstraints, logger, roomKey }: RoomConnectionOptions);
297
+ get roomKey(): string | null;
298
+ private _handleNewChatMessage;
299
+ private _handleCloudRecordingStarted;
300
+ private _handleStreamingStarted;
301
+ private _handleNewClient;
302
+ private _handleClientLeft;
303
+ private _handleClientAudioEnabled;
304
+ private _handleClientVideoEnabled;
305
+ private _handleClientMetadataReceived;
306
+ private _handleKnockHandled;
307
+ private _handleKnockerLeft;
308
+ private _handleRoomJoined;
309
+ private _handleRoomKnocked;
310
+ private _handleReconnect;
311
+ private _handleDisconnect;
312
+ private _handleCloudRecordingStopped;
313
+ private _handleStreamingStopped;
314
+ private _handleScreenshareStarted;
315
+ private _handleScreenshareStopped;
316
+ private _handleRtcEvent;
317
+ private _handleRtcManagerCreated;
318
+ private _handleRtcManagerDestroyed;
319
+ private _handleAcceptStreams;
320
+ private _handleStreamAdded;
321
+ private _joinRoom;
322
+ join(): Promise<void>;
323
+ knock(): void;
324
+ leave(): void;
325
+ sendChatMessage(text: string): void;
326
+ setDisplayName(displayName: string): void;
327
+ acceptWaitingParticipant(participantId: string): void;
328
+ rejectWaitingParticipant(participantId: string): void;
329
+ updateStreamResolution({ streamId, width, height }: {
330
+ streamId?: string;
331
+ width: number;
332
+ height: number;
333
+ }): void;
334
+ startScreenshare(): Promise<void>;
335
+ stopScreenshare(): void;
83
336
  }
84
337
 
85
338
  type RemoteParticipantState = Omit<RemoteParticipant, "updateStreamState">;
86
- interface RoomState {
339
+ interface RoomConnectionState {
340
+ chatMessages: ChatMessage[];
341
+ cloudRecording: CloudRecordingState;
342
+ isJoining: boolean;
343
+ isStartingScreenshare: boolean;
344
+ joinError: unknown;
345
+ startScreenshareError: unknown;
87
346
  localParticipant?: LocalParticipant;
88
- roomConnectionStatus?: "connecting" | "connected" | "disconnected";
347
+ mostRecentChatMessage: ChatMessage | null;
89
348
  remoteParticipants: RemoteParticipantState[];
90
- }
91
-
349
+ screenshares: Screenshare[];
350
+ roomConnectionStatus: RoomConnectionStatus;
351
+ streaming: StreamingState;
352
+ waitingParticipants: WaitingParticipant[];
353
+ }
354
+ interface UseRoomConnectionOptions extends Omit<RoomConnectionOptions, "localMedia"> {
355
+ localMedia?: LocalMediaRef;
356
+ }
92
357
  interface RoomConnectionActions {
358
+ sendChatMessage(text: string): void;
359
+ knock(): void;
360
+ setDisplayName(displayName: string): void;
93
361
  toggleCamera(enabled?: boolean): void;
94
362
  toggleMicrophone(enabled?: boolean): void;
95
- setDisplayName(displayName: string): void;
363
+ acceptWaitingParticipant(participantId: string): void;
364
+ rejectWaitingParticipant(participantId: string): void;
365
+ startScreenshare(): void;
366
+ stopScreenshare(): void;
96
367
  }
368
+ type VideoViewComponentProps = Omit<React.ComponentProps<typeof _default>, "onResize">;
97
369
  interface RoomConnectionComponents {
98
- VideoView: typeof _default;
370
+ VideoView: (props: VideoViewComponentProps) => ReturnType<typeof _default>;
99
371
  }
100
- declare function useRoomConnection(roomUrl: string, roomConnectionOptions: RoomConnectionOptions): [state: RoomState, actions: RoomConnectionActions, components: RoomConnectionComponents];
372
+ type RoomConnectionRef = {
373
+ state: RoomConnectionState;
374
+ actions: RoomConnectionActions;
375
+ components: RoomConnectionComponents;
376
+ _ref: RoomConnection;
377
+ };
378
+ declare function useRoomConnection(roomUrl: string, roomConnectionOptions: UseRoomConnectionOptions): RoomConnectionRef;
101
379
 
102
- declare const sdkVersion = "2.0.0-alpha2";
380
+ declare const sdkVersion = "2.0.0-alpha21";
103
381
 
104
- export { sdkVersion, useRoomConnection };
382
+ export { _default as VideoView, sdkVersion, useLocalMedia, useRoomConnection };