@tencentcloud/trtc-cloud-wx 1.0.9-beta.0 → 1.0.10
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/package.json +2 -40
- package/{dist/trtc-cloud-wx.js → trtc-cloud-wx.js} +3 -5
- package/.babelrc +0 -6
- package/.eslintrc.json +0 -129
- package/build/chokidar.js +0 -19
- package/build/clear.js +0 -24
- package/build/copy.js +0 -24
- package/build/copy_to_roomkit.js +0 -19
- package/dist/package.json +0 -14
- package/docs/API/TRTCCloud.html +0 -4353
- package/docs/API/index.html +0 -98
- package/docs/API/scripts/add-toc.js +0 -57
- package/docs/API/scripts/collapse.js +0 -20
- package/docs/API/scripts/highlight/highlight.min.js +0 -1282
- package/docs/API/scripts/highlight/highlightjs-line-numbers.min.js +0 -1
- package/docs/API/scripts/linenumber.js +0 -25
- package/docs/API/scripts/nav.js +0 -12
- package/docs/API/scripts/polyfill.js +0 -4
- package/docs/API/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/docs/API/scripts/prettify/lang-css.js +0 -2
- package/docs/API/scripts/prettify/prettify.js +0 -28
- package/docs/API/scripts/search.js +0 -83
- package/docs/API/styles/font.css +0 -81
- package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3g3D_vx3rCubqg.woff2 +0 -0
- package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3gTD_vx3rCubqg.woff2 +0 -0
- package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3gbD_vx3rCubqg.woff2 +0 -0
- package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3gfD_vx3rCubqg.woff2 +0 -0
- package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3gnD_vx3rCs.woff2 +0 -0
- package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459W1hyyTh89ZNpQ.woff2 +0 -0
- package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459WRhyyTh89ZNpQ.woff2 +0 -0
- package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459WZhyyTh89ZNpQ.woff2 +0 -0
- package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459WdhyyTh89ZNpQ.woff2 +0 -0
- package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459WlhyyTh89Y.woff2 +0 -0
- package/docs/API/styles/highlight/highlight.min.css +0 -26
- package/docs/API/styles/highlight/rainbow.min.css +0 -1
- package/docs/API/styles/jsdoc.css +0 -684
- package/docs/API/styles/prettify.css +0 -79
- package/docs/API/styles/toc.css +0 -44
- package/docs/API/tutorial-00-guideline.html +0 -81
- package/docs/doc-src/home.md +0 -7
- package/docs/doc-src/tutorials/00-guideline.md +0 -1
- package/docs/doc-src/tutorials/tutorials.json +0 -5
- package/jsdoc.json +0 -43
- package/rollup.config.js +0 -19
- package/sdk_publish.bash +0 -5
- package/src/TaskMachine.ts +0 -371
- package/src/index.ts +0 -1184
- package/src/interface/index.ts +0 -45
- package/src/interface/types.ts +0 -95
- package/src/log/logger.ts +0 -80
- package/src/types.d.ts +0 -1
- package/src/utils/common.ts +0 -50
- package/src/utils/index.ts +0 -2
- package/src/utils/translate.ts +0 -139
- package/tsconfig.json +0 -15
- package/typedoc.json +0 -21
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
.pln {
|
|
2
|
-
color: #ddd;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
/* string content */
|
|
6
|
-
.str {
|
|
7
|
-
color: #61ce3c;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/* a keyword */
|
|
11
|
-
.kwd {
|
|
12
|
-
color: #fbde2d;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/* a comment */
|
|
16
|
-
.com {
|
|
17
|
-
color: #aeaeae;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/* a type name */
|
|
21
|
-
.typ {
|
|
22
|
-
color: #8da6ce;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/* a literal value */
|
|
26
|
-
.lit {
|
|
27
|
-
color: #fbde2d;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/* punctuation */
|
|
31
|
-
.pun {
|
|
32
|
-
color: #ddd;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/* lisp open bracket */
|
|
36
|
-
.opn {
|
|
37
|
-
color: #000000;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/* lisp close bracket */
|
|
41
|
-
.clo {
|
|
42
|
-
color: #000000;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/* a markup tag name */
|
|
46
|
-
.tag {
|
|
47
|
-
color: #8da6ce;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/* a markup attribute name */
|
|
51
|
-
.atn {
|
|
52
|
-
color: #fbde2d;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/* a markup attribute value */
|
|
56
|
-
.atv {
|
|
57
|
-
color: #ddd;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/* a declaration */
|
|
61
|
-
.dec {
|
|
62
|
-
color: #EF5050;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/* a variable name */
|
|
66
|
-
.var {
|
|
67
|
-
color: #c82829;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/* a function name */
|
|
71
|
-
.fun {
|
|
72
|
-
color: #4271ae;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/* Specify class=linenums on a pre to get line numbering */
|
|
76
|
-
ol.linenums {
|
|
77
|
-
margin-top: 0;
|
|
78
|
-
margin-bottom: 0;
|
|
79
|
-
}
|
package/docs/API/styles/toc.css
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/* toc 相关样式 */
|
|
2
|
-
.toc{overflow-y:auto}.toc>.toc-list{overflow:hidden;position:relative}.toc>.toc-list li{list-style:none}.toc-list{margin:0;padding-left:10px}a.toc-link{color:currentColor;height:100%}.is-collapsible{max-height:1000px;overflow:hidden;transition:all 300ms ease-in-out}.is-collapsed{max-height:0}.is-position-fixed{position:fixed !important;top:0}.is-active-link{font-weight:700}.toc-link::before{background-color:#EEE;content:' ';display:inline-block;height:inherit;left:0;margin-top:-1px;position:absolute;width:2px}.is-active-link::before{background-color:#54BC4B}
|
|
3
|
-
|
|
4
|
-
section {
|
|
5
|
-
display: flex;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
section article {
|
|
9
|
-
width: calc(100% - 300px);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
#toc-container {
|
|
13
|
-
width: 300px;
|
|
14
|
-
max-height: 80vh;
|
|
15
|
-
background: #fff;
|
|
16
|
-
overflow-y: auto;
|
|
17
|
-
position: sticky;
|
|
18
|
-
top: 100px;
|
|
19
|
-
margin-left: 10px;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.toc-link::before {
|
|
23
|
-
width: 3px !important;
|
|
24
|
-
}
|
|
25
|
-
.is-active-link::before {
|
|
26
|
-
background-color: #00a4ff !important;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.toc-link::before {
|
|
30
|
-
height: 30px;
|
|
31
|
-
}
|
|
32
|
-
.toc-list {
|
|
33
|
-
list-style-type: none;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@media screen and (max-width:1024px){
|
|
37
|
-
section article {
|
|
38
|
-
width: 100%;
|
|
39
|
-
}
|
|
40
|
-
/* 小屏不显示目录 */
|
|
41
|
-
#toc-container {
|
|
42
|
-
display: none;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<title>Tutorial: ChatEngine 使用指引 - Documentation</title>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
<script src="scripts/highlight/highlight.min.js"></script>
|
|
10
|
-
<script src="scripts/highlight/highlightjs-line-numbers.min.js"></script>
|
|
11
|
-
<!--[if lt IE 9]>
|
|
12
|
-
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
-
<![endif]-->
|
|
14
|
-
<link type="text/css" rel="stylesheet" href="styles/highlight/rainbow.min.css">
|
|
15
|
-
<link type="text/css" rel="stylesheet" href="styles/highlight/highlight.min.css">
|
|
16
|
-
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
17
|
-
<script src="scripts/nav.js" defer></script>
|
|
18
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
-
</head>
|
|
20
|
-
<body>
|
|
21
|
-
|
|
22
|
-
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
-
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
-
<div class="navicon"></div>
|
|
25
|
-
</label>
|
|
26
|
-
|
|
27
|
-
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
-
|
|
29
|
-
<nav >
|
|
30
|
-
|
|
31
|
-
<input type="text" id="nav-search" placeholder="Search" />
|
|
32
|
-
|
|
33
|
-
<h2><a href="index.html">Home</a></h2><h3>Interfaces</h3><ul><li><a href="TRTCCloud.html">TRTCCloud</a><ul class='methods'><li data-type='method' style='display: none;'><a href="TRTCCloud.html#.getTRTCShareInstance">getTRTCShareInstance</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#.destroyTRTCShareInstance">destroyTRTCShareInstance</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#on">on</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#off">off</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#emit">emit</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#enterRoom">enterRoom</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#exitRoom">exitRoom</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#switchRoom">switchRoom</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#switchRole">switchRole</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#startLocalPreview">startLocalPreview</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#stopLocalPreview">stopLocalPreview</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#updateLocalView">updateLocalView</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#muteLocalVideo">muteLocalVideo</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#startRemoteView">startRemoteView</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#stopRemoteView">stopRemoteView</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#updateRemoteView">updateRemoteView</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#switchCamera">switchCamera</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#.getTRTCShareInstance">getTRTCShareInstance</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#.destroyTRTCShareInstance">destroyTRTCShareInstance</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#on">on</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#off">off</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#emit">emit</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#enterRoom">enterRoom</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#exitRoom">exitRoom</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#switchRoom">switchRoom</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#switchRole">switchRole</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#startLocalPreview">startLocalPreview</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#stopLocalPreview">stopLocalPreview</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#updateLocalView">updateLocalView</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#muteLocalVideo">muteLocalVideo</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#startRemoteView">startRemoteView</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#stopRemoteView">stopRemoteView</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#updateRemoteView">updateRemoteView</a></li><li data-type='method' style='display: none;'><a href="TRTCCloud.html#switchCamera">switchCamera</a></li></ul></li></ul><h3>Tutorials</h3><ul><li><a href="tutorial-00-guideline.html">ChatEngine 使用指引</a></li></ul>
|
|
34
|
-
</nav>
|
|
35
|
-
|
|
36
|
-
<div id="main">
|
|
37
|
-
|
|
38
|
-
<h1 class="page-title">Tutorial: ChatEngine 使用指引</h1>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
<section>
|
|
42
|
-
|
|
43
|
-
<header>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
<h2>ChatEngine 使用指引</h2>
|
|
47
|
-
<link type="text/css" rel="stylesheet" href="styles/toc.css">
|
|
48
|
-
|
|
49
|
-
</header>
|
|
50
|
-
|
|
51
|
-
<article>
|
|
52
|
-
<p>待补充</p>
|
|
53
|
-
</article>
|
|
54
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.11.1/tocbot.min.js"></script>
|
|
55
|
-
<script src="scripts/add-toc.js"></script>
|
|
56
|
-
</section>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
</div>
|
|
61
|
-
|
|
62
|
-
<br class="clear">
|
|
63
|
-
|
|
64
|
-
<footer>
|
|
65
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Mon Apr 24 2023 16:55:54 GMT+0800 (China Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
66
|
-
</footer>
|
|
67
|
-
|
|
68
|
-
<script>
|
|
69
|
-
hljs.highlightAll({cssSelector:'highlight'});
|
|
70
|
-
hljs.initLineNumbersOnLoad();
|
|
71
|
-
</script>
|
|
72
|
-
<script src="scripts/polyfill.js"></script>
|
|
73
|
-
|
|
74
|
-
<script src="scripts/search.js" defer></script>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
<script src="scripts/collapse.js" defer></script>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
</body>
|
|
81
|
-
</html>
|
package/docs/doc-src/home.md
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# 腾讯云即时通信 IM SDK
|
|
2
|
-
|
|
3
|
-
## 简介
|
|
4
|
-
腾讯是国内最早也是最大的即时通信开发商,QQ 和微信已经成为每个互联网用户必不可少的应用。顺应行业数字化转型的趋势,腾讯将高并发、高可靠的即时通信能力进行开放,您可以轻易地根据腾讯提供的 SDK 将即时通信功能集成到 App 中,来满足您业务的各种需求。<br/>
|
|
5
|
-
针对开发者的不同阶段需求及不同场景,即时通信 IM 团队提供了一系列解决方案,包括:Android、iOS、Windows、Web 的 SDK 组件、服务端集成 REST API 接口、第三方回调接口 等。利用这些组件和能力,开发者可以简单快捷地构建高可靠且稳定的即时通信产品,随心所想,触达全球。
|
|
6
|
-
|
|
7
|
-
ChatEngine 基于腾讯云即时通讯 IM SDK 底层能力实现业务逻辑层核心逻辑封装,支持在 Web 网页、H5、微信小程序、uniapp 等平台下接入使用。
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
待补充
|
package/jsdoc.json
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"plugins": [
|
|
3
|
-
"plugins/markdown",
|
|
4
|
-
"node_modules/better-docs/typescript"
|
|
5
|
-
],
|
|
6
|
-
"sourceType": "module",
|
|
7
|
-
"source": {
|
|
8
|
-
"include": [
|
|
9
|
-
"./src/index.ts",
|
|
10
|
-
"./src/interface/types.ts"
|
|
11
|
-
],
|
|
12
|
-
"includePattern": ".+\\.ts(doc|x)?$"
|
|
13
|
-
},
|
|
14
|
-
"typescript": {
|
|
15
|
-
"moduleRoot": "src"
|
|
16
|
-
},
|
|
17
|
-
"opts": {
|
|
18
|
-
"encoding": "utf8",
|
|
19
|
-
"recurse": true,
|
|
20
|
-
"verbose": true,
|
|
21
|
-
"readme": "./docs/doc-src/home.md",
|
|
22
|
-
"tutorials": "./docs/doc-src/tutorials",
|
|
23
|
-
"template": "node_modules/docdash-blue",
|
|
24
|
-
"destination": "docs/API"
|
|
25
|
-
},
|
|
26
|
-
"docdash":{
|
|
27
|
-
"sort": false,
|
|
28
|
-
"search": true,
|
|
29
|
-
"collapse": true,
|
|
30
|
-
"static": true,
|
|
31
|
-
"sectionOrder": [
|
|
32
|
-
"Interfaces",
|
|
33
|
-
"Modules",
|
|
34
|
-
"Tutorials"
|
|
35
|
-
]
|
|
36
|
-
},
|
|
37
|
-
"templates": {
|
|
38
|
-
"default": {
|
|
39
|
-
"outputSourceFiles": false,
|
|
40
|
-
"useLongnameInNav": true
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
package/rollup.config.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import typescript from '@rollup/plugin-typescript'
|
|
2
|
-
import {babel} from '@rollup/plugin-babel'
|
|
3
|
-
import json from '@rollup/plugin-json'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
input: 'src/index.ts',
|
|
8
|
-
output: {
|
|
9
|
-
file: 'dist/trtc-cloud-wx.js',
|
|
10
|
-
format: 'cjs',
|
|
11
|
-
},
|
|
12
|
-
plugins: [
|
|
13
|
-
babel({
|
|
14
|
-
extensions: ['.js', '.jsx', '.es6', '.es', '.mjs', 'ts', 'tsx'],
|
|
15
|
-
}),
|
|
16
|
-
typescript(),
|
|
17
|
-
json()
|
|
18
|
-
],
|
|
19
|
-
}
|
package/sdk_publish.bash
DELETED
package/src/TaskMachine.ts
DELETED
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
export enum Handletype {
|
|
2
|
-
setPusher = 'setPusher',
|
|
3
|
-
setPlayer = 'setPlayer'
|
|
4
|
-
}
|
|
5
|
-
// 数字越高,set优先级越高
|
|
6
|
-
export const TaskMap = {
|
|
7
|
-
enterRoom: {priority: 0, type: Handletype.setPusher},
|
|
8
|
-
switchRole: {priority: 1, type: Handletype.setPusher},
|
|
9
|
-
startLocalPreview: {priority: 0, type: Handletype.setPusher},
|
|
10
|
-
stopLocalPreview: {priority: 0, type: Handletype.setPusher},
|
|
11
|
-
muteLocalVideo: {priority: 1, type: Handletype.setPusher},
|
|
12
|
-
setVideoEncoderParam: {priority: 0, type: Handletype.setPusher},
|
|
13
|
-
setLocalRenderParams: {priority: 0, type: Handletype.setPusher},
|
|
14
|
-
startLocalAudio: {priority: 0, type: Handletype.setPusher},
|
|
15
|
-
stopLocalAudio: {priority: 0, type: Handletype.setPusher},
|
|
16
|
-
muteLocalAudio: {priority: 1, type: Handletype.setPusher},
|
|
17
|
-
switchCamera: {priority: 0, type: Handletype.setPusher},
|
|
18
|
-
setBeautyStyle: {priority: 0, type: Handletype.setPusher},
|
|
19
|
-
exitRoom: {priority: 9, type: Handletype.setPusher},
|
|
20
|
-
startRemoteView: {priority: 0, type: Handletype.setPlayer},
|
|
21
|
-
updateRemoteView: {priority: 0, type: Handletype.setPlayer},
|
|
22
|
-
stopAllRemoteView: {priority: 1, type: Handletype.setPlayer},
|
|
23
|
-
muteRemoteVideoStream: {priority: 1, type: Handletype.setPlayer},
|
|
24
|
-
muteAllRemoteVideoStreams: {priority: 1, type: Handletype.setPlayer},
|
|
25
|
-
setRemoteRenderParams: {priority: 0, type: Handletype.setPlayer},
|
|
26
|
-
muteRemoteAudio: {priority: 1, type: Handletype.setPlayer},
|
|
27
|
-
muteAllRemoteAudio: {priority: 1, type: Handletype.setPlayer},
|
|
28
|
-
}
|
|
29
|
-
interface TaskOptions {
|
|
30
|
-
ctx: any;
|
|
31
|
-
priority?: number;
|
|
32
|
-
action: Function;
|
|
33
|
-
args: any;
|
|
34
|
-
resolve: Function;
|
|
35
|
-
reject: Function;
|
|
36
|
-
name: string;
|
|
37
|
-
}
|
|
38
|
-
class Task {
|
|
39
|
-
public ctx: any;
|
|
40
|
-
|
|
41
|
-
public priority: number;
|
|
42
|
-
|
|
43
|
-
public action: Function
|
|
44
|
-
|
|
45
|
-
public sequenceNumber: number
|
|
46
|
-
|
|
47
|
-
public args: any
|
|
48
|
-
|
|
49
|
-
public resolve: Function
|
|
50
|
-
|
|
51
|
-
public reject: Function
|
|
52
|
-
|
|
53
|
-
public name: string
|
|
54
|
-
|
|
55
|
-
public single: boolean
|
|
56
|
-
|
|
57
|
-
public type: Handletype
|
|
58
|
-
|
|
59
|
-
public result: any
|
|
60
|
-
|
|
61
|
-
public err: any
|
|
62
|
-
|
|
63
|
-
static nextSequenceNumber = 0;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
constructor(optinos: TaskOptions) {
|
|
67
|
-
const {
|
|
68
|
-
priority = 0, action, args, resolve, reject, ctx, name
|
|
69
|
-
} = optinos
|
|
70
|
-
this.ctx = ctx
|
|
71
|
-
this.priority = priority
|
|
72
|
-
this.action = action
|
|
73
|
-
this.args = args
|
|
74
|
-
this.resolve = resolve
|
|
75
|
-
this.reject = reject
|
|
76
|
-
this.name = name
|
|
77
|
-
this.single = this.whetherSingle(name)
|
|
78
|
-
this.type = TaskMap[name]?.type || Handletype.setPusher
|
|
79
|
-
this.sequenceNumber = Task.nextSequenceNumber++
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
whetherSingle(funName: string): boolean {
|
|
83
|
-
switch (funName) {
|
|
84
|
-
case 'enterRoom':
|
|
85
|
-
return true
|
|
86
|
-
default:
|
|
87
|
-
return false
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export enum TaskQueueState {
|
|
93
|
-
IDLE = 'idle',
|
|
94
|
-
PENDING = 'pending',
|
|
95
|
-
PROCESS = 'process',
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export enum TaskQueueEvent {
|
|
99
|
-
SET = 'SET',
|
|
100
|
-
SETPROCESS = 'SETPROCESS',
|
|
101
|
-
SETDONE = 'SETDONE',
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export class TaskMachine {
|
|
105
|
-
public state: TaskQueueState;
|
|
106
|
-
|
|
107
|
-
private isProcessing = false; // 表示 pusherTaskQueue 是否正在处理
|
|
108
|
-
|
|
109
|
-
private pusherDomReady = false
|
|
110
|
-
|
|
111
|
-
private pusherTaskQueue = [] as Task[]; // 存储所有 pusher 任务
|
|
112
|
-
|
|
113
|
-
private playerTasks: Record<
|
|
114
|
-
string, {taskQueue: Task[]; isProcessing: boolean; domReady: boolean}
|
|
115
|
-
> = {}; // 存储每个 player 的任务队列
|
|
116
|
-
|
|
117
|
-
constructor() {
|
|
118
|
-
this.state = TaskQueueState.IDLE
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
reset(): void {
|
|
122
|
-
this.state = TaskQueueState.IDLE
|
|
123
|
-
this.resetPusherTasks()
|
|
124
|
-
for (const key in this.playerTasks) {
|
|
125
|
-
if (this.playerTasks[key]) {
|
|
126
|
-
this.resetPlayerTasks(key)
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
this.playerTasks = {}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
resetPusherTasks(): void {
|
|
133
|
-
this.isProcessing = false
|
|
134
|
-
this.pusherTaskQueue.forEach((task) => {
|
|
135
|
-
task.resolve()
|
|
136
|
-
})
|
|
137
|
-
this.pusherTaskQueue.length = 0
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
resetPlayerTasks(view: string): void {
|
|
141
|
-
if (this.playerTasks[view]) {
|
|
142
|
-
this.playerTasks[view].taskQueue.forEach(task => {
|
|
143
|
-
task.resolve()
|
|
144
|
-
})
|
|
145
|
-
this.playerTasks[view].taskQueue.length = 0
|
|
146
|
-
this.playerTasks[view].isProcessing = false
|
|
147
|
-
this.playerTasks[view].domReady = false
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
setPusherDomReady(isReady: boolean): boolean {
|
|
152
|
-
this.pusherDomReady = isReady
|
|
153
|
-
if (!isReady) {
|
|
154
|
-
this.resetPusherTasks()
|
|
155
|
-
}
|
|
156
|
-
return this.pusherDomReady
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
setPlayerDomReady(view: string, isReady: boolean): void {
|
|
160
|
-
if (!this.playerTasks[view]) {
|
|
161
|
-
this.playerTasks[view] = {taskQueue: [], isProcessing: false, domReady: false}
|
|
162
|
-
}
|
|
163
|
-
this.playerTasks[view].domReady = isReady
|
|
164
|
-
if (isReady) {
|
|
165
|
-
this.processPlayerTasks(view)
|
|
166
|
-
} else {
|
|
167
|
-
this.resetPlayerTasks(view)
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
send(event: TaskQueueEvent, view?: string): void {
|
|
172
|
-
switch (this.state) {
|
|
173
|
-
case TaskQueueState.IDLE:
|
|
174
|
-
if (event === TaskQueueEvent.SET) {
|
|
175
|
-
this.state = TaskQueueState.PENDING
|
|
176
|
-
if (view) {
|
|
177
|
-
this.processPlayerTasks(view)
|
|
178
|
-
} else {
|
|
179
|
-
this.processPusherTasks()
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
break
|
|
183
|
-
case TaskQueueState.PENDING:
|
|
184
|
-
if (event === TaskQueueEvent.SETPROCESS) {
|
|
185
|
-
if (view) {
|
|
186
|
-
this.processPlayerTasks(view)
|
|
187
|
-
} else {
|
|
188
|
-
this.processPusherTasks()
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
if (event === TaskQueueEvent.SETDONE) {
|
|
192
|
-
this.state = TaskQueueState.IDLE
|
|
193
|
-
}
|
|
194
|
-
break
|
|
195
|
-
case TaskQueueState.PROCESS:
|
|
196
|
-
if (event === TaskQueueEvent.SETDONE) {
|
|
197
|
-
this.state = TaskQueueState.IDLE
|
|
198
|
-
}
|
|
199
|
-
break
|
|
200
|
-
default:
|
|
201
|
-
break
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
addTask(task: Task): void {
|
|
206
|
-
if (task.type === Handletype.setPusher) {
|
|
207
|
-
this.addPusherTask(task)
|
|
208
|
-
} else {
|
|
209
|
-
this.addPlayerTask(task.args.view, task)
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
private addPusherTask(task: Task): void {
|
|
214
|
-
this.addTaskToQueue(task, this.pusherTaskQueue)
|
|
215
|
-
if (this.state === TaskQueueState.PROCESS && !this.isProcessing) {
|
|
216
|
-
this.processPusherTasks()
|
|
217
|
-
} else if (this.state === TaskQueueState.IDLE) {
|
|
218
|
-
this.send(TaskQueueEvent.SET)
|
|
219
|
-
} else if (this.state === TaskQueueState.PENDING) {
|
|
220
|
-
this.send(TaskQueueEvent.SETPROCESS)
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
private addPlayerTask(view: string, task: Task): void {
|
|
225
|
-
if (!this.playerTasks[view]) {
|
|
226
|
-
this.playerTasks[view] = {taskQueue: [], isProcessing: false, domReady: false}
|
|
227
|
-
}
|
|
228
|
-
this.addTaskToQueue(task, this.playerTasks[view].taskQueue)
|
|
229
|
-
if (this.state === TaskQueueState.PROCESS && !this.playerTasks[view].isProcessing) {
|
|
230
|
-
this.processPlayerTasks(view)
|
|
231
|
-
} else if (this.state === TaskQueueState.IDLE) {
|
|
232
|
-
this.send(TaskQueueEvent.SET, view)
|
|
233
|
-
} else if (this.state === TaskQueueState.PENDING) {
|
|
234
|
-
this.send(TaskQueueEvent.SETPROCESS, view)
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
private addTaskToQueue(task: Task, queue: Task[]): void {
|
|
239
|
-
queue.push(task)
|
|
240
|
-
queue.sort((a, b) => {
|
|
241
|
-
if (a.priority !== b.priority) {
|
|
242
|
-
return a.priority - b.priority
|
|
243
|
-
}
|
|
244
|
-
return a.sequenceNumber - b.sequenceNumber
|
|
245
|
-
})
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* 处理任务队列
|
|
250
|
-
* @param taskQueue
|
|
251
|
-
* @param isProcessing
|
|
252
|
-
* @param domReady
|
|
253
|
-
* @param setProcessing
|
|
254
|
-
* @returns
|
|
255
|
-
*/
|
|
256
|
-
private async processTasks(
|
|
257
|
-
taskQueue: Task[],
|
|
258
|
-
isProcessing: boolean,
|
|
259
|
-
domReady: boolean,
|
|
260
|
-
setProcessing: (value: boolean) => void,
|
|
261
|
-
view?: string
|
|
262
|
-
): Promise<void> {
|
|
263
|
-
if (isProcessing || !domReady || taskQueue.length === 0) return
|
|
264
|
-
setProcessing(true)
|
|
265
|
-
this.state = TaskQueueState.PROCESS
|
|
266
|
-
|
|
267
|
-
const currentTasks = [...taskQueue]
|
|
268
|
-
taskQueue.length = 0
|
|
269
|
-
const singleTasks = currentTasks.filter(task => task.single)
|
|
270
|
-
const exceptSingleTask = currentTasks.filter(task => !task.single)
|
|
271
|
-
|
|
272
|
-
for (const task of singleTasks) {
|
|
273
|
-
try {
|
|
274
|
-
task.result = await task.action.call(task.ctx, task.args, task.name, TaskMap[task.name].type)
|
|
275
|
-
} catch (err) {
|
|
276
|
-
task.err = err
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const params = exceptSingleTask.reduce(
|
|
281
|
-
(acc, cur) => {
|
|
282
|
-
const params = cur.args.params
|
|
283
|
-
return {...acc, ...(typeof params === 'function' ? params() : params)}
|
|
284
|
-
}, {}
|
|
285
|
-
)
|
|
286
|
-
const task = exceptSingleTask[0]
|
|
287
|
-
const sequenceTask = currentTasks.sort((a, b) => a.sequenceNumber - b.sequenceNumber)
|
|
288
|
-
try {
|
|
289
|
-
let r = null
|
|
290
|
-
if (task) {
|
|
291
|
-
view
|
|
292
|
-
? r = await task.action.call(
|
|
293
|
-
task.ctx,
|
|
294
|
-
{params, streamId: task.args.streamId, view},
|
|
295
|
-
task.name,
|
|
296
|
-
Handletype.setPlayer
|
|
297
|
-
)
|
|
298
|
-
: r = await task.action.call(task.ctx, {params}, task.name, Handletype.setPusher)
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
for (const task of sequenceTask) {
|
|
302
|
-
if (task.err) {
|
|
303
|
-
task.reject(task.err)
|
|
304
|
-
} else {
|
|
305
|
-
task.resolve(task.result || r)
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
} catch (err) {
|
|
309
|
-
for (const task of sequenceTask) {
|
|
310
|
-
task.reject(err)
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
setProcessing(false)
|
|
315
|
-
this.send(TaskQueueEvent.SETDONE, view)
|
|
316
|
-
|
|
317
|
-
if (taskQueue.length > 0) {
|
|
318
|
-
Promise.resolve().then(() => {
|
|
319
|
-
this.processTasks(taskQueue, isProcessing, domReady, setProcessing, view)
|
|
320
|
-
}).catch(console.error)
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
private async processPusherTasks(): Promise<void> {
|
|
325
|
-
await this.processTasks(
|
|
326
|
-
this.pusherTaskQueue,
|
|
327
|
-
this.isProcessing,
|
|
328
|
-
this.pusherDomReady,
|
|
329
|
-
(value) => { this.isProcessing = value }
|
|
330
|
-
)
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
private async processPlayerTasks(view: string): Promise<void> {
|
|
334
|
-
if (!this.playerTasks[view]) return
|
|
335
|
-
await this.processTasks(
|
|
336
|
-
this.playerTasks[view].taskQueue,
|
|
337
|
-
this.playerTasks[view].isProcessing,
|
|
338
|
-
this.playerTasks[view].domReady,
|
|
339
|
-
(value) => { this.playerTasks[view].isProcessing = value },
|
|
340
|
-
view
|
|
341
|
-
)
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
export const taskMachine = new TaskMachine()
|
|
345
|
-
interface TaskParams {
|
|
346
|
-
params: any;
|
|
347
|
-
funName: string;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
export const setHandle = (target: any, key: string, descriptor: PropertyDescriptor): PropertyDescriptor => {
|
|
351
|
-
const originalMethod = descriptor.value
|
|
352
|
-
descriptor.value = function (...args: any): Promise<any> {
|
|
353
|
-
const [params, funName] = args
|
|
354
|
-
return new Promise((resolve, reject) => {
|
|
355
|
-
try {
|
|
356
|
-
taskMachine.addTask(new Task({
|
|
357
|
-
ctx: this,
|
|
358
|
-
priority: TaskMap[funName]?.priority || 0,
|
|
359
|
-
action: originalMethod,
|
|
360
|
-
args: params,
|
|
361
|
-
name: funName,
|
|
362
|
-
resolve,
|
|
363
|
-
reject
|
|
364
|
-
}))
|
|
365
|
-
} catch (error) {
|
|
366
|
-
reject(error)
|
|
367
|
-
}
|
|
368
|
-
})
|
|
369
|
-
}
|
|
370
|
-
return descriptor
|
|
371
|
-
}
|