@coze/realtime-api 1.0.3 → 1.0.4
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/README.zh-CN.md +104 -0
- package/dist/cjs/index.cjs +273 -31
- package/dist/esm/index.js +273 -31
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/client.d.ts +5 -1
- package/dist/types/event-handler.d.ts +5 -0
- package/dist/types/index.d.ts +14 -1
- package/dist/types/utils.d.ts +11 -0
- package/dist/umd/index.js +273 -31
- package/package.json +6 -10
- package/assets/api-overview.png +0 -0
package/dist/esm/index.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
2
2
|
var __webpack_modules__ = {
|
3
|
-
"?
|
3
|
+
"?e272": function() {
|
4
4
|
/* (ignored) */ },
|
5
|
-
"?
|
5
|
+
"?5742": function() {
|
6
6
|
/* (ignored) */ },
|
7
|
-
"?
|
7
|
+
"?9caf": function() {
|
8
8
|
/* (ignored) */ }
|
9
9
|
};
|
10
10
|
/************************************************************************/ // The module cache
|
@@ -68,7 +68,7 @@ __webpack_require__.d(common_utils_namespaceObject, {
|
|
68
68
|
hasBrowserEnv: ()=>hasBrowserEnv,
|
69
69
|
hasStandardBrowserEnv: ()=>hasStandardBrowserEnv,
|
70
70
|
hasStandardBrowserWebWorkerEnv: ()=>hasStandardBrowserWebWorkerEnv,
|
71
|
-
navigator: ()=>
|
71
|
+
navigator: ()=>utils_navigator,
|
72
72
|
origin: ()=>origin
|
73
73
|
});
|
74
74
|
// NAMESPACE OBJECT: ./src/utils.ts
|
@@ -78,6 +78,8 @@ __webpack_require__.d(src_utils_namespaceObject, {
|
|
78
78
|
checkDevicePermission: ()=>checkDevicePermission,
|
79
79
|
checkPermission: ()=>checkPermission,
|
80
80
|
getAudioDevices: ()=>getAudioDevices,
|
81
|
+
isScreenShareDevice: ()=>isScreenShareDevice,
|
82
|
+
isScreenShareSupported: ()=>isScreenShareSupported,
|
81
83
|
sleep: ()=>utils_sleep
|
82
84
|
});
|
83
85
|
function bind(fn, thisArg) {
|
@@ -1040,7 +1042,7 @@ class InterceptorManager_InterceptorManager {
|
|
1040
1042
|
]
|
1041
1043
|
};
|
1042
1044
|
const hasBrowserEnv = 'undefined' != typeof window && 'undefined' != typeof document;
|
1043
|
-
const
|
1045
|
+
const utils_navigator = 'object' == typeof navigator && navigator || void 0;
|
1044
1046
|
/**
|
1045
1047
|
* Determine if we're running in a standard browser environment
|
1046
1048
|
*
|
@@ -1057,11 +1059,11 @@ const _navigator = 'object' == typeof navigator && navigator || void 0;
|
|
1057
1059
|
* navigator.product -> 'NativeScript' or 'NS'
|
1058
1060
|
*
|
1059
1061
|
* @returns {boolean}
|
1060
|
-
*/ const hasStandardBrowserEnv = hasBrowserEnv && (!
|
1062
|
+
*/ const hasStandardBrowserEnv = hasBrowserEnv && (!utils_navigator || [
|
1061
1063
|
'ReactNative',
|
1062
1064
|
'NativeScript',
|
1063
1065
|
'NS'
|
1064
|
-
].indexOf(
|
1066
|
+
].indexOf(utils_navigator.product) < 0);
|
1065
1067
|
/**
|
1066
1068
|
* Determine if we're running in a standard browser webWorker environment
|
1067
1069
|
*
|
@@ -2846,11 +2848,11 @@ axios.default = axios;
|
|
2846
2848
|
// so that it can keep same with es module or cjs
|
2847
2849
|
const { Axios: axios_Axios, AxiosError: axios_AxiosError, CanceledError: axios_CanceledError, isCancel: axios_isCancel, CancelToken: axios_CancelToken, VERSION: axios_VERSION, all: axios_all, Cancel, isAxiosError: axios_isAxiosError, spread: axios_spread, toFormData: axios_toFormData, AxiosHeaders: axios_AxiosHeaders, HttpStatusCode: axios_HttpStatusCode, formToJSON, getAdapter, mergeConfig: axios_mergeConfig } = lib_axios;
|
2848
2850
|
// EXTERNAL MODULE: os (ignored)
|
2849
|
-
var os_ignored_ = __webpack_require__("?
|
2851
|
+
var os_ignored_ = __webpack_require__("?9caf");
|
2850
2852
|
// EXTERNAL MODULE: crypto (ignored)
|
2851
|
-
__webpack_require__("?
|
2853
|
+
__webpack_require__("?e272");
|
2852
2854
|
// EXTERNAL MODULE: jsonwebtoken (ignored)
|
2853
|
-
__webpack_require__("?
|
2855
|
+
__webpack_require__("?5742");
|
2854
2856
|
class APIResource {
|
2855
2857
|
constructor(client){
|
2856
2858
|
this._client = client;
|
@@ -3650,9 +3652,9 @@ class documents_Documents extends APIResource {
|
|
3650
3652
|
* @param params.page - Optional The page number for paginated queries. Default is 1. | 可选 分页查询时的页码。默认为 1。
|
3651
3653
|
* @param params.page_size - Optional The size of pagination. Default is 10. | 可选 分页大小。默认为 10。
|
3652
3654
|
* @returns ListDocumentData | 知识库文件列表
|
3653
|
-
*/ list(params, options) {
|
3655
|
+
*/ async list(params, options) {
|
3654
3656
|
const apiUrl = '/open_api/knowledge/document/list';
|
3655
|
-
const response = this._client.get(apiUrl, params, false, esm_mergeConfig(options, {
|
3657
|
+
const response = await this._client.get(apiUrl, params, false, esm_mergeConfig(options, {
|
3656
3658
|
headers: documents_documents_headers
|
3657
3659
|
}));
|
3658
3660
|
return response;
|
@@ -3701,9 +3703,104 @@ class documents_Documents extends APIResource {
|
|
3701
3703
|
}));
|
3702
3704
|
}
|
3703
3705
|
}
|
3706
|
+
class Images extends APIResource {
|
3707
|
+
/**
|
3708
|
+
* Update the description of an image in the knowledge base | 更新知识库中的图片描述
|
3709
|
+
* @docs en: https://www.coze.com/docs/developer_guides/developer_guides/update_image_caption?_lang=en
|
3710
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/developer_guides/update_image_caption?_lang=zh
|
3711
|
+
* @param datasetId - The ID of the dataset | 必选 知识库 ID
|
3712
|
+
* @param documentId - The ID of the document | 必选 知识库文件 ID
|
3713
|
+
* @param params - The parameters for updating the image
|
3714
|
+
* @param params.caption - Required. The description of the image | 必选 图片的描述信息
|
3715
|
+
* @returns undefined
|
3716
|
+
*/ // eslint-disable-next-line max-params
|
3717
|
+
async update(datasetId, documentId, params, options) {
|
3718
|
+
const apiUrl = `/v1/datasets/${datasetId}/images/${documentId}`;
|
3719
|
+
await this._client.put(apiUrl, params, false, options);
|
3720
|
+
}
|
3721
|
+
/**
|
3722
|
+
* List images in the knowledge base | 列出知识库中的图片
|
3723
|
+
* @docs en: https://www.coze.com/docs/developer_guides/developer_guides/get_images?_lang=en
|
3724
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/developer_guides/get_images?_lang=zh
|
3725
|
+
* @param datasetId - The ID of the dataset | 必选 知识库 ID
|
3726
|
+
* @param params - The parameters for listing images
|
3727
|
+
* @param params.page_num - Optional. Page number for pagination, minimum value is 1, defaults to 1 | 可选 分页查询时的页码。默认为 1。
|
3728
|
+
* @param params.page_size - Optional. Number of items per page, range 1-299, defaults to 10 | 可选 分页大小。默认为 10。
|
3729
|
+
* @param params.keyword - Optional. Search keyword for image descriptions | 可选 图片描述的搜索关键词。
|
3730
|
+
* @param params.has_caption - Optional. Filter for images with/without captions | 可选 是否过滤有/无描述的图片。
|
3731
|
+
*/ async list(datasetId, params, options) {
|
3732
|
+
const apiUrl = `/v1/datasets/${datasetId}/images`;
|
3733
|
+
const response = await this._client.get(apiUrl, params, false, options);
|
3734
|
+
return response.data;
|
3735
|
+
}
|
3736
|
+
}
|
3704
3737
|
class Datasets extends APIResource {
|
3738
|
+
/**
|
3739
|
+
* Creates a new dataset | 创建数据集
|
3740
|
+
* @docs en: https://www.coze.com/docs/developer_guides/create_dataset?_lang=en
|
3741
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/create_dataset?_lang=zh
|
3742
|
+
* @param params - The parameters for creating a dataset
|
3743
|
+
* @param {string} params.name - Required. Dataset name, maximum length of 100 characters | 必选 数据集名称,最大长度为 100 个字符
|
3744
|
+
* @param {string} params.space_id - Required. Space ID where the dataset belongs | 必选 数据集所属的空间 ID
|
3745
|
+
* @param {number} params.format_type - Required. Dataset type (0: Text type, 2: Image type) | 必选 数据集类型 (0: 文本类型, 2: 图片类型)
|
3746
|
+
* @param {string} [params.description] - Optional. Dataset description | 可选 数据集描述
|
3747
|
+
* @param {string} [params.file_id] - Optional. Dataset icon file ID from file upload
|
3748
|
+
*/ async create(params, options) {
|
3749
|
+
const apiUrl = '/v1/datasets';
|
3750
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
3751
|
+
return response.data;
|
3752
|
+
}
|
3753
|
+
/**
|
3754
|
+
* Lists all datasets in a space | 列出空间中的所有数据集
|
3755
|
+
* @docs en: https://www.coze.com/docs/developer_guides/list_dataset?_lang=en
|
3756
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/list_dataset?_lang=zh
|
3757
|
+
* @param params - The parameters for listing datasets | 列出数据集的参数
|
3758
|
+
* @param {string} params.space_id - Required. Space ID where the datasets belong | 必选 数据集所属的空间 ID
|
3759
|
+
* @param {string} [params.name] - Optional. Dataset name for fuzzy search | 可选 数据集名称用于模糊搜索
|
3760
|
+
* @param {number} [params.format_type] - Optional. Dataset type (0: Text type, 2: Image type) | 可选 数据集类型 (0: 文本类型, 2: 图片类型)
|
3761
|
+
* @param {number} [params.page_num] - Optional. Page number for pagination (default: 1) | 可选 分页查询时的页码。默认为 1。
|
3762
|
+
* @param {number} [params.page_size] - Optional. Number of items per page (default: 10) | 可选 分页大小。默认为 10。
|
3763
|
+
*/ async list(params, options) {
|
3764
|
+
const apiUrl = '/v1/datasets';
|
3765
|
+
const response = await this._client.get(apiUrl, params, false, options);
|
3766
|
+
return response.data;
|
3767
|
+
}
|
3768
|
+
/**
|
3769
|
+
* Updates a dataset | 更新数据集
|
3770
|
+
* @docs en: https://www.coze.com/docs/developer_guides/update_dataset?_lang=en
|
3771
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/update_dataset?_lang=zh
|
3772
|
+
* @param dataset_id - Required. The ID of the dataset to update | 必选 数据集 ID
|
3773
|
+
* @param params - Required. The parameters for updating the dataset | 必选 更新数据集的参数
|
3774
|
+
* @param params.name - Required. Dataset name, maximum length of 100 characters. | 必选 数据集名称,最大长度为 100 个字符。
|
3775
|
+
* @param params.file_id - Optional. Dataset icon, should pass the file_id obtained from the file upload interface. | 可选 数据集图标,应传递从文件上传接口获取的 file_id。
|
3776
|
+
* @param params.description - Optional. Dataset description. | 可选 数据集描述。
|
3777
|
+
*/ async update(dataset_id, params, options) {
|
3778
|
+
const apiUrl = `/v1/datasets/${dataset_id}`;
|
3779
|
+
await this._client.put(apiUrl, params, false, options);
|
3780
|
+
}
|
3781
|
+
/**
|
3782
|
+
* Deletes a dataset | 删除数据集
|
3783
|
+
* @docs en: https://www.coze.com/docs/developer_guides/delete_dataset?_lang=en
|
3784
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/delete_dataset?_lang=zh
|
3785
|
+
* @param dataset_id - Required. The ID of the dataset to delete | 必选 数据集 ID
|
3786
|
+
*/ async delete(dataset_id, options) {
|
3787
|
+
const apiUrl = `/v1/datasets/${dataset_id}`;
|
3788
|
+
await this._client.delete(apiUrl, false, options);
|
3789
|
+
}
|
3790
|
+
/**
|
3791
|
+
* Views the progress of dataset upload | 查看数据集上传进度
|
3792
|
+
* @docs en: https://www.coze.com/docs/developer_guides/get_dataset_progress?_lang=en
|
3793
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/get_dataset_progress?_lang=zh
|
3794
|
+
* @param dataset_id - Required. The ID of the dataset to process | 必选 数据集 ID
|
3795
|
+
* @param params - Required. The parameters for processing the dataset | 必选 处理数据集的参数
|
3796
|
+
* @param params.dataset_ids - Required. List of dataset IDs | 必选 数据集 ID 列表
|
3797
|
+
*/ async process(dataset_id, params, options) {
|
3798
|
+
const apiUrl = `/v1/datasets/${dataset_id}/process`;
|
3799
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
3800
|
+
return response.data;
|
3801
|
+
}
|
3705
3802
|
constructor(...args){
|
3706
|
-
super(...args), this.documents = new documents_Documents(this._client);
|
3803
|
+
super(...args), this.documents = new documents_Documents(this._client), this.images = new Images(this._client);
|
3707
3804
|
}
|
3708
3805
|
}
|
3709
3806
|
class Voices extends APIResource {
|
@@ -3760,7 +3857,10 @@ class Speech extends APIResource {
|
|
3760
3857
|
* @returns Speech synthesis data
|
3761
3858
|
*/ async create(params, options) {
|
3762
3859
|
const apiUrl = '/v1/audio/speech';
|
3763
|
-
const response = await this._client.post(apiUrl,
|
3860
|
+
const response = await this._client.post(apiUrl, {
|
3861
|
+
...params,
|
3862
|
+
sample_rate: params.sample_rate || 24000
|
3863
|
+
}, false, esm_mergeConfig(options, {
|
3764
3864
|
responseType: 'arraybuffer'
|
3765
3865
|
}));
|
3766
3866
|
return response;
|
@@ -3778,7 +3878,21 @@ class esm_Audio extends APIResource {
|
|
3778
3878
|
super(...args), this.rooms = new Rooms(this._client), this.voices = new Voices(this._client), this.speech = new Speech(this._client);
|
3779
3879
|
}
|
3780
3880
|
}
|
3781
|
-
|
3881
|
+
class Templates extends APIResource {
|
3882
|
+
/**
|
3883
|
+
* Duplicate a template. | 复制一个模板。
|
3884
|
+
* @param templateId - Required. The ID of the template to duplicate. | 要复制的模板的 ID。
|
3885
|
+
* @param params - Optional. The parameters for the duplicate operation. | 可选参数,用于复制操作。
|
3886
|
+
* @param params.workspace_id - Required. The ID of the workspace to duplicate the template into. | 要复制到的目标工作空间的 ID。
|
3887
|
+
* @param params.name - Optional. The name of the new template. | 新模板的名称。
|
3888
|
+
* @returns TemplateDuplicateRes | 复制模板结果
|
3889
|
+
*/ async duplicate(templateId, params, options) {
|
3890
|
+
const apiUrl = `/v1/templates/${templateId}/duplicate`;
|
3891
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
3892
|
+
return response.data;
|
3893
|
+
}
|
3894
|
+
}
|
3895
|
+
var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.0.16","description":"Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中","keywords":["coze","ai","nodejs","sdk","chatbot","typescript"],"homepage":"https://github.com/coze-dev/coze-js/tree/main/packages/coze-js","bugs":{"url":"https://github.com/coze-dev/coze-js/issues"},"repository":{"type":"git","url":"https://github.com/coze-dev/coze-js.git","directory":"packages/coze-js"},"license":"MIT","author":"Leeight <leeight@gmail.com>","type":"module","exports":{".":{"require":"./dist/cjs/index.cjs","import":"./dist/esm/index.js","types":"./dist/types/index.d.ts"}},"main":"dist/cjs/index.cjs","module":"dist/esm/index.js","browser":{"crypto":false,"os":false,"jsonwebtoken":false},"types":"dist/types/index.d.ts","files":["dist","LICENSE","README.md","README.zh-CN.md"],"scripts":{"build":"rm -rf dist && rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","start":"rm -rf dist && rslib build -w","test":"vitest","test:cov":"vitest --coverage --run"},"dependencies":{"jsonwebtoken":"^9.0.2"},"devDependencies":{"@coze-infra/eslint-config":"workspace:*","@coze-infra/ts-config":"workspace:*","@coze-infra/vitest-config":"workspace:*","@rslib/core":"0.0.18","@swc/core":"^1.3.14","@types/jsonwebtoken":"^9.0.0","@types/node":"^20","@types/uuid":"^9.0.1","@types/whatwg-fetch":"^0.0.33","@vitest/coverage-v8":"~2.1.4","axios":"^1.7.7","typescript":"^5.5.3","vitest":"~2.1.4"},"peerDependencies":{"axios":"^1.7.1"}}'); // CONCATENATED MODULE: ./src/version.ts
|
3782
3896
|
const { version: esm_version } = package_namespaceObject;
|
3783
3897
|
const getEnv = ()=>{
|
3784
3898
|
const nodeVersion = process.version.slice(1); // Remove 'v' prefix
|
@@ -3828,6 +3942,55 @@ const getNodeClientUserAgent = ()=>{
|
|
3828
3942
|
};
|
3829
3943
|
return JSON.stringify(ua);
|
3830
3944
|
};
|
3945
|
+
const getBrowserClientUserAgent = ()=>{
|
3946
|
+
const browserInfo = {
|
3947
|
+
name: 'unknown',
|
3948
|
+
version: 'unknown'
|
3949
|
+
};
|
3950
|
+
const osInfo = {
|
3951
|
+
name: 'unknown',
|
3952
|
+
version: 'unknown'
|
3953
|
+
};
|
3954
|
+
const { userAgent } = navigator;
|
3955
|
+
// 检测操作系统及版本
|
3956
|
+
if (userAgent.indexOf('Windows') > -1) {
|
3957
|
+
var _userAgent_match;
|
3958
|
+
osInfo.name = 'windows';
|
3959
|
+
const windowsVersion = (null === (_userAgent_match = userAgent.match(/Windows NT ([0-9.]+)/)) || void 0 === _userAgent_match ? void 0 : _userAgent_match[1]) || 'unknown';
|
3960
|
+
osInfo.version = windowsVersion;
|
3961
|
+
} else if (userAgent.indexOf('Mac OS X') > -1) {
|
3962
|
+
var _userAgent_match1;
|
3963
|
+
osInfo.name = 'macos';
|
3964
|
+
// 将 10_15_7 格式转换为 10.15.7
|
3965
|
+
osInfo.version = ((null === (_userAgent_match1 = userAgent.match(/Mac OS X ([0-9_]+)/)) || void 0 === _userAgent_match1 ? void 0 : _userAgent_match1[1]) || 'unknown').replace(/_/g, '.');
|
3966
|
+
} else if (userAgent.indexOf('Linux') > -1) {
|
3967
|
+
var _userAgent_match2;
|
3968
|
+
osInfo.name = 'linux';
|
3969
|
+
osInfo.version = (null === (_userAgent_match2 = userAgent.match(/Linux ([0-9.]+)/)) || void 0 === _userAgent_match2 ? void 0 : _userAgent_match2[1]) || 'unknown';
|
3970
|
+
}
|
3971
|
+
// 检测浏览器及版本
|
3972
|
+
if (userAgent.indexOf('Chrome') > -1) {
|
3973
|
+
var _userAgent_match3;
|
3974
|
+
browserInfo.name = 'chrome';
|
3975
|
+
browserInfo.version = (null === (_userAgent_match3 = userAgent.match(/Chrome\/([0-9.]+)/)) || void 0 === _userAgent_match3 ? void 0 : _userAgent_match3[1]) || 'unknown';
|
3976
|
+
} else if (userAgent.indexOf('Firefox') > -1) {
|
3977
|
+
var _userAgent_match4;
|
3978
|
+
browserInfo.name = 'firefox';
|
3979
|
+
browserInfo.version = (null === (_userAgent_match4 = userAgent.match(/Firefox\/([0-9.]+)/)) || void 0 === _userAgent_match4 ? void 0 : _userAgent_match4[1]) || 'unknown';
|
3980
|
+
} else if (userAgent.indexOf('Safari') > -1) {
|
3981
|
+
var _userAgent_match5;
|
3982
|
+
browserInfo.name = 'safari';
|
3983
|
+
browserInfo.version = (null === (_userAgent_match5 = userAgent.match(/Version\/([0-9.]+)/)) || void 0 === _userAgent_match5 ? void 0 : _userAgent_match5[1]) || 'unknown';
|
3984
|
+
}
|
3985
|
+
const ua = {
|
3986
|
+
version: esm_version,
|
3987
|
+
browser: browserInfo.name,
|
3988
|
+
browser_version: browserInfo.version,
|
3989
|
+
os_name: osInfo.name,
|
3990
|
+
os_version: osInfo.version
|
3991
|
+
};
|
3992
|
+
return JSON.stringify(ua);
|
3993
|
+
};
|
3831
3994
|
/* eslint-disable @typescript-eslint/no-explicit-any */ const esm_handleError = (error)=>{
|
3832
3995
|
if (!error.isAxiosError && (!error.code || !error.message)) return new CozeError(`Unexpected error: ${error.message}`);
|
3833
3996
|
if ('ECONNABORTED' === error.code && error.message.includes('timeout') || 'ETIMEDOUT' === error.code) {
|
@@ -3925,7 +4088,8 @@ function isAxiosStatic(instance) {
|
|
3925
4088
|
const headers = {
|
3926
4089
|
authorization: `Bearer ${token}`
|
3927
4090
|
};
|
3928
|
-
if (
|
4091
|
+
if (isBrowser()) headers['X-Coze-Client-User-Agent'] = getBrowserClientUserAgent();
|
4092
|
+
else {
|
3929
4093
|
headers['User-Agent'] = getUserAgent();
|
3930
4094
|
headers['X-Coze-Client-User-Agent'] = getNodeClientUserAgent();
|
3931
4095
|
}
|
@@ -4017,7 +4181,7 @@ class CozeAPI extends APIClient {
|
|
4017
4181
|
constructor(...args){
|
4018
4182
|
super(...args), this.bots = new Bots(this), this.chat = new Chat(this), this.conversations = new Conversations(this), this.files = new Files(this), /**
|
4019
4183
|
* @deprecated
|
4020
|
-
*/ this.knowledge = new Knowledge(this), this.datasets = new Datasets(this), this.workflows = new Workflows(this), this.workspaces = new WorkSpaces(this), this.audio = new esm_Audio(this);
|
4184
|
+
*/ this.knowledge = new Knowledge(this), this.datasets = new Datasets(this), this.workflows = new Workflows(this), this.workspaces = new WorkSpaces(this), this.audio = new esm_Audio(this), this.templates = new Templates(this);
|
4021
4185
|
}
|
4022
4186
|
}
|
4023
4187
|
/**
|
@@ -9249,7 +9413,7 @@ var setPrototypeOf = setPrototypeOf$2, _Object$setPrototypeOf = getDefaultExport
|
|
9249
9413
|
}, stringPad = {
|
9250
9414
|
start: createMethod(!1),
|
9251
9415
|
end: createMethod(!0)
|
9252
|
-
},
|
9416
|
+
}, index_esm_min_userAgent = engineUserAgent, stringPadWebkitBug = /Version\/10(?:\.\d+){1,2}(?: [\w./]+)?(?: Mobile\/\w+)? Safari\//.test(index_esm_min_userAgent), $$F = _export, $padEnd = stringPad.end, WEBKIT_BUG$1 = stringPadWebkitBug;
|
9253
9417
|
$$F({
|
9254
9418
|
target: "String",
|
9255
9419
|
proto: !0,
|
@@ -38422,7 +38586,11 @@ var VERTC = _createClass(function e() {
|
|
38422
38586
|
return false;
|
38423
38587
|
}
|
38424
38588
|
};
|
38425
|
-
|
38589
|
+
/**
|
38590
|
+
* Checks device permissions for audio and video
|
38591
|
+
* @param checkVideo Whether to check video permissions (default: false)
|
38592
|
+
* @returns Promise that resolves with the device permission status
|
38593
|
+
*/ const checkDevicePermission = async function() {
|
38426
38594
|
let checkVideo = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
|
38427
38595
|
return await index_esm_min_index.enableDevices({
|
38428
38596
|
audio: true,
|
@@ -38435,7 +38603,16 @@ const checkDevicePermission = async function() {
|
|
38435
38603
|
*/ const getAudioDevices = async function() {
|
38436
38604
|
let { video = false } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
38437
38605
|
let devices = [];
|
38438
|
-
|
38606
|
+
if (video) {
|
38607
|
+
devices = await index_esm_min_index.enumerateDevices();
|
38608
|
+
if (isScreenShareSupported()) // @ts-expect-error - add screenShare device to devices
|
38609
|
+
devices.push({
|
38610
|
+
deviceId: 'screenShare',
|
38611
|
+
kind: 'videoinput',
|
38612
|
+
label: 'Screen Share',
|
38613
|
+
groupId: 'screenShare'
|
38614
|
+
});
|
38615
|
+
} else devices = await [
|
38439
38616
|
...await index_esm_min_index.enumerateAudioCaptureDevices(),
|
38440
38617
|
...await index_esm_min_index.enumerateAudioPlaybackDevices()
|
38441
38618
|
];
|
@@ -38450,6 +38627,14 @@ const checkDevicePermission = async function() {
|
|
38450
38627
|
videoInputs: devices.filter((i)=>i.deviceId && 'videoinput' === i.kind)
|
38451
38628
|
};
|
38452
38629
|
};
|
38630
|
+
const isScreenShareDevice = (deviceId)=>'screenShare' === deviceId;
|
38631
|
+
/**
|
38632
|
+
* Check if browser supports screen sharing
|
38633
|
+
* 检查浏览器是否支持屏幕共享
|
38634
|
+
*/ function isScreenShareSupported() {
|
38635
|
+
var _navigator_mediaDevices, _navigator;
|
38636
|
+
return !!(null === (_navigator = navigator) || void 0 === _navigator ? void 0 : null === (_navigator_mediaDevices = _navigator.mediaDevices) || void 0 === _navigator_mediaDevices ? void 0 : _navigator_mediaDevices.getDisplayMedia);
|
38637
|
+
}
|
38453
38638
|
var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
|
38454
38639
|
RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
|
38455
38640
|
RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
|
@@ -38543,6 +38728,10 @@ var event_handler_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
38543
38728
|
* zh: 音频输出设备改变
|
38544
38729
|
*/ EventNames["AUDIO_OUTPUT_DEVICE_CHANGED"] = "client.output.device.changed";
|
38545
38730
|
/**
|
38731
|
+
* en: Video input device changed
|
38732
|
+
* zh: 视频输入设备改变
|
38733
|
+
*/ EventNames["VIDEO_INPUT_DEVICE_CHANGED"] = "client.video.input.device.changed";
|
38734
|
+
/**
|
38546
38735
|
* en: Bot joined
|
38547
38736
|
* zh: Bot 加入
|
38548
38737
|
*/ EventNames["BOT_JOIN"] = "server.bot.join";
|
@@ -41960,23 +42149,47 @@ class EngineClient extends RealtimeEventHandler {
|
|
41960
42149
|
if (-1 === devices.audioOutputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Audio output device not found: ${deviceId}`);
|
41961
42150
|
await this.engine.setAudioPlaybackDevice(deviceId);
|
41962
42151
|
}
|
42152
|
+
async setVideoInputDevice(deviceId) {
|
42153
|
+
let isAutoCapture = !(arguments.length > 1) || void 0 === arguments[1] || arguments[1];
|
42154
|
+
var _this__videoConfig;
|
42155
|
+
const devices = await getAudioDevices({
|
42156
|
+
video: true
|
42157
|
+
});
|
42158
|
+
if (-1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
|
42159
|
+
await this.changeVideoState(false);
|
42160
|
+
if (isScreenShareDevice(deviceId)) {
|
42161
|
+
if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_MAIN);
|
42162
|
+
if (isAutoCapture) {
|
42163
|
+
var _this__videoConfig1;
|
42164
|
+
this.engine.setVideoSourceType(StreamIndex$1.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
42165
|
+
await this.engine.startScreenCapture(null === (_this__videoConfig1 = this._videoConfig) || void 0 === _this__videoConfig1 ? void 0 : _this__videoConfig1.screenConfig);
|
42166
|
+
await this.engine.publishScreen(MediaType$1.VIDEO);
|
42167
|
+
}
|
42168
|
+
this._streamIndex = StreamIndex$1.STREAM_INDEX_SCREEN;
|
42169
|
+
} else {
|
42170
|
+
if (this._streamIndex === StreamIndex$1.STREAM_INDEX_SCREEN) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_SCREEN);
|
42171
|
+
if (isAutoCapture) await this.engine.startVideoCapture(deviceId);
|
42172
|
+
this._streamIndex = StreamIndex$1.STREAM_INDEX_MAIN;
|
42173
|
+
}
|
42174
|
+
this.engine.setLocalVideoPlayer(this._streamIndex, {
|
42175
|
+
renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
|
42176
|
+
userId: this._roomUserId
|
42177
|
+
});
|
42178
|
+
}
|
41963
42179
|
async createLocalStream(userId, videoConfig) {
|
42180
|
+
this._roomUserId = userId;
|
41964
42181
|
const devices = await getAudioDevices({
|
41965
42182
|
video: this._isSupportVideo
|
41966
42183
|
});
|
41967
42184
|
if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
|
41968
42185
|
if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
|
41969
42186
|
await this.engine.startAudioCapture(devices.audioInputs[0].deviceId);
|
41970
|
-
if (this._isSupportVideo
|
41971
|
-
if (this._isSupportVideo) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_MAIN, {
|
41972
|
-
renderDom: (null == videoConfig ? void 0 : videoConfig.renderDom) || 'local-player',
|
41973
|
-
userId
|
41974
|
-
});
|
42187
|
+
if (this._isSupportVideo) this.setVideoInputDevice((null == videoConfig ? void 0 : videoConfig.videoInputDeviceId) || devices.videoInputs[0].deviceId, null == videoConfig ? void 0 : videoConfig.videoOnDefault);
|
41975
42188
|
}
|
41976
42189
|
async disconnect() {
|
41977
42190
|
try {
|
41978
|
-
if (this._isSupportVideo) await this.
|
41979
|
-
await this.
|
42191
|
+
if (this._isSupportVideo) await this.changeVideoState(false);
|
42192
|
+
await this.changeAudioState(false);
|
41980
42193
|
await this.engine.unpublishStream(MediaType$1.AUDIO);
|
41981
42194
|
await this.engine.leaveRoom();
|
41982
42195
|
this.removeEventListener();
|
@@ -41996,8 +42209,19 @@ class EngineClient extends RealtimeEventHandler {
|
|
41996
42209
|
}
|
41997
42210
|
async changeVideoState(isVideoOn) {
|
41998
42211
|
try {
|
41999
|
-
if (isVideoOn)
|
42000
|
-
|
42212
|
+
if (isVideoOn) {
|
42213
|
+
if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
|
42214
|
+
else {
|
42215
|
+
var _this__videoConfig;
|
42216
|
+
this.engine.setVideoSourceType(StreamIndex$1.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
42217
|
+
await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
|
42218
|
+
await this.engine.publishScreen(MediaType$1.VIDEO);
|
42219
|
+
}
|
42220
|
+
} else if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
|
42221
|
+
else {
|
42222
|
+
await this.engine.stopScreenCapture();
|
42223
|
+
await this.engine.unpublishScreen(MediaType$1.VIDEO);
|
42224
|
+
}
|
42001
42225
|
} catch (e) {
|
42002
42226
|
this.dispatch(event_handler_EventNames.ERROR, e);
|
42003
42227
|
throw e;
|
@@ -42075,7 +42299,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
42075
42299
|
}
|
42076
42300
|
}
|
42077
42301
|
// eslint-disable-next-line max-params
|
42078
|
-
constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false){
|
42302
|
+
constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false, videoConfig){
|
42079
42303
|
super(debug), this.joinUserId = '', this._AIAnsExtension = null, this._isSupportVideo = false;
|
42080
42304
|
if (isTestEnv) index_esm_min_index.setParameter('ICE_CONFIG_REQUEST_URLS', [
|
42081
42305
|
'rtc-test.bytedance.com'
|
@@ -42090,6 +42314,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
42090
42314
|
this.handleLocalAudioPropertiesReport = this.handleLocalAudioPropertiesReport.bind(this);
|
42091
42315
|
this.handleRemoteAudioPropertiesReport = this.handleRemoteAudioPropertiesReport.bind(this);
|
42092
42316
|
this._isSupportVideo = isSupportVideo;
|
42317
|
+
this._videoConfig = videoConfig;
|
42093
42318
|
}
|
42094
42319
|
}
|
42095
42320
|
class RealtimeClient extends RealtimeEventHandler {
|
@@ -42114,7 +42339,7 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
42114
42339
|
throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
|
42115
42340
|
}
|
42116
42341
|
// Step2 create engine
|
42117
|
-
this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo);
|
42342
|
+
this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
|
42118
42343
|
// Step3 bind engine events
|
42119
42344
|
this._client.bindEngineEvents();
|
42120
42345
|
this._client.on(event_handler_EventNames.ALL, (eventName, data)=>{
|
@@ -42250,6 +42475,13 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
42250
42475
|
deviceId
|
42251
42476
|
});
|
42252
42477
|
}
|
42478
|
+
async setVideoInputDevice(deviceId) {
|
42479
|
+
var _this__client;
|
42480
|
+
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
|
42481
|
+
this.dispatch(event_handler_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
|
42482
|
+
deviceId
|
42483
|
+
});
|
42484
|
+
}
|
42253
42485
|
/**
|
42254
42486
|
* Constructor for initializing a RealtimeClient instance.
|
42255
42487
|
*
|
@@ -42280,6 +42512,16 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
42280
42512
|
* @param config.suppressNonStationaryNoise - Optional, suppress non-stationary noise, defaults to false. |
|
42281
42513
|
* 可选,默认是否抑制非静态噪声,默认值为 false。
|
42282
42514
|
* @param config.isAutoSubscribeAudio - Optional, whether to automatically subscribe to bot reply audio streams, defaults to true. |
|
42515
|
+
* @param config.videoConfig - Optional, Video configuration. |
|
42516
|
+
* 可选,视频配置。
|
42517
|
+
* @param config.videoConfig.videoOnDefault - Optional, Whether to turn on video by default, defaults to true. |
|
42518
|
+
* 可选,默认是否开启视频,默认值为 true。
|
42519
|
+
* @param config.videoConfig.renderDom - Optional, The DOM element to render the video stream to. |
|
42520
|
+
* 可选,渲染视频流的 DOM 元素。
|
42521
|
+
* @param config.videoConfig.videoInputDeviceId - Optional, The device ID of the video input device to use. |
|
42522
|
+
* 可选,视频输入设备的设备 ID。
|
42523
|
+
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
42524
|
+
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
42283
42525
|
*/ constructor(config){
|
42284
42526
|
super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
|
42285
42527
|
this._config = config;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":"5.6.3"}
|
package/dist/types/client.d.ts
CHANGED
@@ -6,7 +6,10 @@ export declare class EngineClient extends RealtimeEventHandler {
|
|
6
6
|
private joinUserId;
|
7
7
|
private _AIAnsExtension;
|
8
8
|
private _isSupportVideo;
|
9
|
-
|
9
|
+
private _videoConfig?;
|
10
|
+
private _streamIndex?;
|
11
|
+
private _roomUserId?;
|
12
|
+
constructor(appId: string, debug?: boolean, isTestEnv?: boolean, isSupportVideo?: boolean, videoConfig?: VideoConfig);
|
10
13
|
bindEngineEvents(): void;
|
11
14
|
removeEventListener(): void;
|
12
15
|
_parseMessage(event: UserMessageEvent): any;
|
@@ -25,6 +28,7 @@ export declare class EngineClient extends RealtimeEventHandler {
|
|
25
28
|
}): Promise<void>;
|
26
29
|
setAudioInputDevice(deviceId: string): Promise<void>;
|
27
30
|
setAudioOutputDevice(deviceId: string): Promise<void>;
|
31
|
+
setVideoInputDevice(deviceId: string, isAutoCapture?: boolean): Promise<void>;
|
28
32
|
createLocalStream(userId?: string, videoConfig?: VideoConfig): Promise<void>;
|
29
33
|
disconnect(): Promise<void>;
|
30
34
|
changeAudioState(isMicOn: boolean): Promise<void>;
|
@@ -79,6 +79,11 @@ export declare enum EventNames {
|
|
79
79
|
* zh: 音频输出设备改变
|
80
80
|
*/
|
81
81
|
AUDIO_OUTPUT_DEVICE_CHANGED = "client.output.device.changed",
|
82
|
+
/**
|
83
|
+
* en: Video input device changed
|
84
|
+
* zh: 视频输入设备改变
|
85
|
+
*/
|
86
|
+
VIDEO_INPUT_DEVICE_CHANGED = "client.video.input.device.changed",
|
82
87
|
/**
|
83
88
|
* en: Bot joined
|
84
89
|
* zh: Bot 加入
|
package/dist/types/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { type AudioPropertiesConfig } from '@volcengine/rtc';
|
1
|
+
import { type ScreenConfig, type AudioPropertiesConfig } from '@volcengine/rtc';
|
2
2
|
import { type GetToken } from '@coze/api';
|
3
3
|
import * as RealtimeUtils from './utils';
|
4
4
|
import { RealtimeEventHandler, EventNames } from './event-handler';
|
@@ -6,6 +6,8 @@ import { RealtimeAPIError, RealtimeError } from './error';
|
|
6
6
|
export interface VideoConfig {
|
7
7
|
videoOnDefault?: boolean /** optional, Whether to turn on video by default, defaults to true */;
|
8
8
|
renderDom?: string /** optional, The DOM element to render the video stream to */;
|
9
|
+
videoInputDeviceId?: string /** optional, The device ID of the video input device to use */;
|
10
|
+
screenConfig?: ScreenConfig;
|
9
11
|
}
|
10
12
|
export interface RealtimeClientConfig {
|
11
13
|
accessToken: GetToken /** required, Access Token */;
|
@@ -62,6 +64,16 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
62
64
|
* @param config.suppressNonStationaryNoise - Optional, suppress non-stationary noise, defaults to false. |
|
63
65
|
* 可选,默认是否抑制非静态噪声,默认值为 false。
|
64
66
|
* @param config.isAutoSubscribeAudio - Optional, whether to automatically subscribe to bot reply audio streams, defaults to true. |
|
67
|
+
* @param config.videoConfig - Optional, Video configuration. |
|
68
|
+
* 可选,视频配置。
|
69
|
+
* @param config.videoConfig.videoOnDefault - Optional, Whether to turn on video by default, defaults to true. |
|
70
|
+
* 可选,默认是否开启视频,默认值为 true。
|
71
|
+
* @param config.videoConfig.renderDom - Optional, The DOM element to render the video stream to. |
|
72
|
+
* 可选,渲染视频流的 DOM 元素。
|
73
|
+
* @param config.videoConfig.videoInputDeviceId - Optional, The device ID of the video input device to use. |
|
74
|
+
* 可选,视频输入设备的设备 ID。
|
75
|
+
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
76
|
+
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
65
77
|
*/
|
66
78
|
constructor(config: RealtimeClientConfig);
|
67
79
|
/**
|
@@ -125,5 +137,6 @@ declare class RealtimeClient extends RealtimeEventHandler {
|
|
125
137
|
* zh: 设置音频输出设备
|
126
138
|
*/
|
127
139
|
setAudioOutputDevice(deviceId: string): Promise<void>;
|
140
|
+
setVideoInputDevice(deviceId: string): Promise<void>;
|
128
141
|
}
|
129
142
|
export { RealtimeUtils, RealtimeClient, RealtimeAPIError, RealtimeError, EventNames, };
|
package/dist/types/utils.d.ts
CHANGED
@@ -13,6 +13,11 @@ export declare const checkPermission: ({ audio, video, }?: {
|
|
13
13
|
audio?: boolean;
|
14
14
|
video?: boolean;
|
15
15
|
}) => Promise<boolean>;
|
16
|
+
/**
|
17
|
+
* Checks device permissions for audio and video
|
18
|
+
* @param checkVideo Whether to check video permissions (default: false)
|
19
|
+
* @returns Promise that resolves with the device permission status
|
20
|
+
*/
|
16
21
|
export declare const checkDevicePermission: (checkVideo?: boolean) => Promise<{
|
17
22
|
video: boolean;
|
18
23
|
audio: boolean;
|
@@ -30,3 +35,9 @@ export declare const getAudioDevices: ({ video, }?: {
|
|
30
35
|
audioOutputs: MediaDeviceInfo[];
|
31
36
|
videoInputs: MediaDeviceInfo[];
|
32
37
|
}>;
|
38
|
+
export declare const isScreenShareDevice: (deviceId?: string) => boolean;
|
39
|
+
/**
|
40
|
+
* Check if browser supports screen sharing
|
41
|
+
* 检查浏览器是否支持屏幕共享
|
42
|
+
*/
|
43
|
+
export declare function isScreenShareSupported(): boolean;
|