Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

Commit

Permalink
fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
hpihkala committed Oct 7, 2018
1 parent 8dec85c commit 2965a4f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
@@ -1,7 +1,7 @@
module.exports = exports = {
extends: 'streamr',
env: {
mocha: true,
jest: true,
},
rules: {
'no-plusplus': ["error", { "allowForLoopAfterthoughts": true }],
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -13,6 +13,7 @@
"scripts": {
"build": "NODE_ENV=production webpack",
"dev": "webpack --progress --colors --watch",
"eslint": "eslint src/** test/**",
"test": "jest",
"test-unit": "jest test/unit",
"test-integration": "jest test/integration"
Expand Down
69 changes: 34 additions & 35 deletions src/Connection.js
Expand Up @@ -30,47 +30,46 @@ class Connection extends EventEmitter {
return Promise.reject(new Error('Already connecting!'))
} else if (this.state === Connection.State.CONNECTED) {
return Promise.reject(new Error('Already connected!'))
} else {
this.socket = this.socket || new WebSocket(this.options.url)
this.socket.binaryType = 'arraybuffer'
this.socket.events = new EventEmitter()
this.socket.onopen = () => this.socket.events.emit('open')
this.socket.onclose = () => this.socket.events.emit('close')

this.updateState(Connection.State.CONNECTING)

this.socket.events.on('open', () => {
debug('Connected to ', this.options.url)
this.updateState(Connection.State.CONNECTED)
})
}
this.socket = this.socket || new WebSocket(this.options.url)
this.socket.binaryType = 'arraybuffer'
this.socket.events = new EventEmitter()
this.socket.onopen = () => this.socket.events.emit('open')
this.socket.onclose = () => this.socket.events.emit('close')

this.socket.events.on('close', () => {
if (this.state !== Connection.State.DISCONNECTING) {
debug('Connection lost. Attempting to reconnect')
setTimeout(() => {
this.connect()
}, 2000)
}
this.updateState(Connection.State.CONNECTING)

this.updateState(Connection.State.DISCONNECTED)
})
this.socket.events.on('open', () => {
debug('Connected to ', this.options.url)
this.updateState(Connection.State.CONNECTED)
})

this.socket.onmessage = (messageEvent) => {
try {
const decodedWrapper = decodeBrowserWrapper(messageEvent.data)
const decodedMessage = decodeMessage(decodedWrapper.type, decodedWrapper.msg)
this.emit(decodedWrapper.type, decodedMessage, decodedWrapper.subId)
} catch (err) {
this.emit('error', err)
}
this.socket.events.on('close', () => {
if (this.state !== Connection.State.DISCONNECTING) {
debug('Connection lost. Attempting to reconnect')
setTimeout(() => {
this.connect()
}, 2000)
}

return new Promise((resolve) => {
this.socket.events.once('open', () => {
resolve()
})
})
this.updateState(Connection.State.DISCONNECTED)
})

this.socket.onmessage = (messageEvent) => {
try {
const decodedWrapper = decodeBrowserWrapper(messageEvent.data)
const decodedMessage = decodeMessage(decodedWrapper.type, decodedWrapper.msg)
this.emit(decodedWrapper.type, decodedMessage, decodedWrapper.subId)
} catch (err) {
this.emit('error', err)
}
}

return new Promise((resolve) => {
this.socket.events.once('open', () => {
resolve()
})
})
}

disconnect() {
Expand Down
3 changes: 0 additions & 3 deletions test/mocha.opts

This file was deleted.

6 changes: 5 additions & 1 deletion test/unit/Connection.test.js
Expand Up @@ -145,7 +145,11 @@ describe('Connection', () => {
})
conn.socket.onmessage({
data: JSON.stringify([0, 0, '',
[28, 'L9xDhrevS_CE3_OA6pLVuQ', 0, 1538926879033, 0, 3445690152, 3445690148, 27, '{"t":"p","id":437.0,"lat":60.16314,"lng":24.908923,"color":"rgba(233, 87, 15, 1.0)"}']]),
[28, 'L9xDhrevS_CE3_OA6pLVuQ', 0, 1538926879033, 0,
3445690152, 3445690148, 27,
JSON.stringify({
t: 'p', id: 437.0, lat: 60.16314, lng: 24.908923, color: 'rgba(233, 87, 15, 1.0)',
})]]),
})
})

Expand Down
7 changes: 6 additions & 1 deletion test/unit/StreamrClient.test.js
Expand Up @@ -90,7 +90,12 @@ describe('StreamrClient', () => {

c.send = (msgToSend) => {
const next = c.expectedMessagesToSend.shift()
assert.deepEqual(msgToSend, next, `Sending unexpected message: ${JSON.stringify(msgToSend)}. Expected: ${JSON.stringify(next)}, Queue: ${JSON.stringify(c.expectedMessagesToSend)}`)
assert.deepEqual(
msgToSend, next,
`Sending unexpected message: ${JSON.stringify(msgToSend)}
Expected: ${JSON.stringify(next)}
Queue: ${JSON.stringify(c.expectedMessagesToSend)}`,
)
}

c.expect = (msgToExpect) => {
Expand Down

0 comments on commit 2965a4f

Please sign in to comment.