Skip to content

Commit

Permalink
Merge pull request #46 from amio-io/fix_reconnect
Browse files Browse the repository at this point in the history
fix: fixed a case where we would get different session id after reconnect
  • Loading branch information
karelrochelt authored Sep 1, 2020
2 parents 5815d5a + 2ebbf97 commit 02a8e06
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 21 deletions.
30 changes: 21 additions & 9 deletions lib/amio-chat-sdk-web.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/amio-chat-sdk-web.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/amio-chat-sdk-web.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/amio-chat-sdk-web.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amio-chat-sdk-web",
"version": "1.4.0",
"version": "1.4.1",
"description": "Amio Chat JavaScript SDK for custom webchat implementation. https://amio.io",
"main": "lib/amio-chat-sdk-web.js",
"module": "src/amio-chat-client.js",
Expand Down
8 changes: 8 additions & 0 deletions src/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ class Connection {
reject(`Connection rejected from server. Error: ${JSON.stringify(error)}`)
})

this.socket.on('reconnect_attempt', () => {
// if we didn't set the sessionId here, we could end up with a new one after reconnect
const sessionId = session.getId()
if(sessionId) {
this.socket.io.opts.query.session_id = sessionId
}
})

this.socket.on(SOCKET_IO_DISCONNECT, () => {
this.online = false
this.connectionStateChangedHandler(this.online)
Expand Down
13 changes: 6 additions & 7 deletions src/connection/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import {

class Session {

constructor() {
_getStorage() {
if(window.localStorage) {
this.storage = window.localStorage
} else {
this.storage = new TestStorage()
return window.localStorage
}
return new TestStorage()
}

getId() {
return this.storage.getItem(STORAGE_SESSION_NAME)
return this._getStorage().getItem(STORAGE_SESSION_NAME)
}

setId(value) {
return this.storage.setItem(STORAGE_SESSION_NAME, value)
return this._getStorage().setItem(STORAGE_SESSION_NAME, value)
}

clear() {
return this.storage.removeItem(STORAGE_SESSION_NAME)
return this._getStorage().removeItem(STORAGE_SESSION_NAME)
}
}

Expand Down

0 comments on commit 02a8e06

Please sign in to comment.