cleanup worker migration
This commit is contained in:
parent
d57db886ac
commit
6e018288de
|
@ -4,8 +4,6 @@ import EventEmitter from 'events'
|
||||||
import { Writable, PassThrough } from 'stream'
|
import { Writable, PassThrough } from 'stream'
|
||||||
import toArrayBuffer from 'to-arraybuffer'
|
import toArrayBuffer from 'to-arraybuffer'
|
||||||
import ByteBuffer from 'bytebuffer'
|
import ByteBuffer from 'bytebuffer'
|
||||||
//import work from 'webworkify-webpack'
|
|
||||||
//import worker from './worker'
|
|
||||||
import Worker from './worker'
|
import Worker from './worker'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,8 +12,7 @@ import Worker from './worker'
|
||||||
*/
|
*/
|
||||||
class WorkerBasedMumbleConnector {
|
class WorkerBasedMumbleConnector {
|
||||||
constructor () {
|
constructor () {
|
||||||
this._worker = new Worker() //work(require.resolve('./worker'))
|
this._worker = new Worker()
|
||||||
console.log(this._worker)
|
|
||||||
this._worker.addEventListener('message', this._onMessage.bind(this))
|
this._worker.addEventListener('message', this._onMessage.bind(this))
|
||||||
this._reqId = 1
|
this._reqId = 1
|
||||||
this._requests = {}
|
this._requests = {}
|
||||||
|
|
|
@ -8,23 +8,12 @@ import CodecsBrowser from 'mumble-client-codecs-browser'
|
||||||
// Polyfill nested webworkers for https://bugs.chromium.org/p/chromium/issues/detail?id=31666
|
// Polyfill nested webworkers for https://bugs.chromium.org/p/chromium/issues/detail?id=31666
|
||||||
import 'subworkers'
|
import 'subworkers'
|
||||||
|
|
||||||
// Monkey-patch to allow webworkify-webpack and codecs to work inside of web worker
|
|
||||||
/* global URL */
|
|
||||||
//if (typeof window === 'undefined') global.window = {}
|
|
||||||
//window.URL = URL
|
|
||||||
|
|
||||||
// Using require to ensure ordering relative to monkey-patch above
|
|
||||||
//let CodecsBrowser = require('mumble-client-codecs-browser')
|
|
||||||
|
|
||||||
|
|
||||||
let sampleRate
|
let sampleRate
|
||||||
let nextClientId = 1
|
let nextClientId = 1
|
||||||
let nextVoiceId = 1
|
let nextVoiceId = 1
|
||||||
let voiceStreams = []
|
let voiceStreams = []
|
||||||
let clients = []
|
let clients = []
|
||||||
|
|
||||||
console.log('worker created!')
|
|
||||||
|
|
||||||
function postMessage (msg, transfer) {
|
function postMessage (msg, transfer) {
|
||||||
try {
|
try {
|
||||||
self.postMessage(msg, transfer)
|
self.postMessage(msg, transfer)
|
||||||
|
|
|
@ -29,7 +29,7 @@ index 3925f29..be9af92 100644
|
||||||
+export default null
|
+export default null
|
||||||
\ No newline at end of file
|
\ No newline at end of file
|
||||||
diff --git a/node_modules/mumble-client-codecs-browser/lib/decoder-stream.js b/node_modules/mumble-client-codecs-browser/lib/decoder-stream.js
|
diff --git a/node_modules/mumble-client-codecs-browser/lib/decoder-stream.js b/node_modules/mumble-client-codecs-browser/lib/decoder-stream.js
|
||||||
index 6cfda8b..eed6fa3 100644
|
index 6cfda8b..28a9549 100644
|
||||||
--- a/node_modules/mumble-client-codecs-browser/lib/decoder-stream.js
|
--- a/node_modules/mumble-client-codecs-browser/lib/decoder-stream.js
|
||||||
+++ b/node_modules/mumble-client-codecs-browser/lib/decoder-stream.js
|
+++ b/node_modules/mumble-client-codecs-browser/lib/decoder-stream.js
|
||||||
@@ -1,9 +1,5 @@
|
@@ -1,9 +1,5 @@
|
||||||
|
@ -42,28 +42,47 @@ index 6cfda8b..eed6fa3 100644
|
||||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||||
|
|
||||||
var _stream = require('stream');
|
var _stream = require('stream');
|
||||||
@@ -20,9 +16,9 @@ var _toArraybuffer = require('to-arraybuffer');
|
@@ -12,17 +8,11 @@ var _reusePool = require('reuse-pool');
|
||||||
|
|
||||||
|
var _reusePool2 = _interopRequireDefault(_reusePool);
|
||||||
|
|
||||||
|
-var _webworkify = require('webworkify');
|
||||||
|
-
|
||||||
|
-var _webworkify2 = _interopRequireDefault(_webworkify);
|
||||||
|
-
|
||||||
|
var _toArraybuffer = require('to-arraybuffer');
|
||||||
|
|
||||||
var _toArraybuffer2 = _interopRequireDefault(_toArraybuffer);
|
var _toArraybuffer2 = _interopRequireDefault(_toArraybuffer);
|
||||||
|
|
||||||
-var _decodeWorker = require('./decode-worker');
|
-var _decodeWorker = require('./decode-worker');
|
||||||
+//var _decodeWorker = require('./decode-worker');
|
-
|
||||||
|
|
||||||
-var _decodeWorker2 = _interopRequireDefault(_decodeWorker);
|
-var _decodeWorker2 = _interopRequireDefault(_decodeWorker);
|
||||||
+import _decodeWorker2 from './decode-worker';
|
+import DecodeWorker from './decode-worker';
|
||||||
|
|
||||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||||
|
|
||||||
@@ -33,7 +29,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
@@ -33,7 +23,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
||||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||||
|
|
||||||
var pool = (0, _reusePool2.default)(function () {
|
var pool = (0, _reusePool2.default)(function () {
|
||||||
- return (0, _webworkify2.default)(_decodeWorker2.default);
|
- return (0, _webworkify2.default)(_decodeWorker2.default);
|
||||||
+ return new _decodeWorker2();
|
+ return new DecodeWorker();
|
||||||
});
|
});
|
||||||
// Prepare first worker
|
// Prepare first worker
|
||||||
pool.recycle(pool.get());
|
pool.recycle(pool.get());
|
||||||
@@ -112,4 +108,5 @@ var DecoderStream = function (_Transform) {
|
@@ -48,11 +38,6 @@ var DecoderStream = function (_Transform) {
|
||||||
|
|
||||||
|
_this._worker = pool.get();
|
||||||
|
_this._worker.onmessage = function (msg) {
|
||||||
|
- if (_this._worker.objectURL) {
|
||||||
|
- // The object URL can now be revoked as the worker has been loaded
|
||||||
|
- window.URL.revokeObjectURL(_this._worker.objectURL);
|
||||||
|
- _this._worker.objectURL = null;
|
||||||
|
- }
|
||||||
|
_this._onMessage(msg.data);
|
||||||
|
};
|
||||||
|
return _this;
|
||||||
|
@@ -112,4 +97,5 @@ var DecoderStream = function (_Transform) {
|
||||||
return DecoderStream;
|
return DecoderStream;
|
||||||
}(_stream.Transform);
|
}(_stream.Transform);
|
||||||
|
|
||||||
|
@ -104,7 +123,7 @@ index f7187ab..c2ebaa3 100644
|
||||||
+export default null
|
+export default null
|
||||||
\ No newline at end of file
|
\ No newline at end of file
|
||||||
diff --git a/node_modules/mumble-client-codecs-browser/lib/encoder-stream.js b/node_modules/mumble-client-codecs-browser/lib/encoder-stream.js
|
diff --git a/node_modules/mumble-client-codecs-browser/lib/encoder-stream.js b/node_modules/mumble-client-codecs-browser/lib/encoder-stream.js
|
||||||
index 021f131..853a99e 100644
|
index 021f131..eeb9189 100644
|
||||||
--- a/node_modules/mumble-client-codecs-browser/lib/encoder-stream.js
|
--- a/node_modules/mumble-client-codecs-browser/lib/encoder-stream.js
|
||||||
+++ b/node_modules/mumble-client-codecs-browser/lib/encoder-stream.js
|
+++ b/node_modules/mumble-client-codecs-browser/lib/encoder-stream.js
|
||||||
@@ -1,9 +1,5 @@
|
@@ -1,9 +1,5 @@
|
||||||
|
@ -117,29 +136,43 @@ index 021f131..853a99e 100644
|
||||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||||
|
|
||||||
var _stream = require('stream');
|
var _stream = require('stream');
|
||||||
@@ -16,9 +12,10 @@ var _webworkify = require('webworkify');
|
@@ -12,13 +8,7 @@ var _reusePool = require('reuse-pool');
|
||||||
|
|
||||||
var _webworkify2 = _interopRequireDefault(_webworkify);
|
var _reusePool2 = _interopRequireDefault(_reusePool);
|
||||||
|
|
||||||
|
-var _webworkify = require('webworkify');
|
||||||
|
-
|
||||||
|
-var _webworkify2 = _interopRequireDefault(_webworkify);
|
||||||
|
-
|
||||||
-var _encodeWorker = require('./encode-worker');
|
-var _encodeWorker = require('./encode-worker');
|
||||||
+//var _encodeWorker = require('./encode-worker');
|
-
|
||||||
|
|
||||||
-var _encodeWorker2 = _interopRequireDefault(_encodeWorker);
|
-var _encodeWorker2 = _interopRequireDefault(_encodeWorker);
|
||||||
+//var _encodeWorker2 = _interopRequireDefault(_encodeWorker);
|
+import EncodeWorker from './encode-worker'
|
||||||
+import _encodeWorker2 from './encode-worker'
|
|
||||||
|
|
||||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||||
|
|
||||||
@@ -29,7 +26,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
@@ -29,7 +19,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
||||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||||
|
|
||||||
var pool = (0, _reusePool2.default)(function () {
|
var pool = (0, _reusePool2.default)(function () {
|
||||||
- return (0, _webworkify2.default)(_encodeWorker2.default);
|
- return (0, _webworkify2.default)(_encodeWorker2.default);
|
||||||
+ return new _encodeWorker2();
|
+ return new EncodeWorker();
|
||||||
});
|
});
|
||||||
// Prepare first worker
|
// Prepare first worker
|
||||||
pool.recycle(pool.get());
|
pool.recycle(pool.get());
|
||||||
@@ -96,4 +93,5 @@ var EncoderStream = function (_Transform) {
|
@@ -46,11 +36,6 @@ var EncoderStream = function (_Transform) {
|
||||||
|
|
||||||
|
_this._worker = pool.get();
|
||||||
|
_this._worker.onmessage = function (msg) {
|
||||||
|
- if (_this._worker.objectURL) {
|
||||||
|
- // The object URL can now be revoked as the worker has been loaded
|
||||||
|
- window.URL.revokeObjectURL(_this._worker.objectURL);
|
||||||
|
- _this._worker.objectURL = null;
|
||||||
|
- }
|
||||||
|
_this._onMessage(msg.data);
|
||||||
|
};
|
||||||
|
return _this;
|
||||||
|
@@ -96,4 +81,5 @@ var EncoderStream = function (_Transform) {
|
||||||
return EncoderStream;
|
return EncoderStream;
|
||||||
}(_stream.Transform);
|
}(_stream.Transform);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue