Skip to content

Commit d9ab728

Browse files
tmulkernjpwsutton
authored andcommitted
Removed reference to window and change to self (#116)
* Removed reference to window and change to self Removed reference to window and change to self. This is to allow the client to be used in Web Workers see: https://developer.mozilla.org/en/docs/Web/API/Window/self Signed-off-by: Tadhg Mulkern<[email protected]> * Updated Client-hareness.js Updated Client-hareness.js, set global.window = global; to global.self = global; * Update .travis.yml to fix build error Update .travis.yml to fix build error, set nodejs version to use the latest stable version of 5.x
1 parent 522b48f commit d9ab728

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
language: node_js
2+
node_js: 5
13
script:
24
mvn clean verify

src/paho-mqtt.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,9 @@ var PahoMQTT = (function (global) {
689689
* Repeat keepalive requests, monitor responses.
690690
* @ignore
691691
*/
692-
var Pinger = function(client, window, keepAliveInterval) {
692+
var Pinger = function(client, self, keepAliveInterval) {
693693
this._client = client;
694-
this._window = window;
694+
this._self = self;
695695
this._keepAliveInterval = keepAliveInterval*1000;
696696
this.isReset = false;
697697

@@ -712,28 +712,28 @@ var PahoMQTT = (function (global) {
712712
this.isReset = false;
713713
this._client._trace("Pinger.doPing", "send PINGREQ");
714714
this._client.socket.send(pingReq);
715-
this.timeout = this._window.setTimeout(doTimeout(this), this._keepAliveInterval);
715+
this.timeout = this._self.setTimeout(doTimeout(this), this._keepAliveInterval);
716716
}
717717
};
718718

719719
this.reset = function() {
720720
this.isReset = true;
721-
this._window.clearTimeout(this.timeout);
721+
this._self.clearTimeout(this.timeout);
722722
if (this._keepAliveInterval > 0)
723723
this.timeout = setTimeout(doTimeout(this), this._keepAliveInterval);
724724
};
725725

726726
this.cancel = function() {
727-
this._window.clearTimeout(this.timeout);
727+
this._self.clearTimeout(this.timeout);
728728
};
729729
};
730730

731731
/**
732732
* Monitor request completion.
733733
* @ignore
734734
*/
735-
var Timeout = function(client, window, timeoutSeconds, action, args) {
736-
this._window = window;
735+
var Timeout = function(client, self, timeoutSeconds, action, args) {
736+
this._self = self;
737737
if (!timeoutSeconds)
738738
timeoutSeconds = 30;
739739

@@ -745,7 +745,7 @@ var PahoMQTT = (function (global) {
745745
this.timeout = setTimeout(doTimeout(action, client, args), timeoutSeconds * 1000);
746746

747747
this.cancel = function() {
748-
this._window.clearTimeout(this.timeout);
748+
this._self.clearTimeout(this.timeout);
749749
};
750750
};
751751

@@ -905,7 +905,7 @@ var PahoMQTT = (function (global) {
905905
}
906906

907907
if (subscribeOptions.timeout) {
908-
wireMessage.timeOut = new Timeout(this, window, subscribeOptions.timeout, subscribeOptions.onFailure,
908+
wireMessage.timeOut = new Timeout(this, self, subscribeOptions.timeout, subscribeOptions.onFailure,
909909
[{invocationContext:subscribeOptions.invocationContext,
910910
errorCode:ERROR.SUBSCRIBE_TIMEOUT.code,
911911
errorMessage:format(ERROR.SUBSCRIBE_TIMEOUT)}]);
@@ -930,7 +930,7 @@ var PahoMQTT = (function (global) {
930930
wireMessage.callback = function() {unsubscribeOptions.onSuccess({invocationContext:unsubscribeOptions.invocationContext});};
931931
}
932932
if (unsubscribeOptions.timeout) {
933-
wireMessage.timeOut = new Timeout(this, window, unsubscribeOptions.timeout, unsubscribeOptions.onFailure,
933+
wireMessage.timeOut = new Timeout(this, self, unsubscribeOptions.timeout, unsubscribeOptions.onFailure,
934934
[{invocationContext:unsubscribeOptions.invocationContext,
935935
errorCode:ERROR.UNSUBSCRIBE_TIMEOUT.code,
936936
errorMessage:format(ERROR.UNSUBSCRIBE_TIMEOUT)}]);
@@ -1051,13 +1051,13 @@ var PahoMQTT = (function (global) {
10511051
this.socket.onerror = scope(this._on_socket_error, this);
10521052
this.socket.onclose = scope(this._on_socket_close, this);
10531053

1054-
this.sendPinger = new Pinger(this, window, this.connectOptions.keepAliveInterval);
1055-
this.receivePinger = new Pinger(this, window, this.connectOptions.keepAliveInterval);
1054+
this.sendPinger = new Pinger(this, self, this.connectOptions.keepAliveInterval);
1055+
this.receivePinger = new Pinger(this, self, this.connectOptions.keepAliveInterval);
10561056
if (this._connectTimeout) {
10571057
this._connectTimeout.cancel();
10581058
this._connectTimeout = null;
10591059
}
1060-
this._connectTimeout = new Timeout(this, window, this.connectOptions.timeout, this._disconnected, [ERROR.CONNECT_TIMEOUT.code, format(ERROR.CONNECT_TIMEOUT)]);
1060+
this._connectTimeout = new Timeout(this, self, this.connectOptions.timeout, this._disconnected, [ERROR.CONNECT_TIMEOUT.code, format(ERROR.CONNECT_TIMEOUT)]);
10611061
};
10621062

10631063

@@ -1548,7 +1548,7 @@ var PahoMQTT = (function (global) {
15481548

15491549
if (errorCode !== undefined && this._reconnecting) {
15501550
//Continue automatic reconnect process
1551-
this._reconnectTimeout = new Timeout(this, window, this._reconnectInterval, this._reconnect);
1551+
this._reconnectTimeout = new Timeout(this, self, this._reconnectInterval, this._reconnect);
15521552
return;
15531553
}
15541554

@@ -2408,6 +2408,6 @@ var PahoMQTT = (function (global) {
24082408
Client: Client,
24092409
Message: Message
24102410
};
2411-
})(window);
2411+
})(self);
24122412
return PahoMQTT;
24132413
});

src/test/client-harness.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
global.window = global;
1+
global.self = global;
22

33
var WebSocketClient = require('websocket').client;
44
var Paho = require('../paho-mqtt')

0 commit comments

Comments
 (0)