@coze/realtime-api 0.0.3 → 1.0.0
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/README.md +6 -0
- package/dist/cjs/index.cjs +42074 -0
- package/dist/cjs/index.cjs.LICENSE.txt +1 -0
- package/dist/esm/index.js +42058 -0
- package/dist/esm/index.js.LICENSE.txt +1 -0
- package/dist/{client.d.ts → types/client.d.ts} +8 -2
- package/dist/{error.d.ts → types/error.d.ts} +10 -2
- package/dist/{event-handler.d.ts → types/event-handler.d.ts} +26 -1
- package/dist/{index.d.ts → types/index.d.ts} +7 -1
- package/dist/{utils.d.ts → types/utils.d.ts} +6 -1
- package/dist/umd/index.js +42077 -0
- package/dist/umd/index.js.LICENSE.txt +1 -0
- package/package.json +27 -10
- package/dist/client.js +0 -242
- package/dist/error.js +0 -36
- package/dist/event-handler.js +0 -126
- package/dist/index.js +0 -258
- package/dist/utils.js +0 -40
@@ -0,0 +1 @@
|
|
1
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
@@ -1,27 +1,33 @@
|
|
1
1
|
import { type AudioPropertiesConfig, type onUserJoinedEvent, type onUserLeaveEvent, type UserMessageEvent } from '@volcengine/rtc';
|
2
2
|
import { RealtimeEventHandler } from './event-handler';
|
3
|
+
import { type VideoConfig } from '.';
|
3
4
|
export declare class EngineClient extends RealtimeEventHandler {
|
4
5
|
private engine;
|
5
6
|
private joinUserId;
|
6
7
|
private _AIAnsExtension;
|
7
|
-
|
8
|
+
private _isSupportVideo;
|
9
|
+
constructor(appId: string, debug?: boolean, isTestEnv?: boolean, isSupportVideo?: boolean);
|
8
10
|
bindEngineEvents(): void;
|
9
11
|
removeEventListener(): void;
|
12
|
+
_parseMessage(event: UserMessageEvent): any;
|
10
13
|
handleMessage(event: UserMessageEvent): void;
|
11
14
|
handleEventError(e: unknown): void;
|
12
15
|
handleUserJoin(event: onUserJoinedEvent): void;
|
13
16
|
handleUserLeave(event: onUserLeaveEvent): void;
|
17
|
+
handlePlayerEvent(event: unknown): void;
|
14
18
|
joinRoom(options: {
|
15
19
|
token: string;
|
16
20
|
roomId: string;
|
17
21
|
uid: string;
|
18
22
|
audioMutedDefault?: boolean;
|
23
|
+
videoOnDefault?: boolean;
|
19
24
|
}): Promise<void>;
|
20
25
|
setAudioInputDevice(deviceId: string): Promise<void>;
|
21
26
|
setAudioOutputDevice(deviceId: string): Promise<void>;
|
22
|
-
createLocalStream(): Promise<void>;
|
27
|
+
createLocalStream(userId?: string, videoConfig?: VideoConfig): Promise<void>;
|
23
28
|
disconnect(): Promise<void>;
|
24
29
|
changeAudioState(isMicOn: boolean): Promise<void>;
|
30
|
+
changeVideoState(isVideoOn: boolean): Promise<void>;
|
25
31
|
stop(): Promise<void>;
|
26
32
|
sendMessage(message: Record<string, unknown>): Promise<void>;
|
27
33
|
enableAudioPropertiesReport(config?: AudioPropertiesConfig): void;
|
@@ -8,10 +8,18 @@ export declare enum RealtimeError {
|
|
8
8
|
PERMISSION_DENIED = "PERMISSION_DENIED",
|
9
9
|
NETWORK_ERROR = "NETWORK_ERROR",
|
10
10
|
INVALID_STATE = "INVALID_STATE",
|
11
|
-
CREATE_ROOM_ERROR = "CREATE_ROOM_ERROR"
|
11
|
+
CREATE_ROOM_ERROR = "CREATE_ROOM_ERROR",
|
12
|
+
PARSE_MESSAGE_ERROR = "PARSE_MESSAGE_ERROR",
|
13
|
+
HANDLER_MESSAGE_ERROR = "HANDLER_MESSAGE_ERROR"
|
12
14
|
}
|
13
15
|
export declare const ErrorMessages: Record<RealtimeError, string>;
|
14
16
|
export declare class RealtimeAPIError extends Error {
|
15
17
|
code: RealtimeError;
|
16
|
-
|
18
|
+
error?: unknown;
|
19
|
+
/**
|
20
|
+
* @param code - Error code
|
21
|
+
* @param message - Error message
|
22
|
+
* @param error - Error object
|
23
|
+
*/
|
24
|
+
constructor(code: RealtimeError, message: string, error?: unknown);
|
17
25
|
}
|
@@ -39,6 +39,21 @@ export declare enum EventNames {
|
|
39
39
|
* zh: 客户端音频静音
|
40
40
|
*/
|
41
41
|
AUDIO_MUTED = "client.audio.muted",
|
42
|
+
/**
|
43
|
+
* en: Client video on
|
44
|
+
* zh: 客户端视频开启
|
45
|
+
*/
|
46
|
+
VIDEO_ON = "client.video.on",
|
47
|
+
/**
|
48
|
+
* en: Client video off
|
49
|
+
* zh: 客户端视频关闭
|
50
|
+
*/
|
51
|
+
VIDEO_OFF = "client.video.off",
|
52
|
+
/**
|
53
|
+
* en: Client video event
|
54
|
+
* zh: 客户端视频事件
|
55
|
+
*/
|
56
|
+
PLAYER_EVENT = "client.video.event",
|
42
57
|
/**
|
43
58
|
* en: Client error
|
44
59
|
* zh: 客户端错误
|
@@ -63,7 +78,17 @@ export declare enum EventNames {
|
|
63
78
|
* en: Audio output device changed
|
64
79
|
* zh: 音频输出设备改变
|
65
80
|
*/
|
66
|
-
AUDIO_OUTPUT_DEVICE_CHANGED = "client.output.device.changed"
|
81
|
+
AUDIO_OUTPUT_DEVICE_CHANGED = "client.output.device.changed",
|
82
|
+
/**
|
83
|
+
* en: Bot joined
|
84
|
+
* zh: Bot 加入
|
85
|
+
*/
|
86
|
+
BOT_JOIN = "server.bot.join",
|
87
|
+
/**
|
88
|
+
* en: Bot left
|
89
|
+
* zh: Bot 离开
|
90
|
+
*/
|
91
|
+
BOT_LEAVE = "server.bot.leave"
|
67
92
|
}
|
68
93
|
type EventCallback = (eventName: string, event: unknown) => void;
|
69
94
|
export declare class RealtimeEventHandler {
|
@@ -2,6 +2,10 @@ import { type AudioPropertiesConfig } from '@volcengine/rtc';
|
|
2
2
|
import * as RealtimeUtils from './utils';
|
3
3
|
import { RealtimeEventHandler, EventNames } from './event-handler';
|
4
4
|
import { RealtimeAPIError, RealtimeError } from './error';
|
5
|
+
export interface VideoConfig {
|
6
|
+
videoOnDefault?: boolean /** optional, Whether to turn on video by default, defaults to true */;
|
7
|
+
renderDom?: string /** optional, The DOM element to render the video stream to */;
|
8
|
+
}
|
5
9
|
export interface RealtimeClientConfig {
|
6
10
|
accessToken: string /** required, Access Token */;
|
7
11
|
botId: string /** required, Bot Id */;
|
@@ -17,14 +21,15 @@ export interface RealtimeClientConfig {
|
|
17
21
|
connectorId: string /** required, Connector Id */;
|
18
22
|
suppressStationaryNoise?: boolean /** optional, Suppress stationary noise, defaults to false */;
|
19
23
|
suppressNonStationaryNoise?: boolean /** optional, Suppress non-stationary noise, defaults to false */;
|
24
|
+
videoConfig?: VideoConfig /** optional, Video configuration */;
|
20
25
|
}
|
21
26
|
declare class RealtimeClient extends RealtimeEventHandler {
|
22
27
|
private _config;
|
23
28
|
private _client;
|
24
|
-
private _roomInfo;
|
25
29
|
isConnected: boolean;
|
26
30
|
private _api;
|
27
31
|
private _isTestEnv;
|
32
|
+
_isSupportVideo: boolean;
|
28
33
|
/**
|
29
34
|
* Constructor for initializing a RealtimeClient instance.
|
30
35
|
*
|
@@ -86,6 +91,7 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
86
91
|
* zh: 启用或禁用音频
|
87
92
|
*/
|
88
93
|
setAudioEnable(isEnable: boolean): Promise<void>;
|
94
|
+
setVideoEnable(isEnable: boolean): Promise<void>;
|
89
95
|
/**
|
90
96
|
* en: Enable audio properties reporting (debug mode only)
|
91
97
|
*
|
@@ -8,7 +8,10 @@ export declare const sleep: (milliseconds: number) => Promise<void>;
|
|
8
8
|
/**
|
9
9
|
* Check microphone permission,return boolean
|
10
10
|
*/
|
11
|
-
export declare const checkPermission: (
|
11
|
+
export declare const checkPermission: ({ audio, video, }?: {
|
12
|
+
audio?: boolean;
|
13
|
+
video?: boolean;
|
14
|
+
}) => Promise<boolean>;
|
12
15
|
/**
|
13
16
|
* Get audio devices
|
14
17
|
* @returns Promise<AudioDevices> Object containing arrays of audio input and output devices
|
@@ -16,4 +19,6 @@ export declare const checkPermission: () => Promise<boolean>;
|
|
16
19
|
export declare const getAudioDevices: () => Promise<{
|
17
20
|
audioInputs: MediaDeviceInfo[];
|
18
21
|
audioOutputs: MediaDeviceInfo[];
|
22
|
+
videoInputs: MediaDeviceInfo[];
|
23
|
+
videoOutputs: MediaDeviceInfo[];
|
19
24
|
}>;
|