diff --git a/lib/encodingQueue.ts b/lib/encodingQueue.ts index f0b3e40..7595bcd 100644 --- a/lib/encodingQueue.ts +++ b/lib/encodingQueue.ts @@ -2,30 +2,11 @@ import { EventEmitter } from "eventemitter3"; import logger from "./logger"; export class EncodingQueue extends EventEmitter { - readonly fileReader: FileReader = new FileReader(); - private _queue: Blob[] = []; private _processing: boolean = false; constructor() { super(); - - this.fileReader.onload = (evt) => { - this._processing = false; - - if (evt.target) { - this.emit('done', evt.target.result as ArrayBuffer); - } - - this.doNextTask(); - }; - - this.fileReader.onerror = (evt) => { - logger.error(`EncodingQueue error:`, evt); - this._processing = false; - this.destroy(); - this.emit('error', evt); - } } get queue(): Blob[] { @@ -41,6 +22,8 @@ export class EncodingQueue extends EventEmitter { } enque(blob: Blob): void { + // Need to define a `name` for the blob to make our `filereader` module process the blob + blob.name = 'mylovelylilblob'; this.queue.push(blob); if (this.processing) return; @@ -49,7 +32,6 @@ export class EncodingQueue extends EventEmitter { } destroy(): void { - this.fileReader.abort(); this._queue = []; } @@ -59,6 +41,18 @@ export class EncodingQueue extends EventEmitter { this._processing = true; - this.fileReader.readAsArrayBuffer(this.queue.shift()); + const currentBlob = this.queue.shift(); + currentBlob.arrayBuffer().then((res) => { + this._processing = false; + if (res.target) { + this.emit('done', res.target.result as ArrayBuffer); + } + this.doNextTask(); + }).catch((err) => { + logger.error(`EncodingQueue error:`, err); + this._processing = false; + this.destroy(); + this.emit('error', err); + } } -} \ No newline at end of file +} diff --git a/lib/exports.ts b/lib/exports.ts index 5772d02..63a57e3 100644 --- a/lib/exports.ts +++ b/lib/exports.ts @@ -7,7 +7,3 @@ export const peerjs = { }; export default Peer; - -(window).peerjs = peerjs; -/** @deprecated Should use peerjs namespace */ -(window).Peer = Peer; diff --git a/lib/peer.ts b/lib/peer.ts index 8f11659..9dcd105 100644 --- a/lib/peer.ts +++ b/lib/peer.ts @@ -111,11 +111,6 @@ export class Peer extends EventEmitter { }; this._options = options; - // Detect relative URL host. - if (this._options.host === "/") { - this._options.host = window.location.hostname; - } - // Set path correctly. if (this._options.path) { if (this._options.path[0] !== "/") { diff --git a/lib/supports.ts b/lib/supports.ts index 1801188..2783c43 100644 --- a/lib/supports.ts +++ b/lib/supports.ts @@ -1,7 +1,5 @@ -import { webRTCAdapter } from './adapter'; - export const Supports = new class { - readonly isIOS = ['iPad', 'iPhone', 'iPod'].includes(navigator.platform); + readonly isIOS = false; readonly supportedBrowsers = ['firefox', 'chrome', 'safari']; readonly minFirefoxVersion = 59; @@ -28,36 +26,15 @@ export const Supports = new class { } getBrowser(): string { - return webRTCAdapter.browserDetails.browser; + return 'chrome'; } getVersion(): number { - return webRTCAdapter.browserDetails.version || 0; + return this.minChromeVersion; } isUnifiedPlanSupported(): boolean { - const browser = this.getBrowser(); - const version = webRTCAdapter.browserDetails.version || 0; - - if (browser === 'chrome' && version < 72) return false; - if (browser === 'firefox' && version >= 59) return true; - if (!window.RTCRtpTransceiver || !('currentDirection' in RTCRtpTransceiver.prototype)) return false; - - let tempPc: RTCPeerConnection; - let supported = false; - - try { - tempPc = new RTCPeerConnection(); - tempPc.addTransceiver('audio'); - supported = true; - } catch (e) { } - finally { - if (tempPc) { - tempPc.close(); - } - } - - return supported; + return false; } toString(): string { @@ -69,4 +46,4 @@ export const Supports = new class { isBrowserSupported:${this.isBrowserSupported()} isUnifiedPlanSupported:${this.isUnifiedPlanSupported()}`; } -} \ No newline at end of file +} diff --git a/package.json b/package.json index bb851bd..d304972 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "parcel-bundler": "^1.12.3", "standard": "^14.1.0", "ts-node": "^8.3.0", - "typescript": "^3.6.2" + "typescript": "^3.7.2" }, "dependencies": { "@types/node": "^10.14.17",