@tencentcloud/trtc-cloud-wx 0.0.28 → 0.0.30

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.
Files changed (57) hide show
  1. package/package.json +3 -44
  2. package/{dist/trtc-cloud-wx.js → trtc-cloud-wx.js} +1 -146
  3. package/.babelrc +0 -6
  4. package/.eslintrc.json +0 -129
  5. package/build/chokidar.js +0 -19
  6. package/build/clear.js +0 -24
  7. package/build/copy.js +0 -24
  8. package/build/copy_to_roomkit.js +0 -19
  9. package/dist/package.json +0 -15
  10. package/docs/API/TRTCCloud.html +0 -4353
  11. package/docs/API/index.html +0 -98
  12. package/docs/API/scripts/add-toc.js +0 -57
  13. package/docs/API/scripts/collapse.js +0 -20
  14. package/docs/API/scripts/highlight/highlight.min.js +0 -1282
  15. package/docs/API/scripts/highlight/highlightjs-line-numbers.min.js +0 -1
  16. package/docs/API/scripts/linenumber.js +0 -25
  17. package/docs/API/scripts/nav.js +0 -12
  18. package/docs/API/scripts/polyfill.js +0 -4
  19. package/docs/API/scripts/prettify/Apache-License-2.0.txt +0 -202
  20. package/docs/API/scripts/prettify/lang-css.js +0 -2
  21. package/docs/API/scripts/prettify/prettify.js +0 -28
  22. package/docs/API/scripts/search.js +0 -83
  23. package/docs/API/styles/font.css +0 -81
  24. package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3g3D_vx3rCubqg.woff2 +0 -0
  25. package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3gTD_vx3rCubqg.woff2 +0 -0
  26. package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3gbD_vx3rCubqg.woff2 +0 -0
  27. package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3gfD_vx3rCubqg.woff2 +0 -0
  28. package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3gnD_vx3rCs.woff2 +0 -0
  29. package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459W1hyyTh89ZNpQ.woff2 +0 -0
  30. package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459WRhyyTh89ZNpQ.woff2 +0 -0
  31. package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459WZhyyTh89ZNpQ.woff2 +0 -0
  32. package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459WdhyyTh89ZNpQ.woff2 +0 -0
  33. package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459WlhyyTh89Y.woff2 +0 -0
  34. package/docs/API/styles/highlight/highlight.min.css +0 -26
  35. package/docs/API/styles/highlight/rainbow.min.css +0 -1
  36. package/docs/API/styles/jsdoc.css +0 -684
  37. package/docs/API/styles/prettify.css +0 -79
  38. package/docs/API/styles/toc.css +0 -44
  39. package/docs/API/tutorial-00-guideline.html +0 -81
  40. package/docs/doc-src/home.md +0 -7
  41. package/docs/doc-src/tutorials/00-guideline.md +0 -1
  42. package/docs/doc-src/tutorials/tutorials.json +0 -5
  43. package/jsdoc.json +0 -43
  44. package/rollup.config.js +0 -19
  45. package/sdk_publish.bash +0 -5
  46. package/src/TaskMachine.ts +0 -368
  47. package/src/deviceAuthorize.ts +0 -75
  48. package/src/index.ts +0 -1091
  49. package/src/interface/index.ts +0 -44
  50. package/src/interface/types.ts +0 -88
  51. package/src/log/logger.ts +0 -103
  52. package/src/types.d.ts +0 -1
  53. package/src/utils/common.ts +0 -67
  54. package/src/utils/index.ts +0 -2
  55. package/src/utils/translate.ts +0 -125
  56. package/tsconfig.json +0 -15
  57. 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
