|
1 |
| -/** 1.5.4 */ |
2 |
| - |
3 |
| -// eslint-disable-next-line no-undef |
| 1 | +/** 1.6.0 */ |
| 2 | +// eslint-disable-next-line no-undef,max-classes-per-file |
4 | 3 | export as namespace SendBirdCall;
|
5 | 4 |
|
6 | 5 | export function init(appId: string): void;
|
@@ -37,6 +36,9 @@ export function handleWebhookData(data: WebhookData): void;
|
37 | 36 | export function addDirectCallSound(type: SoundType, url: string): Promise<boolean>;
|
38 | 37 | export function removeDirectCallSound(type: SoundType): boolean;
|
39 | 38 | export function getCall(callId: string): DirectCall;
|
| 39 | +export function createRoom(params: RoomParams): Promise<Room>; |
| 40 | +export function getCachedRoomById(roomId: string): Room; |
| 41 | +export function fetchRoomById(roomId: string): Promise<Room>; |
40 | 42 | export const sdkVersion: string;
|
41 | 43 | export const appId: string;
|
42 | 44 | export const currentUser: User;
|
@@ -101,6 +103,15 @@ export enum ErrorCode {
|
101 | 103 | INTERNAL_SERVER_ERROR= 1800207,
|
102 | 104 | ERR_MALFORMED_DATA= 1800208,
|
103 | 105 |
|
| 106 | + // Room |
| 107 | + ERR_PARTICIPANT_ALREADY_IN_ROOM = 1800700, |
| 108 | + ERR_ENTERING_ROOM_STILL_IN_PROGRESS = 1800701, |
| 109 | + ERR_PARTICIPANT_NOT_IN_ROOM = 1800702, |
| 110 | + ERR_EXITING_ROOM_STILL_IN_PROGRESS = 1800703, |
| 111 | + ERR_FAILED_TO_ESTABLISH_CONNECTION_TO_SEND_STREAM = 1800704, |
| 112 | + ERR_FAILED_TO_ESTABLISH_CONNECTION_TO_RECEIVE_STREAM = 1800705, |
| 113 | + ERR_LOCAL_PARTICIPANT_LOST_CONNECTION = 1800706, |
| 114 | + |
104 | 115 | // Error for take snapshot
|
105 | 116 | ERR_CAPTURE_NOT_ALLOWED_ON_AUDIO_CALL = 1800600,
|
106 | 117 | ERR_VIDEO_VIEW_NOT_READY = 1800601,
|
@@ -132,20 +143,91 @@ export enum ErrorCode {
|
132 | 143 | ERR_NOT_SUPPORTED_BROWSER_FOR_RECORDING = 1800616,
|
133 | 144 | ERR_INVALID_RECORDING_TYPE = 1800617,
|
134 | 145 | ERR_NOT_SUPPORTED_OS_VERSION_FOR_RECORDING = 1800618,
|
| 146 | + |
| 147 | + // screen share |
| 148 | + ERR_SCREEN_SHARE_RESTRICTED_FROM_AUDIO_CALL = 1800620, |
| 149 | + ERR_SCREEN_SHARE_REQUEST_BEFORE_CALL_IS_CONNECTED = 1800621, |
| 150 | + ERR_SCREEN_SHARE_ALREADY_IN_PROGRESS = 1800622, |
| 151 | + ERR_NO_SCREEN_SHARE_EXISTS = 1800623, |
| 152 | + ERR_NOT_SUPPORTED_BROWSER_FOR_SCREEN_SHARE = 1800625, |
| 153 | + ERR_SCREEN_SHARE_FAILED_DUE_TO_UNKNOWN_REASON = 1800626, |
| 154 | + ERR_NOT_SUPPORTED_APP_STATE_FOR_SCREEN_SHARE = 1800627, |
| 155 | + ERR_PERMISSION_DENIED_FOR_SCREEN_SHARE = 1800628, |
| 156 | + ERR_SELECTED_CONTENT_NOT_EXIST = 1800629, |
| 157 | + ERR_SELECTED_CONTENT_INACCESSIBLE = 1800630, |
| 158 | + |
135 | 159 | }
|
136 | 160 |
|
137 | 161 | export interface SendBirdCallListener {
|
138 |
| - onRinging: ((directCall: DirectCall) => void) | null; |
139 |
| - onAudioInputDeviceChanged: ((currentAudioInputDevice: InputDeviceInfo, availableAudioInputDevices: InputDeviceInfo[]) => void) | null; |
140 |
| - onAudioOutputDeviceChanged: ((currentAudioOutputDevice: MediaDeviceInfo, availableAudioOutputDevices: MediaDeviceInfo[]) => void) | null; |
141 |
| - onVideoInputDeviceChanged: ((currentVideoInputDevice: InputDeviceInfo, availableVideoInputDevices: InputDeviceInfo[]) => void) | null; |
| 162 | + onRinging?: ((directCall: DirectCall) => void) | null; |
| 163 | + onAudioInputDeviceChanged?: ((currentAudioInputDevice: InputDeviceInfo, availableAudioInputDevices: InputDeviceInfo[]) => void) | null; |
| 164 | + onAudioOutputDeviceChanged?: ((currentAudioOutputDevice: MediaDeviceInfo, availableAudioOutputDevices: MediaDeviceInfo[]) => void) | null; |
| 165 | + onVideoInputDeviceChanged?: ((currentVideoInputDevice: InputDeviceInfo, availableVideoInputDevices: InputDeviceInfo[]) => void) | null; |
142 | 166 | }
|
143 | 167 |
|
144 | 168 | export interface SendBirdCallRecordingListener {
|
145 | 169 | onRecordingSucceeded: ((callId: string, recordingId: string, options: DirectCallRecordOption, fileName?: string) => void) | null;
|
146 | 170 | onRecordingFailed: ((callId: string, recordingId: string, error) => void) | null;
|
147 | 171 | }
|
148 | 172 |
|
| 173 | +/** |
| 174 | + * Event Target |
| 175 | + */ |
| 176 | + |
| 177 | +interface Event { |
| 178 | + readonly args?: any[]; |
| 179 | +} |
| 180 | + |
| 181 | +declare type nullish = null | undefined; |
| 182 | + |
| 183 | +declare type ArgsType<T extends Event> = T['args'] extends nullish ? [] : T['args']; |
| 184 | + |
| 185 | +interface EventListener<T extends Event> { |
| 186 | + (...args: ArgsType<T>): void; |
| 187 | +} |
| 188 | + |
| 189 | +declare type EventMap = Record<string, Event>; |
| 190 | + |
| 191 | +declare type EventKey<T extends EventMap> = keyof T; |
| 192 | + |
| 193 | +declare class EventTarget<T extends EventMap> { |
| 194 | + |
| 195 | + /** |
| 196 | + * Adds a listener to receive events. |
| 197 | + */ |
| 198 | + addEventListener<K extends EventKey<T>>(type: K, callback: EventListener<T[K]>): void; |
| 199 | + |
| 200 | + /** |
| 201 | + * Alias for addEventListener |
| 202 | + */ |
| 203 | + on: <K extends keyof T>(type: K, callback: EventListener<T[K]>) => void; |
| 204 | + |
| 205 | + /** |
| 206 | + * Adds listener to receive events once. |
| 207 | + */ |
| 208 | + once<K extends EventKey<T>>(type: K, givenCb: EventListener<T[K]>): void; |
| 209 | + |
| 210 | + /** |
| 211 | + * Removes an added listener. |
| 212 | + */ |
| 213 | + removeEventListener<K extends EventKey<T>>(type: K, callback: EventListener<T[K]>): void; |
| 214 | + |
| 215 | + /** |
| 216 | + * Alias for removeEventListener |
| 217 | + */ |
| 218 | + off: <K extends keyof T>(type: K, callback: EventListener<T[K]>) => void; |
| 219 | + |
| 220 | + /** |
| 221 | + * Removes all added listeners. |
| 222 | + */ |
| 223 | + removeAllEventListeners(): void; |
| 224 | + |
| 225 | +} |
| 226 | + |
| 227 | +/** |
| 228 | + * DirectCall |
| 229 | + */ |
| 230 | + |
149 | 231 | export interface DirectCall {
|
150 | 232 | onEstablished: ((call: DirectCall) => void) | null;
|
151 | 233 | onConnected: ((call: DirectCall) => void) | null;
|
@@ -344,3 +426,221 @@ export interface WebhookData {
|
344 | 426 | [key: string]: any;
|
345 | 427 | }
|
346 | 428 | /* eslint-enable babel/camelcase */
|
| 429 | + |
| 430 | + |
| 431 | +/** |
| 432 | + * Room |
| 433 | + */ |
| 434 | + |
| 435 | +declare type RoomEventMap = { |
| 436 | + remoteParticipantEntered: { args: [RemoteParticipant]; }; |
| 437 | + remoteParticipantExited: { args: [RemoteParticipant]; }; |
| 438 | + remoteParticipantStreamStarted: { args: [RemoteParticipant]; }; |
| 439 | + remoteAudioSettingsChanged: { args: [RemoteParticipant]; }; |
| 440 | + remoteVideoSettingsChanged: { args: [RemoteParticipant]; }; |
| 441 | + error: { args: [Error, Participant?] }; |
| 442 | +}; |
| 443 | + |
| 444 | +/** |
| 445 | + * Called when remote participant has been entered |
| 446 | + */ |
| 447 | +export type RemoteParticipantEnteredEventListener = (participant: RemoteParticipant) => void; |
| 448 | +/** |
| 449 | + * Called when remote participant has been exited |
| 450 | + */ |
| 451 | +export type RemoteParticipantExitedEventListener = (participant: RemoteParticipant) => void; |
| 452 | +/** |
| 453 | + * Called when it's able to receive media stream from remote participant. |
| 454 | + */ |
| 455 | +export type RemoteParticipantStreamStartedEventListener = (participant: RemoteParticipant) => void; |
| 456 | +/** |
| 457 | + * Called when audio settings of remote participant has been changed |
| 458 | + */ |
| 459 | +export type RemoteAudioSettingsChangedEventListener = (participant: RemoteParticipant) => void; |
| 460 | +/** |
| 461 | + * Called when video settings of remote participant has been changed. |
| 462 | + */ |
| 463 | +export type RemoteVideoSettingsChangedEventListener = (participant: RemoteParticipant) => void; |
| 464 | + |
| 465 | +export enum RoomType { |
| 466 | + /** |
| 467 | + * Type of a room that supports audio and video, can have up to 6 participants. |
| 468 | + */ |
| 469 | + LARGE_ROOM_FOR_AUDIO_ONLY = 'large_room_for_audio_only', |
| 470 | + /** |
| 471 | + * Type of a room that only supports audio and can have up to 20 participants. |
| 472 | + */ |
| 473 | + SMALL_ROOM_FOR_VIDEO = 'small_room_for_video', |
| 474 | +} |
| 475 | + |
| 476 | +export declare class Room extends EventTarget<RoomEventMap> { |
| 477 | + |
| 478 | + /** |
| 479 | + * The ID of room |
| 480 | + */ |
| 481 | + readonly roomId: string; |
| 482 | + |
| 483 | + /** |
| 484 | + * Room type |
| 485 | + */ |
| 486 | + readonly roomType: RoomType; |
| 487 | + |
| 488 | + /** |
| 489 | + * Long value of the date when the room created at. |
| 490 | + */ |
| 491 | + readonly createdAt: number; |
| 492 | + |
| 493 | + /** |
| 494 | + * The ID of user who created the room |
| 495 | + */ |
| 496 | + readonly createdBy: string; |
| 497 | + |
| 498 | + /** |
| 499 | + * The list of all participants including local participant. |
| 500 | + */ |
| 501 | + readonly participants: Participant[]; |
| 502 | + |
| 503 | + /** |
| 504 | + * The local participant. |
| 505 | + */ |
| 506 | + readonly localParticipant: LocalParticipant; |
| 507 | + |
| 508 | + /** |
| 509 | + * The list of remote participants. |
| 510 | + */ |
| 511 | + readonly remoteParticipants: RemoteParticipant[]; |
| 512 | + |
| 513 | + /** |
| 514 | + * Enters a room |
| 515 | + */ |
| 516 | + enter(params: EnterParams): Promise<void>; |
| 517 | + |
| 518 | + /** |
| 519 | + * Exits a room |
| 520 | + */ |
| 521 | + exit(): void; |
| 522 | + |
| 523 | + /** |
| 524 | + * Sets audio for a large room |
| 525 | + */ |
| 526 | + setAudioForLargeRoom(mediaView: HTMLAudioElement): Promise<void>; |
| 527 | + |
| 528 | +} |
| 529 | + |
| 530 | +export type RoomParams = { |
| 531 | + /** |
| 532 | + * An enum that represents different types of a room. |
| 533 | + */ |
| 534 | + roomType: RoomType; |
| 535 | +} |
| 536 | + |
| 537 | +/** |
| 538 | + * A class that provides the methods to enable audio and video settings. |
| 539 | + */ |
| 540 | +export interface EnterParams { |
| 541 | + /** |
| 542 | + * Enables a participant's audio settings when entering a room. |
| 543 | + */ |
| 544 | + audioEnabled: boolean; |
| 545 | + /** |
| 546 | + * Enables a participant's video settings when entering a room. |
| 547 | + */ |
| 548 | + videoEnabled: boolean; |
| 549 | +} |
| 550 | + |
| 551 | +export enum ParticipantState { |
| 552 | + /** |
| 553 | + * The state when the participant has entered room |
| 554 | + */ |
| 555 | + ENTERED = 'entered', |
| 556 | + /** |
| 557 | + * The state when the participant has been connected. |
| 558 | + */ |
| 559 | + CONNECTED = 'connected', |
| 560 | + /** |
| 561 | + * The state when the participant has exit room |
| 562 | + */ |
| 563 | + EXITED = 'exited', |
| 564 | +} |
| 565 | + |
| 566 | +export interface Participant { |
| 567 | + /** |
| 568 | + * A unique identifier for a participant in a room. |
| 569 | + */ |
| 570 | + participantId: string; |
| 571 | + |
| 572 | + /** |
| 573 | + * The timestamp of when the participant enters the room, in Unix milliseconds. |
| 574 | + */ |
| 575 | + enteredAt: number; |
| 576 | + |
| 577 | + /** |
| 578 | + * The timestamp of when the participant information was updated within the room, in Unix milliseconds. |
| 579 | + */ |
| 580 | + updatedAt: number; |
| 581 | + |
| 582 | + /** |
| 583 | + * The timestamp of when the participant exited the room, in Unix milliseconds. |
| 584 | + */ |
| 585 | + exitedAt?: number; |
| 586 | + |
| 587 | + /** |
| 588 | + * The period from the time when the participant entered the room to the time the participant left the room, measured in seconds. |
| 589 | + */ |
| 590 | + duration?: number; |
| 591 | + |
| 592 | + /** |
| 593 | + * The state of the participant. Valid values are entered, exited, and connected. |
| 594 | + */ |
| 595 | + state: ParticipantState; |
| 596 | + |
| 597 | + /** |
| 598 | + * Indicates a user in Calls who corresponds to the participant. |
| 599 | + */ |
| 600 | + user: User; |
| 601 | + |
| 602 | + /** |
| 603 | + * Indicates whether the participant has enabled their audio. |
| 604 | + */ |
| 605 | + isAudioEnabled: boolean; |
| 606 | + |
| 607 | + /** |
| 608 | + * Indicates whether the participant has enabled their video. |
| 609 | + */ |
| 610 | + isVideoEnabled: boolean; |
| 611 | + |
| 612 | + setMediaView(mediaView: HTMLMediaElement): Promise<void>; |
| 613 | +} |
| 614 | + |
| 615 | +export interface LocalParticipant extends Participant { |
| 616 | + readonly isLocalParticipant: true; |
| 617 | + |
| 618 | + /** |
| 619 | + * Alias for setMediaView |
| 620 | + */ |
| 621 | + setLocalMediaView(mediaView: HTMLMediaElement): Promise<void>; |
| 622 | + |
| 623 | + /** |
| 624 | + * Stop the local audio. |
| 625 | + */ |
| 626 | + muteMicrophone(): void; |
| 627 | + /** |
| 628 | + * Start the local audio. |
| 629 | + */ |
| 630 | + unmuteMicrophone(): void; |
| 631 | + |
| 632 | + /** |
| 633 | + * Start the local video. |
| 634 | + */ |
| 635 | + stopVideo(): void; |
| 636 | + |
| 637 | + /** |
| 638 | + * Stop the local video. |
| 639 | + */ |
| 640 | + startVideo(): void; |
| 641 | + |
| 642 | +} |
| 643 | + |
| 644 | +export interface RemoteParticipant extends Participant { |
| 645 | + readonly isLocalParticipant: false; |
| 646 | +} |
0 commit comments