Przeglądaj źródła

增加自定义worker 与 webrtc serve

gemercheung 3 lat temu
rodzic
commit
7f27435725
13 zmienionych plików z 14594 dodań i 3028 usunięć
  1. 1356 0
      dist/libs/decoder-1.js
  2. 3 2
      package.json
  3. 11 1
      rollup.config.js
  4. 1575 0
      src/Workers-bk.js
  5. 1268 1276
      src/Workers.js
  6. 3 1
      src/main.js
  7. 7 0
      src/v2Decoder-bk/index.js
  8. 112 0
      src/v2Decoder-bk/util.js
  9. 7 0
      src/v2Decoder-bk/v2Worker.js
  10. 1353 0
      src/v2Decoder/index.js
  11. 7151 1
      src/wasm/lib264.js
  12. BIN
      src/wasm/lib_ff264dec.wasm
  13. 1748 1747
      yarn.lock

Plik diff jest za duży
+ 1356 - 0
dist/libs/decoder-1.js


+ 3 - 2
package.json

@@ -12,11 +12,12 @@
   "scripts": {
     "dev": "node --no-warnings ./scripts/build.js",
     "build": "node --no-warnings ./scripts/build.js --env=production",
-    "serve": "http-server ./dist -p 8088 -c 0 -P http://192.168.0.47 --cors",
+    "serve": "http-server ./dist -p 8088 -c 0 -P http://0.0.0.0 --cors",
     "start": "npm-run-all --parallel serve dev"
   },
   "dependencies": {
-    "axios": "^0.26.1"
+    "axios": "^0.26.1",
+    "rollup-plugin-string": "^3.0.0"
   },
   "devDependencies": {
     "@babel/core": "^7.13.14",

+ 11 - 1
rollup.config.js

@@ -5,6 +5,8 @@ import commonjs from '@rollup/plugin-commonjs'
 import babel from '@rollup/plugin-babel'
 import babelEnvConfig from './babel.env.config'
 import { terser } from 'rollup-plugin-terser'
+import { string } from "rollup-plugin-string";
+
 
 const pkg = require(`./package.json`)
 const version = pkg.version
@@ -39,7 +41,15 @@ const sdk_plugins = [
     }),
     babel(babelEnvConfig()),
     commonjs(),
