| RED.comms = (function() { | RED.comms = (function() { | ||||
| var errornotification = null; | |||||
| var subscriptions = {}; | |||||
| var ws; | |||||
| //var errornotification = null; | |||||
| //var subscriptions = {}; | |||||
| //var ws; | |||||
| function connectWS() { | function connectWS() { | ||||
| /* | |||||
| var path = location.hostname+":"+location.port+document.location.pathname; | var path = location.hostname+":"+location.port+document.location.pathname; | ||||
| path = path+(path.slice(-1) == "/"?"":"/")+"comms"; | path = path+(path.slice(-1) == "/"?"":"/")+"comms"; | ||||
| path = "ws"+(document.location.protocol=="https:"?"s":"")+"://"+path; | path = "ws"+(document.location.protocol=="https:"?"s":"")+"://"+path; | ||||
| } | } | ||||
| setTimeout(connectWS,1000); | setTimeout(connectWS,1000); | ||||
| } | } | ||||
| */ | |||||
| } | } | ||||
| function subscribe(topic,callback) { | function subscribe(topic,callback) { | ||||
| if (subscriptions[topic] == null) { | |||||
| subscriptions[topic] = []; | |||||
| } | |||||
| subscriptions[topic].push(callback); | |||||
| if (ws && ws.readyState == 1) { | |||||
| ws.send(JSON.stringify({subscribe:topic})); | |||||
| } | |||||
| //if (subscriptions[topic] == null) { | |||||
| //subscriptions[topic] = []; | |||||
| //} | |||||
| //subscriptions[topic].push(callback); | |||||
| //if (ws && ws.readyState == 1) { | |||||
| //ws.send(JSON.stringify({subscribe:topic})); | |||||
| //} | |||||
| } | } | ||||