Skip to content

Commit

Permalink
Merge pull request #105 from Pradhyumna02/WebSockets-Bug-Fix
Browse files Browse the repository at this point in the history
Added try catch while creating the websocket connection
  • Loading branch information
Pradhyumna02 authored Oct 9, 2017
2 parents 2b7c05f + e5de203 commit a9bc812
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "speed-testjs",
"version": "1.0.28",
"version": "1.0.29",
"description": "measure internet bandwidth",
"main": "index.js",
"author": "Maulan Byron",
Expand Down
24 changes: 16 additions & 8 deletions public/lib/webSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@
* Initiate the request
*/
webSocket.prototype.start = function () {
if (this._request === null ||
typeof this._request === 'undefined') {
this._request = new WebSocket(this.url);
this._request.onopen = this._handleOnOpen.bind(this);
this._request.onmessage = this._handleOnMessage.bind(this);
this._request.onclose = this._handleOnClose.bind(this);
this._request.onerror = this._handleOnError.bind(this);
if (this._request === null || typeof this._request === 'undefined') {
try {
this._request = new WebSocket(this.url);
this._request.onopen = this._handleOnOpen.bind(this);
this._request.onmessage = this._handleOnMessage.bind(this);
this._request.onclose = this._handleOnClose.bind(this);
this._request.onerror = this._handleOnError.bind(this);
} catch (err) {
this.callbackOnError('connection error');
}

}
};

Expand Down Expand Up @@ -96,7 +100,11 @@
* close webSocket
*/
webSocket.prototype.close = function () {
this._request.close();
try {
this._request.close();
} catch (error) { // jshint ignore:line

}
};


Expand Down

0 comments on commit a9bc812

Please sign in to comment.