- }
@@ -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>
@@ -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
- 待补充
@@ -1,5 +0,0 @@
1
- {
2
- "00-guideline": {
3
- "title": "ChatEngine 使用指引"
4
- }
5
- }
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
@@ -1,5 +0,0 @@
1
- npm version patch
2
- npm run build
3
- cd ./dist
4
- npm version patch
5
- npm publish
@@ -1,368 +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.pusherDomReady = false
135
- this.pusherTaskQueue.forEach((task) => {
136
- task.resolve()
137
- })
138
- this.pusherTaskQueue.length = 0
139
- }
140
-
141
- resetPlayerTasks(view: string): void {
142
- if (this.playerTasks[view]) {
143
- this.playerTasks[view].taskQueue.forEach(task => {
144
- task.resolve()
145
- })
146
- this.playerTasks[view].taskQueue.length = 0
147
- this.playerTasks[view].isProcessing = false
148
- this.playerTasks[view].domReady = false
149
- }
150
- }
151
-
152
- setPusherDomReady(isReady: boolean): boolean {
153
- this.pusherDomReady = isReady
154
- if (!isReady) {
155
- this.resetPusherTasks()
156
- }
157
- return this.pusherDomReady
158
- }
159
-
160
- setPlayerDomReady(view: string, isReady: boolean): void {
161
- if (!this.playerTasks[view]) {
162
- this.playerTasks[view] = {taskQueue: [], isProcessing: false, domReady: false}
163
- }
164
- this.playerTasks[view].domReady = isReady
165
- if (isReady) {
166
- this.processPlayerTasks(view)
167
- } else {
168
- this.resetPlayerTasks(view)
169
- }
170
- }
171
-
172
- send(event: TaskQueueEvent, view?: string): void {
173
- switch (this.state) {
174
- case TaskQueueState.IDLE:
175
- if (event === TaskQueueEvent.SET) {
176
- this.state = TaskQueueState.PENDING
177
- if (view) {
178
- this.processPlayerTasks(view)
179
- } else {
180
- this.processPusherTasks()
181
- }
182
- }
183
- break
184
- case TaskQueueState.PENDING:
185
- if (event === TaskQueueEvent.SETPROCESS) {
186
- if (view) {
187
- this.processPlayerTasks(view)
188
- } else {
189
- this.processPusherTasks()
190
- }
191
- }
192
- if (event === TaskQueueEvent.SETDONE) {
193
- this.state = TaskQueueState.IDLE
194
- }
195
- break
196
- case TaskQueueState.PROCESS:
197
- if (event === TaskQueueEvent.SETDONE) {
198
- this.state = TaskQueueState.IDLE
199
- }
200
- break
201
- default:
202
- break
203
- }
204
- }
205
-
206
- addTask(task: Task): void {
207
- if (task.type === Handletype.setPusher) {
208
- this.addPusherTask(task)
209
- } else {
210
- this.addPlayerTask(task.args.view, task)
211
- }
212
- }
213
-
214
- private addPusherTask(task: Task): void {
215
- this.addTaskToQueue(task, this.pusherTaskQueue)
216
- if (this.state === TaskQueueState.PROCESS && !this.isProcessing) {
217
- this.processPusherTasks()
218
- } else if (this.state === TaskQueueState.IDLE) {
219
- this.send(TaskQueueEvent.SET)
220
- } else if (this.state === TaskQueueState.PENDING) {
221
- this.send(TaskQueueEvent.SETPROCESS)
222
- }
223
- }
224
-
225
- private addPlayerTask(view: string, task: Task): void {
226
- if (!this.playerTasks[view]) {
227
- this.playerTasks[view] = {taskQueue: [], isProcessing: false, domReady: false}
228
- }
229
- this.addTaskToQueue(task, this.playerTasks[view].taskQueue)
230
- if (this.state === TaskQueueState.PROCESS && !this.playerTasks[view].isProcessing) {
231
- this.processPlayerTasks(view)
232
- } else if (this.state === TaskQueueState.IDLE) {
233
- this.send(TaskQueueEvent.SET, view)
234
- } else if (this.state === TaskQueueState.PENDING) {
235
- this.send(TaskQueueEvent.SETPROCESS, view)
236
- }
237
- }
238
-
239
- private addTaskToQueue(task: Task, queue: Task[]): void {
240
- queue.push(task)
241
- queue.sort((a, b) => {
242
- if (a.priority !== b.priority) {
243
- return a.priority - b.priority
244
- }
245
- return a.sequenceNumber - b.sequenceNumber
246
- })
247
- }
248
-
249
- /**
250
- * 处理任务队列
251
- * @param taskQueue
252
- * @param isProcessing
253
- * @param domReady
254
- * @param setProcessing
255
- * @returns
256
- */
257
- private async processTasks(
258
- taskQueue: Task[],
259
- isProcessing: boolean,
260
- domReady: boolean,
261
- setProcessing: (value: boolean) => void,
262
- view?: string
263
- ): Promise<void> {
264
- if (isProcessing || !domReady || taskQueue.length === 0) return
265
- setProcessing(true)
266
- this.state = TaskQueueState.PROCESS
267
-
268
- const currentTasks = [...taskQueue]
269
- taskQueue.length = 0
270
- const singleTasks = currentTasks.filter(task => task.single)
271
- const exceptSingleTask = currentTasks.filter(task => !task.single)
272
-
273
- for (const task of singleTasks) {
274
- try {
275
- task.result = await task.action.call(task.ctx, task.args, task.name, TaskMap[task.name].type)
276
- } catch (err) {
277
- task.err = err
278
- }
279
- }
280
-
281
- const params = exceptSingleTask.reduce(
282
- (acc, cur) => {
283
- const params = cur.args.params
284
- return {...acc, ...(typeof params === 'function' ? params() : params)}
285
- }, {}
286
- )
287
- const task = exceptSingleTask[0]
288
- const sequenceTask = currentTasks.sort((a, b) => a.sequenceNumber - b.sequenceNumber)
289
- try {
290
- let r = null
291
- if (task) {
292
- view
293
- ? r = await task.action.call(
294
- task.ctx,
295
- {params, streamId: task.args.streamId, view},
296
- task.name,
297
- Handletype.setPlayer
298
- )
299
- : r = await task.action.call(task.ctx, {params}, task.name, Handletype.setPusher)
300
- }
301
-
302
- for (const task of sequenceTask) {
303
- if (task.err) {
304
- task.reject(task.err)
305
- } else {
306
- task.resolve(task.result || r)
307
- }
308
- }
309
- } catch (err) {
310
- for (const task of sequenceTask) {
311
- task.reject(err)
312
- }
313
- }
314
-
315
- setProcessing(false)
316
- this.send(TaskQueueEvent.SETDONE, view)
317
-
318
- if (taskQueue.length > 0) {
319
- Promise.resolve().then(() => {
320
- this.processTasks(taskQueue, isProcessing, domReady, setProcessing, view)
321
- }).catch(console.error)
322
- }
323
- }
324
-
325
- private async processPusherTasks(): Promise<void> {
326
- await this.processTasks(
327
- this.pusherTaskQueue,
328
- this.isProcessing,
329
- this.pusherDomReady,
330
- (value) => { this.isProcessing = value }
331
- )
332
- }
333
-
334
- private async processPlayerTasks(view: string): Promise<void> {
335
- if (!this.playerTasks[view]) return
336
- await this.processTasks(
337
- this.playerTasks[view].taskQueue,
338
- this.playerTasks[view].isProcessing,
339
- this.playerTasks[view].domReady,
340
- (value) => { this.playerTasks[view].isProcessing = value },
341
- view
342
- )
343
- }
344
- }
345
- export const taskMachine = new TaskMachine()
346
-
347
- export const setHandle = (target: any, key: string, descriptor: PropertyDescriptor): PropertyDescriptor => {
348
- const originalMethod = descriptor.value
349
- descriptor.value = function (...args: any): Promise<any> {
350
- const [params, funName] = args
351
- return new Promise((resolve, reject) => {
352
- try {
353
- taskMachine.addTask(new Task({
354
- ctx: this,
355
- priority: TaskMap[funName]?.priority || 0,
356
- action: originalMethod,
357
- args: params,
358
- name: funName,
359
- resolve,
360
- reject
361
- }))
362
- } catch (error) {
363
- reject(error)
364
- }
365
- })
366
- }
367
- return descriptor
368
- }