Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/com/websockets/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ let create = function(endpoint, address) {
}
}

/**
* Check to detect the environment
* https://stackoverflow.com/questions/17575790/environment-detection-node-js-or-browser
*/
let isBrowser = function() {
try {
return this === window;
}
catch(e){
return false;
}
}

/**
* Tries to establish a connection.
*
Expand All @@ -29,7 +42,7 @@ let create = function(endpoint, address) {
let connect = function() {
return new Promise((resolve, reject) => {
var self = this;
if (!SockJSBrowser) self.socket = new SockJSNode(self.endpoint.host + ':' + self.endpoint.port + '/w/messages');
if (!isBrowser()) self.socket = new SockJSNode(self.endpoint.host + ':' + self.endpoint.port + '/w/messages');
else self.socket = new SockJSBrowser(self.endpoint.host + ':' + self.endpoint.port + '/w/messages');
self.stompClient = Stomp.over(self.socket);
self.stompClient.debug = false;
Expand All @@ -55,4 +68,4 @@ let close = function() {

module.exports = {
create
}
}