|
@@ -62,21 +62,19 @@ class PromisedWebSockets {
|
|
this.closed = false
|
|
this.closed = false
|
|
this.website = this.getWebSocketLink(ip, port)
|
|
this.website = this.getWebSocketLink(ip, port)
|
|
this.client = new WebSocketClient(this.website, 'binary')
|
|
this.client = new WebSocketClient(this.website, 'binary')
|
|
- return new Promise(function(resolve, reject) {
|
|
|
|
- this.client.onopen = function() {
|
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ this.client.onopen = () => {
|
|
this.receive()
|
|
this.receive()
|
|
resolve(this)
|
|
resolve(this)
|
|
- }.bind(this)
|
|
|
|
- this.client.onerror = function(error) {
|
|
|
|
- reject(error)
|
|
|
|
}
|
|
}
|
|
- this.client.onclose = function() {
|
|
|
|
|
|
+ this.client.onerror = reject
|
|
|
|
+ this.client.onclose = () => {
|
|
if (this.client.closed) {
|
|
if (this.client.closed) {
|
|
this.resolveRead(false)
|
|
this.resolveRead(false)
|
|
this.closed = true
|
|
this.closed = true
|
|
}
|
|
}
|
|
- }.bind(this)
|
|
|
|
- }.bind(this))
|
|
|
|
|
|
+ }
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
write(data) {
|
|
write(data) {
|
|
@@ -93,7 +91,7 @@ class PromisedWebSockets {
|
|
}
|
|
}
|
|
|
|
|
|
async receive() {
|
|
async receive() {
|
|
- this.client.onmessage = async function(message) {
|
|
|
|
|
|
+ this.client.onmessage = async (message) => {
|
|
let data
|
|
let data
|
|
if (this.isBrowser) {
|
|
if (this.isBrowser) {
|
|
data = Buffer.from(await new Response(message.data).arrayBuffer())
|
|
data = Buffer.from(await new Response(message.data).arrayBuffer())
|
|
@@ -102,7 +100,7 @@ class PromisedWebSockets {
|
|
}
|
|
}
|
|
this.stream = Buffer.concat([this.stream, data])
|
|
this.stream = Buffer.concat([this.stream, data])
|
|
this.resolveRead(true)
|
|
this.resolveRead(true)
|
|
- }.bind(this)
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|