@alessmicrosystems/mpegts.js 1.8.1

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 (121) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +158 -0
  3. package/README_ja.md +153 -0
  4. package/README_zh.md +157 -0
  5. package/d.ts/mpegts.d.ts +524 -0
  6. package/d.ts/src/core/mse-events.d.ts +9 -0
  7. package/d.ts/src/core/transmuxing-events.d.ts +24 -0
  8. package/d.ts/src/demux/aac.d.ts +44 -0
  9. package/d.ts/src/demux/ac3.d.ts +70 -0
  10. package/d.ts/src/demux/av1-parser.d.ts +77 -0
  11. package/d.ts/src/demux/av1.d.ts +11 -0
  12. package/d.ts/src/demux/base-demuxer.d.ts +55 -0
  13. package/d.ts/src/demux/h264.d.ts +40 -0
  14. package/d.ts/src/demux/h265.d.ts +65 -0
  15. package/d.ts/src/demux/klv.d.ts +17 -0
  16. package/d.ts/src/demux/mp3.d.ts +6 -0
  17. package/d.ts/src/demux/mpeg4-audio.d.ts +28 -0
  18. package/d.ts/src/demux/pat-pmt-pes.d.ts +106 -0
  19. package/d.ts/src/demux/patpmt.d.ts +40 -0
  20. package/d.ts/src/demux/pes-private-data.d.ts +14 -0
  21. package/d.ts/src/demux/pgs-data.d.ts +9 -0
  22. package/d.ts/src/demux/scte35.d.ts +250 -0
  23. package/d.ts/src/demux/sei.d.ts +8 -0
  24. package/d.ts/src/demux/smpte2038.d.ts +22 -0
  25. package/d.ts/src/demux/ts-demuxer.d.ts +124 -0
  26. package/d.ts/src/player/live-latency-chaser.d.ts +10 -0
  27. package/d.ts/src/player/live-latency-synchronizer.d.ts +10 -0
  28. package/d.ts/src/player/loading-controller.d.ts +19 -0
  29. package/d.ts/src/player/mse-player.d.ts +30 -0
  30. package/d.ts/src/player/player-engine-dedicated-thread-worker.d.ts +2 -0
  31. package/d.ts/src/player/player-engine-dedicated-thread.d.ts +48 -0
  32. package/d.ts/src/player/player-engine-main-thread.d.ts +50 -0
  33. package/d.ts/src/player/player-engine-worker-cmd-def.d.ts +25 -0
  34. package/d.ts/src/player/player-engine-worker-msg-def.d.ts +54 -0
  35. package/d.ts/src/player/player-engine-worker.d.ts +2 -0
  36. package/d.ts/src/player/player-engine.d.ts +16 -0
  37. package/d.ts/src/player/player-events.d.ts +21 -0
  38. package/d.ts/src/player/seeking-handler.d.ts +22 -0
  39. package/d.ts/src/player/startup-stall-jumper.d.ts +14 -0
  40. package/d.ts/src/utils/typedarray-equality.d.ts +2 -0
  41. package/dist/mpegts.js +3 -0
  42. package/dist/mpegts.js.LICENSE.txt +7 -0
  43. package/dist/mpegts.js.map +1 -0
  44. package/package.json +53 -0
  45. package/src/config.js +67 -0
  46. package/src/core/features.js +88 -0
  47. package/src/core/media-info.js +127 -0
  48. package/src/core/media-segment-info.js +230 -0
  49. package/src/core/mse-controller.js +599 -0
  50. package/src/core/mse-events.ts +28 -0
  51. package/src/core/transmuxer.js +346 -0
  52. package/src/core/transmuxing-controller.js +628 -0
  53. package/src/core/transmuxing-events.ts +43 -0
  54. package/src/core/transmuxing-worker.js +286 -0
  55. package/src/demux/aac.ts +397 -0
  56. package/src/demux/ac3.ts +335 -0
  57. package/src/demux/amf-parser.js +243 -0
  58. package/src/demux/av1-parser.ts +629 -0
  59. package/src/demux/av1.ts +103 -0
  60. package/src/demux/base-demuxer.ts +69 -0
  61. package/src/demux/demux-errors.js +26 -0
  62. package/src/demux/exp-golomb.js +116 -0
  63. package/src/demux/flv-demuxer.js +1854 -0
  64. package/src/demux/h264.ts +187 -0
  65. package/src/demux/h265-parser.js +501 -0
  66. package/src/demux/h265.ts +214 -0
  67. package/src/demux/klv.ts +40 -0
  68. package/src/demux/mp3.ts +7 -0
  69. package/src/demux/mpeg4-audio.ts +45 -0
  70. package/src/demux/pat-pmt-pes.ts +132 -0
  71. package/src/demux/pes-private-data.ts +16 -0
  72. package/src/demux/pgs-data.ts +11 -0
  73. package/src/demux/scte35.ts +723 -0
  74. package/src/demux/sei.ts +99 -0
  75. package/src/demux/smpte2038.ts +89 -0
  76. package/src/demux/sps-parser.js +298 -0
  77. package/src/demux/ts-demuxer.ts +2405 -0
  78. package/src/index.js +4 -0
  79. package/src/io/fetch-stream-loader.js +266 -0
  80. package/src/io/io-controller.js +647 -0
  81. package/src/io/loader.js +134 -0
  82. package/src/io/param-seek-handler.js +85 -0
  83. package/src/io/range-seek-handler.js +52 -0
  84. package/src/io/speed-sampler.js +93 -0
  85. package/src/io/websocket-loader.js +151 -0
  86. package/src/io/xhr-moz-chunked-loader.js +211 -0
  87. package/src/io/xhr-msstream-loader.js +307 -0
  88. package/src/io/xhr-range-loader.js +366 -0
  89. package/src/mpegts.js +95 -0
  90. package/src/player/live-latency-chaser.ts +66 -0
  91. package/src/player/live-latency-synchronizer.ts +79 -0
  92. package/src/player/loading-controller.ts +142 -0
  93. package/src/player/mse-player.ts +150 -0
  94. package/src/player/native-player.js +262 -0
  95. package/src/player/player-engine-dedicated-thread.ts +479 -0
  96. package/src/player/player-engine-main-thread.ts +463 -0
  97. package/src/player/player-engine-worker-cmd-def.ts +62 -0
  98. package/src/player/player-engine-worker-msg-def.ts +102 -0
  99. package/src/player/player-engine-worker.ts +370 -0
  100. package/src/player/player-engine.ts +35 -0
  101. package/src/player/player-errors.js +39 -0
  102. package/src/player/player-events.ts +40 -0
  103. package/src/player/seeking-handler.ts +205 -0
  104. package/src/player/startup-stall-jumper.ts +86 -0
  105. package/src/remux/aac-silent.js +56 -0
  106. package/src/remux/mp4-generator.js +866 -0
  107. package/src/remux/mp4-remuxer.js +778 -0
  108. package/src/utils/browser.js +128 -0
  109. package/src/utils/exception.js +73 -0
  110. package/src/utils/logger.js +140 -0
  111. package/src/utils/logging-control.js +165 -0
  112. package/src/utils/polyfill.js +68 -0
  113. package/src/utils/typedarray-equality.ts +69 -0
  114. package/src/utils/utf8-conv.js +84 -0
  115. package/src/utils/webworkify-webpack.js +202 -0
  116. package/tsconfig.json +16 -0
  117. package/tslint.json +1 -0
  118. package/types/index.d.ts +3 -0
  119. package/types/test-flv.ts +8 -0
  120. package/types/tsconfig.json +24 -0
  121. package/webpack.config.js +55 -0
