Skip to content

Commit

Permalink
fix ws connection
Browse files Browse the repository at this point in the history
  • Loading branch information
alsakhaev committed Dec 24, 2019
1 parent 8889915 commit 7e14c35
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/inpage/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class Connection {
[id: string]: Function[]
} = {};

private _listenableIds : string[] = [];
private _listenableIds: string[] = [];

constructor(url: string) {
this._createConnection(url);
Expand All @@ -22,7 +22,7 @@ export class Connection {
this._createConnection(url);
};
this._ws.onmessage = (e) => {

const message: { [id: string]: any } = JSON.parse(e.data);

message && Object.keys(message).forEach((id) => {
Expand All @@ -44,7 +44,9 @@ export class Connection {

this._callbacks[id].push(handler);

this._listenableIds.push(id);
if (this._listenableIds.indexOf(id) === -1) {
this._listenableIds.push(id);
}

if (this._ws.readyState === this._ws.OPEN) {
this._ws.send(id);
Expand All @@ -53,6 +55,7 @@ export class Connection {
return {
close: () => {
delete this._callbacks[id];
this._listenableIds = this._listenableIds.filter(f => f !== id);
// ToDo: publish unsubscribe to server
}
};
Expand Down

0 comments on commit 7e14c35

Please sign in to comment.