From 3dc835107d649ec30f2de0353664885a1a106274 Mon Sep 17 00:00:00 2001 From: Lucas Barrena Date: Sun, 4 Feb 2024 23:51:05 -0300 Subject: [PATCH] Adjust things --- index.js | 4 ++-- lib/web-stream.js | 30 +++++++++++++++--------------- package.json | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index 865b790..ff5837a 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const { RTCPeerConnection, RTCIceCandidate } = require('werift') +const { RTCPeerConnection, RTCIceCandidate } = require('get-webrtc') const Protomux = require('protomux') const c = require('compact-encoding') const safetyCatch = require('safety-catch') @@ -13,7 +13,7 @@ module.exports = class WebPeer { constructor (relay) { this._rtc = new RTCPeerConnection({ iceServers }) this._relay = relay - this._mux = new Protomux(relay) // Protomux.from + this._mux = Protomux.from(relay) this._channel = this._mux.createChannel({ protocol: 'hyper-webrtc/signal' }) diff --git a/lib/web-stream.js b/lib/web-stream.js index 93ef226..30ca6f5 100644 --- a/lib/web-stream.js +++ b/lib/web-stream.js @@ -5,13 +5,13 @@ module.exports = class WebStream extends Duplex { constructor (isInitiator, dc, opts = {}) { super({ mapWritable: toBuffer }) - this.dc = dc + this._dc = dc this.noiseStream = this this.rawStream = this this.isInitiator = isInitiator - this.handshakeHash = opts.handshakeHash + this.handshakeHash = opts.handshakeHash || null this._opening = null this._openedDone = null @@ -24,21 +24,21 @@ module.exports = class WebStream extends Duplex { this._onerror = onerror.bind(this) this._onclose = onclose.bind(this) - this.dc.addEventListener('open', this._onopen) - this.dc.addEventListener('message', this._onmessage) - this.dc.addEventListener('error', this._onerror) - this.dc.addEventListener('close', this._onclose) + this._dc.addEventListener('open', this._onopen) + this._dc.addEventListener('message', this._onmessage) + this._dc.addEventListener('error', this._onerror) + this._dc.addEventListener('close', this._onclose) this.resume().pause() // Open immediately } _open (cb) { - if (this.dc.readyState === 'closed' || this.dc.readyState === 'closing') { + if (this._dc.readyState === 'closed' || this._dc.readyState === 'closing') { cb(new Error('Stream is closed')) return } - if (this.dc.readyState === 'connecting') { + if (this._dc.readyState === 'connecting') { this._opening = cb return } @@ -69,7 +69,7 @@ module.exports = class WebStream extends Duplex { } _write (data, cb) { - this.dc.send(data) + this._dc.send(data) cb(null) } @@ -78,7 +78,7 @@ module.exports = class WebStream extends Duplex { } _destroy (cb) { - this.dc.close() + this._dc.close() this._resolveOpened(false) cb(null) } @@ -91,7 +91,7 @@ function onopen () { } function onmessage (event) { - this.push(event.data) // new Uint8Array(data) // b4a.from(event.data) + this.push(b4a.from(event.data)) } function onerror (err) { @@ -99,10 +99,10 @@ function onerror (err) { } function onclose () { - this.dc.removeEventListener('open', this._onopen) - this.dc.removeEventListener('message', this._onmessage) - this.dc.removeEventListener('error', this._onerror) - this.dc.removeEventListener('close', this._onclose) + this._dc.removeEventListener('open', this._onopen) + this._dc.removeEventListener('message', this._onmessage) + this._dc.removeEventListener('error', this._onerror) + this._dc.removeEventListener('close', this._onclose) this.destroy() } diff --git a/package.json b/package.json index 9216ca3..5ddeca2 100644 --- a/package.json +++ b/package.json @@ -20,10 +20,10 @@ "@hyperswarm/dht-relay": "^0.4.3", "b4a": "^1.6.4", "compact-encoding": "^2.13.0", + "get-webrtc": "^1.0.1", "protomux": "^3.5.1", "safety-catch": "^1.0.2", - "streamx": "^2.15.7", - "werift": "^0.19.0" + "streamx": "^2.15.7" }, "devDependencies": { "brittle": "^3.3.2",