@@ -0,0 +1,128 @@
1
+ /*
2
+ * Copyright (C) 2016 Bilibili. All Rights Reserved.
3
+ *
4
+ * @author zheng qian <xqq@xqq.im>
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ let Browser = {};
20
+
21
+ function detect() {
22
+ // modified from jquery-browser-plugin
23
+
24
+ let ua = self.navigator.userAgent.toLowerCase();
25
+
26
+ let match = /(edge)\/([\w.]+)/.exec(ua) ||
27
+ /(opr)[\/]([\w.]+)/.exec(ua) ||
28
+ /(chrome)[ \/]([\w.]+)/.exec(ua) ||
29
+ /(iemobile)[\/]([\w.]+)/.exec(ua) ||
30
+ /(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(ua) ||
31
+ /(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(ua) ||
32
+ /(webkit)[ \/]([\w.]+)/.exec(ua) ||
33
+ /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
34
+ /(msie) ([\w.]+)/.exec(ua) ||
35
+ ua.indexOf('trident') >= 0 && /(rv)(?::| )([\w.]+)/.exec(ua) ||
36
+ ua.indexOf('compatible') < 0 && /(firefox)[ \/]([\w.]+)/.exec(ua) ||
37
+ [];
38
+
39
+ let platform_match = /(ipad)/.exec(ua) ||
40
+ /(ipod)/.exec(ua) ||
41
+ /(windows phone)/.exec(ua) ||
42
+ /(iphone)/.exec(ua) ||
43
+ /(kindle)/.exec(ua) ||
44
+ /(android)/.exec(ua) ||
45
+ /(windows)/.exec(ua) ||
46
+ /(mac)/.exec(ua) ||
47
+ /(linux)/.exec(ua) ||
48
+ /(cros)/.exec(ua) ||
49
+ [];
50
+
51
+ let matched = {
52
+ browser: match[5] || match[3] || match[1] || '',
53
+ version: match[2] || match[4] || '0',
54
+ majorVersion: match[4] || match[2] || '0',
55
+ platform: platform_match[0] || ''
56
+ };
57
+
58
+ let browser = {};
59
+ if (matched.browser) {
60
+ browser[matched.browser] = true;
61
+
62
+ let versionArray = matched.majorVersion.split('.');
63
+ browser.version = {
64
+ major: parseInt(matched.majorVersion, 10),
65
+ string: matched.version
66
+ };
67
+ if (versionArray.length > 1) {
68
+ browser.version.minor = parseInt(versionArray[1], 10);
69
+ }
70
+ if (versionArray.length > 2) {
71
+ browser.version.build = parseInt(versionArray[2], 10);
72
+ }
73
+ }
74
+
75
+ if (matched.platform) {
76
+ browser[matched.platform] = true;
77
+ }
78
+
79
+ if (browser.chrome || browser.opr || browser.safari) {
80
+ browser.webkit = true;
81
+ }
82
+
83
+ // MSIE. IE11 has 'rv' identifer
84
+ if (browser.rv || browser.iemobile) {
85
+ if (browser.rv) {
86
+ delete browser.rv;
87
+ }
88
+ let msie = 'msie';
89
+ matched.browser = msie;
90
+ browser[msie] = true;
91
+ }
92
+
93
+ // Microsoft Edge
94
+ if (browser.edge) {
95
+ delete browser.edge;
96
+ let msedge = 'msedge';
97
+ matched.browser = msedge;
98
+ browser[msedge] = true;
99
+ }
100
+
101
+ // Opera 15+
102
+ if (browser.opr) {
103
+ let opera = 'opera';
104
+ matched.browser = opera;
105
+ browser[opera] = true;
106
+ }
107
+
108
+ // Stock android browsers are marked as Safari
109
+ if (browser.safari && browser.android) {
110
+ let android = 'android';
111
+ matched.browser = android;
112
+ browser[android] = true;
113
+ }
114
+
115
+ browser.name = matched.browser;
116
+ browser.platform = matched.platform;
117
+
118
+ for (let key in Browser) {
119
+ if (Browser.hasOwnProperty(key)) {
120
+ delete Browser[key];
121
+ }
122
+ }
123
+ Object.assign(Browser, browser);
124
+ }
125
+
126
+ detect();
127
+
128
+ export default Browser;
@@ -0,0 +1,73 @@
1
+ /*
2
+ * Copyright (C) 2016 Bilibili. All Rights Reserved.
3
+ *
4
+ * @author zheng qian <xqq@xqq.im>
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ export class RuntimeException {
20
+
21
+ constructor(message) {
22
+ this._message = message;
23
+ }
24
+
25
+ get name() {
26
+ return 'RuntimeException';
27
+ }
28
+
29
+ get message() {
30
+ return this._message;
31
+ }
32
+
33
+ toString() {
34
+ return this.name + ': ' + this.message;
35
+ }
36
+
37
+ }
38
+
39
+ export class IllegalStateException extends RuntimeException {
40
+
41
+ constructor(message) {
42
+ super(message);
43
+ }
44
+
45
+ get name() {
46
+ return 'IllegalStateException';
47
+ }
48
+
49
+ }
50
+
51
+ export class InvalidArgumentException extends RuntimeException {
52
+
53
+ constructor(message) {
54
+ super(message);
55
+ }
56
+
57
+ get name() {
58
+ return 'InvalidArgumentException';
59
+ }
60
+
61
+ }
62
+
63
+ export class NotImplementedException extends RuntimeException {
64
+
65
+ constructor(message) {
66
+ super(message);
67
+ }
68
+
69
+ get name() {
70
+ return 'NotImplementedException';
71
+ }
72
+
73
+ }
@@ -0,0 +1,140 @@
1
+ /*
2
+ * Copyright (C) 2016 Bilibili. All Rights Reserved.
3
+ *
4
+ * @author zheng qian <xqq@xqq.im>
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import EventEmitter from 'events';
20
+
21
+ class Log {
22
+
23
+ static e(tag, msg) {
24
+ if (!tag || Log.FORCE_GLOBAL_TAG)
25
+ tag = Log.GLOBAL_TAG;
26
+
27
+ let str = `[${tag}] > ${msg}`;
28
+
29
+ if (Log.ENABLE_CALLBACK) {
30
+ Log.emitter.emit('log', 'error', str);
31
+ }
32
+
33
+ if (!Log.ENABLE_ERROR) {
34
+ return;
35
+ }
36
+
37
+ if (console.error) {
38
+ console.error(str);
39
+ } else if (console.warn) {
40
+ console.warn(str);
41
+ } else {
42
+ console.log(str);
43
+ }
44
+ }
45
+
46
+ static i(tag, msg) {
47
+ if (!tag || Log.FORCE_GLOBAL_TAG)
48
+ tag = Log.GLOBAL_TAG;
49
+
50
+ let str = `[${tag}] > ${msg}`;
51
+
52
+ if (Log.ENABLE_CALLBACK) {
53
+ Log.emitter.emit('log', 'info', str);
54
+ }
55
+
56
+ if (!Log.ENABLE_INFO) {
57
+ return;
58
+ }
59
+
60
+ if (console.info) {
61
+ console.info(str);
62
+ } else {
63
+ console.log(str);
64
+ }
65
+ }
66
+
67
+ static w(tag, msg) {
68
+ if (!tag || Log.FORCE_GLOBAL_TAG)
69
+ tag = Log.GLOBAL_TAG;
70
+
71
+ let str = `[${tag}] > ${msg}`;
72
+
73
+ if (Log.ENABLE_CALLBACK) {
74
+ Log.emitter.emit('log', 'warn', str);
75
+ }
76
+
77
+ if (!Log.ENABLE_WARN) {
78
+ return;
79
+ }
80
+
81
+ if (console.warn) {
82
+ console.warn(str);
83
+ } else {
84
+ console.log(str);
85
+ }
86
+ }
87
+
88
+ static d(tag, msg) {
89
+ if (!tag || Log.FORCE_GLOBAL_TAG)
90
+ tag = Log.GLOBAL_TAG;
91
+
92
+ let str = `[${tag}] > ${msg}`;
93
+
94
+ if (Log.ENABLE_CALLBACK) {
95
+ Log.emitter.emit('log', 'debug', str);
96
+ }
97
+
98
+ if (!Log.ENABLE_DEBUG) {
99
+ return;
100
+ }
101
+
102
+ if (console.debug) {
103
+ console.debug(str);
104
+ } else {
105
+ console.log(str);
106
+ }
107
+ }
108
+
109
+ static v(tag, msg) {
110
+ if (!tag || Log.FORCE_GLOBAL_TAG)
111
+ tag = Log.GLOBAL_TAG;
112
+
113
+ let str = `[${tag}] > ${msg}`;
114
+
115
+ if (Log.ENABLE_CALLBACK) {
116
+ Log.emitter.emit('log', 'verbose', str);
117
+ }
118
+
119
+ if (!Log.ENABLE_VERBOSE) {
120
+ return;
121
+ }
122
+
123
+ console.log(str);
124
+ }
125
+
126
+ }
127
+
128
+ Log.GLOBAL_TAG = 'mpegts.js';
129
+ Log.FORCE_GLOBAL_TAG = false;
130
+ Log.ENABLE_ERROR = true;
131
+ Log.ENABLE_INFO = true;
132
+ Log.ENABLE_WARN = true;
133
+ Log.ENABLE_DEBUG = true;
134
+ Log.ENABLE_VERBOSE = true;
135
+
136
+ Log.ENABLE_CALLBACK = false;
137
+
138
+ Log.emitter = new EventEmitter();
139
+
140
+ export default Log;
@@ -0,0 +1,165 @@
1
+ /*
2
+ * Copyright (C) 2016 Bilibili. All Rights Reserved.
3
+ *
4
+ * @author zheng qian <xqq@xqq.im>
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import EventEmitter from 'events';
20
+ import Log from './logger.js';
21
+
22
+ class LoggingControl {
23
+
24
+ static get forceGlobalTag() {
25
+ return Log.FORCE_GLOBAL_TAG;
26
+ }
27
+
28
+ static set forceGlobalTag(enable) {
29
+ Log.FORCE_GLOBAL_TAG = enable;
30
+ LoggingControl._notifyChange();
31
+ }
32
+
33
+ static get globalTag() {
34
+ return Log.GLOBAL_TAG;
35
+ }
36
+
37
+ static set globalTag(tag) {
38
+ Log.GLOBAL_TAG = tag;
39
+ LoggingControl._notifyChange();
40
+ }
41
+
42
+ static get enableAll() {
43
+ return Log.ENABLE_VERBOSE
44
+ && Log.ENABLE_DEBUG
45
+ && Log.ENABLE_INFO
46
+ && Log.ENABLE_WARN
47
+ && Log.ENABLE_ERROR;
48
+ }
49
+
50
+ static set enableAll(enable) {
51
+ Log.ENABLE_VERBOSE = enable;
52
+ Log.ENABLE_DEBUG = enable;
53
+ Log.ENABLE_INFO = enable;
54
+ Log.ENABLE_WARN = enable;
55
+ Log.ENABLE_ERROR = enable;
56
+ LoggingControl._notifyChange();
57
+ }
58
+
59
+ static get enableDebug() {
60
+ return Log.ENABLE_DEBUG;
61
+ }
62
+
63
+ static set enableDebug(enable) {
64
+ Log.ENABLE_DEBUG = enable;
65
+ LoggingControl._notifyChange();
66
+ }
67
+
68
+ static get enableVerbose() {
69
+ return Log.ENABLE_VERBOSE;
70
+ }
71
+
72
+ static set enableVerbose(enable) {
73
+ Log.ENABLE_VERBOSE = enable;
74
+ LoggingControl._notifyChange();
75
+ }
76
+
77
+ static get enableInfo() {
78
+ return Log.ENABLE_INFO;
79
+ }
80
+
81
+ static set enableInfo(enable) {
82
+ Log.ENABLE_INFO = enable;
83
+ LoggingControl._notifyChange();
84
+ }
85
+
86
+ static get enableWarn() {
87
+ return Log.ENABLE_WARN;
88
+ }
89
+
90
+ static set enableWarn(enable) {
91
+ Log.ENABLE_WARN = enable;
92
+ LoggingControl._notifyChange();
93
+ }
94
+
95
+ static get enableError() {
96
+ return Log.ENABLE_ERROR;
97
+ }
98
+
99
+ static set enableError(enable) {
100
+ Log.ENABLE_ERROR = enable;
101
+ LoggingControl._notifyChange();
102
+ }
103
+
104
+ static getConfig() {
105
+ return {
106
+ globalTag: Log.GLOBAL_TAG,
107
+ forceGlobalTag: Log.FORCE_GLOBAL_TAG,
108
+ enableVerbose: Log.ENABLE_VERBOSE,
109
+ enableDebug: Log.ENABLE_DEBUG,
110
+ enableInfo: Log.ENABLE_INFO,
111
+ enableWarn: Log.ENABLE_WARN,
112
+ enableError: Log.ENABLE_ERROR,
113
+ enableCallback: Log.ENABLE_CALLBACK
114
+ };
115
+ }
116
+
117
+ static applyConfig(config) {
118
+ Log.GLOBAL_TAG = config.globalTag;
119
+ Log.FORCE_GLOBAL_TAG = config.forceGlobalTag;
120
+ Log.ENABLE_VERBOSE = config.enableVerbose;
121
+ Log.ENABLE_DEBUG = config.enableDebug;
122
+ Log.ENABLE_INFO = config.enableInfo;
123
+ Log.ENABLE_WARN = config.enableWarn;
124
+ Log.ENABLE_ERROR = config.enableError;
125
+ Log.ENABLE_CALLBACK = config.enableCallback;
126
+ }
127
+
128
+ static _notifyChange() {
129
+ let emitter = LoggingControl.emitter;
130
+
131
+ if (emitter.listenerCount('change') > 0) {
132
+ let config = LoggingControl.getConfig();
133
+ emitter.emit('change', config);
134
+ }
135
+ }
136
+
137
+ static registerListener(listener) {
138
+ LoggingControl.emitter.addListener('change', listener);
139
+ }
140
+
141
+ static removeListener(listener) {
142
+ LoggingControl.emitter.removeListener('change', listener);
143
+ }
144
+
145
+ static addLogListener(listener) {
146
+ Log.emitter.addListener('log', listener);
147
+ if (Log.emitter.listenerCount('log') > 0) {
148
+ Log.ENABLE_CALLBACK = true;
149
+ LoggingControl._notifyChange();
150
+ }
151
+ }
152
+
153
+ static removeLogListener(listener) {
154
+ Log.emitter.removeListener('log', listener);
155
+ if (Log.emitter.listenerCount('log') === 0) {
156
+ Log.ENABLE_CALLBACK = false;
157
+ LoggingControl._notifyChange();
158
+ }
159
+ }
160
+
161
+ }
162
+
163
+ LoggingControl.emitter = new EventEmitter();
164
+
165
+ export default LoggingControl;
@@ -0,0 +1,68 @@
1
+ /*
2
+ * Copyright (C) 2016 Bilibili. All Rights Reserved.
3
+ *
4
+ * @author zheng qian <xqq@xqq.im>
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ class Polyfill {
20
+
21
+ static install() {
22
+ // ES6 Object.setPrototypeOf
23
+ Object.setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
24
+ obj.__proto__ = proto;
25
+ return obj;
26
+ };
27
+
28
+ // ES6 Object.assign
29
+ Object.assign = Object.assign || function (target) {
30
+ if (target === undefined || target === null) {
31
+ throw new TypeError('Cannot convert undefined or null to object');
32
+ }
33
+
34
+ let output = Object(target);
35
+ for (let i = 1; i < arguments.length; i++) {
36
+ let source = arguments[i];
37
+ if (source !== undefined && source !== null) {
38
+ for (let key in source) {
39
+ if (source.hasOwnProperty(key)) {
40
+ output[key] = source[key];
41
+ }
42
+ }
43
+ }
44
+ }
45
+ return output;
46
+ };
47
+
48
+ // String.prototype.startsWith()
49
+ if (!String.prototype.startsWith) {
50
+ Object.defineProperty(String.prototype, 'startsWith', {
51
+ value: function (search, rawPos) {
52
+ let pos = rawPos > 0 ? rawPos | 0 : 0;
53
+ return this.substring(pos, pos + search.length) === search;
54
+ }
55
+ });
56
+ }
57
+
58
+ // ES6 Promise (missing support in IE11)
59
+ if (typeof self.Promise !== 'function') {
60
+ require('es6-promise').polyfill();
61
+ }
62
+ }
63
+
64
+ }
65
+
66
+ Polyfill.install();
67
+
68
+ export default Polyfill;
@@ -0,0 +1,69 @@
1
+ /*
2
+ * Copyright (C) 2022 magicxqq. All Rights Reserved.
3
+ *
4
+ * @author magicxqq <xqq@xqq.im>
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ function isAligned16(a: Uint8Array) : boolean {
20
+ return a.byteOffset % 2 === 0 && a.byteLength % 2 === 0;
21
+ }
22
+
23
+ function isAligned32(a: Uint8Array) : boolean {
24
+ return a.byteOffset % 4 === 0 && a.byteLength % 4 === 0;
25
+ }
26
+
27
+ function compareArray(a: Uint8Array | Uint16Array | Uint32Array,
28
+ b: Uint8Array | Uint16Array | Uint32Array): boolean {
29
+ for (let i = 0; i < a.length; i++) {
30
+ if (a[i] !== b[i]) {
31
+ return false;
32
+ }
33
+ }
34
+ return true;
35
+ }
36
+
37
+ function equal8(a: Uint8Array, b: Uint8Array) : boolean {
38
+ return compareArray(a, b);
39
+ }
40
+
41
+ function equal16(a: Uint8Array, b: Uint8Array) : boolean {
42
+ let a16 = new Uint16Array(a.buffer, a.byteOffset, a.byteLength / 2);
43
+ let b16 = new Uint16Array(b.buffer, b.byteOffset, b.byteLength / 2);
44
+ return compareArray(a16, b16);
45
+ }
46
+
47
+ function equal32(a: Uint8Array, b: Uint8Array) : boolean {
48
+ let a32 = new Uint32Array(a.buffer, a.byteOffset, a.byteLength / 4);
49
+ let b32 = new Uint32Array(b.buffer, b.byteOffset, b.byteLength / 4);
50
+ return compareArray(a32, b32);
51
+ }
52
+
53
+ function buffersAreEqual(a: Uint8Array, b: Uint8Array) : boolean {
54
+ if (a.byteLength !== b.byteLength) {
55
+ return false;
56
+ }
57
+
58
+ if (isAligned32(a) && isAligned32(b)) {
59
+ return equal32(a, b);
60
+ }
61
+
62
+ if (isAligned16(a) && isAligned16(b)) {
63
+ return equal16(a, b);
64
+ }
65
+
66
+ return equal8(a, b);
67
+ }
68
+
69
+ export default buffersAreEqual;