Skip to content

Commit

Permalink
Adjust things
Browse files Browse the repository at this point in the history
  • Loading branch information
LuKks committed Feb 5, 2024
1 parent deb453e commit 3dc8351
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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' })

Expand Down
30 changes: 15 additions & 15 deletions lib/web-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -69,7 +69,7 @@ module.exports = class WebStream extends Duplex {
}

_write (data, cb) {
this.dc.send(data)
this._dc.send(data)
cb(null)
}

Expand All @@ -78,7 +78,7 @@ module.exports = class WebStream extends Duplex {
}

_destroy (cb) {
this.dc.close()
this._dc.close()
this._resolveOpened(false)
cb(null)
}
Expand All @@ -91,18 +91,18 @@ 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) {
this.destroy(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()
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 3dc8351

Please sign in to comment.