-    createReplacePlugin()
+    createReplacePlugin(),
+    string({
+        // Required to be specified
+        include: "src/v2Decoder/index.js",
+  
+        // Undefined by default
+        // exclude: ["**/index.html"]
+      })
+
 ]
 
 if (isProd) {

Plik diff jest za duży
+ 1575 - 0
src/Workers-bk.js


Plik diff jest za duży
+ 1268 - 1276
src/Workers.js


+ 3 - 1
src/main.js

@@ -34,7 +34,9 @@ const l = async()=>{
             avatarId: 'KGe_Boy',
             roomId: 'e629ef3e-022d-4e64-8654-703bb96410eb',
             userId: nickname,
-            wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
+            // wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
+            wsServerUrl: "ws://localhost:6688/ws",
+            // wsServerUrl: "wss://meta-socket.4dage.com/ws",
             appId: "10016",
             token: " ",
             nickname: nickname,

+ 7 - 0
src/v2Decoder-bk/index.js

@@ -0,0 +1,7 @@
+// v2 使用元象h264 wasm
+import EventEmitter from "eventemitter3";
+
+class V2Decoder extends EventEmitter {
+  constructor() {}
+  init() {}
+}

+ 112 - 0
src/v2Decoder-bk/util.js

@@ -0,0 +1,112 @@
+/********************************************************
+Copyright (c) <2019> <copyright ErosZy>
+
+"Anti 996" License Version 1.0 (Draft)
+
+Permission is hereby granted to any individual or legal entity
+obtaining a copy of this licensed work (including the source code,
+documentation and/or related items, hereinafter collectively referred
+to as the "licensed work"), free of charge, to deal with the licensed
+work for any purpose, including without limitation, the rights to use,
+reproduce, modify, prepare derivative works of, distribute, publish
+and sublicense the licensed work, subject to the following conditions:
+
+1. The individual or the legal entity must conspicuously display,
+without modification, this License and the notice on each redistributed
+or derivative copy of the Licensed Work.
+
+2. The individual or the legal entity must strictly comply with all
+applicable laws, regulations, rules and standards of the jurisdiction
+relating to labor and employment where the individual is physically
+located or where the individual was born or naturalized; or where the
+legal entity is registered or is operating (whichever is stricter). In
+case that the jurisdiction has no such laws, regulations, rules and
+standards or its laws, regulations, rules and standards are
+unenforceable, the individual or the legal entity are required to
+comply with Core International Labor Standards.
+
+3. The individual or the legal entity shall not induce, suggest or force
+its employee(s), whether full-time or part-time, or its independent
+contractor(s), in any methods, to agree in oral or written form, to
+directly or indirectly restrict, weaken or relinquish his or her
+rights or remedies under such laws, regulations, rules and standards
+relating to labor and employment as mentioned above, no matter whether
+such written or oral agreements are enforceable under the laws of the
+said jurisdiction, nor shall such individual or the legal entity
+limit, in any methods, the rights of its employee(s) or independent
+contractor(s) from reporting or complaining to the copyright holder or
+relevant authorities monitoring the compliance of the license about
+its violation(s) of the said license.
+
+THE LICENSED WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN ANY WAY CONNECTION WITH THE
+LICENSED WORK OR THE USE OR OTHER DEALINGS IN THE LICENSED WORK.
+*********************************************************/
+
+import EventEmitter from 'eventemitter3';
+import inherits from 'inherits';
+
+export default {
+  isWeChat() {
+    return /MicroMessenger/i.test(window.navigator.userAgent);
+  },
+  workerify(func, methods = []) {
+    const funcStr = this.getFuncBody(func.toString());
+    function __Worker__(data) {
+      EventEmitter.call(this);
+      this.id = 0;
+      this.resolves = [];
+
+      const blob = new Blob([funcStr], { type: 'text/javascript' });
+      this.url = URL.createObjectURL(blob);
+      this.worker = new Worker(this.url);
+      this.worker.onmessage = message => {
+        const { id, data, destroy, type } = message.data;
+        if (destroy) {
+          this.resolves = [];
+          URL.revokeObjectURL(this.url);
+          this.worker.terminate();
+          this.worker = null;
+        } else if (type == 'event') {
+          this.emit(data.type, data.data);
+        } else {
+          for (let i = this.resolves.length - 1; i >= 0; i--) {
+            if (id == this.resolves[i].id) {
+              this.resolves[i].resolve(data);
+              this.resolves.splice(i, 1);
+              break;
+            }
+          }
+        }
+      };
+
+      this.worker.postMessage({ type: 'constructor', id: this.id++, data });
+    }
+
+    inherits(__Worker__, EventEmitter);
+
+    for (let i = 0; i < methods.length; i++) {
+      const type = methods[i];
+      __Worker__.prototype[type] = function(data) {
+        return new Promise((resolve, reject) => {
+          const id = this.id++;
+          this.resolves.push({ id, resolve, reject });
+          if (this.worker) {
+            this.worker.postMessage({ type, id, data });
+          }
+        });
+      };
+    }
+
+    return __Worker__;
+  },
+  getFuncBody(funcStr) {
+    return funcStr
+      .trim()
+      .match(/^function\s*\w*\s*\([\w\s,]*\)\s*{([\w\W]*?)}$/)[1];
+  }
+};

+ 7 - 0
src/v2Decoder-bk/v2Worker.js

@@ -0,0 +1,7 @@
+import EventEmitter from "eventemitter3";
+
+class V2Worker extends EventEmitter {
+  constructor() {
+    super();
+  }
+}

Plik diff jest za duży
+ 1353 - 0
src/v2Decoder/index.js


Plik diff jest za duży
+ 7151 - 1
src/wasm/lib264.js


BIN
src/wasm/lib_ff264dec.wasm


Plik diff jest za duży
+ 1748 - 1747
yarn.lock