resources/websockets.js in plezi-0.8.7 vs resources/websockets.js in plezi-0.9.0
- old
+ new
@@ -1,28 +1,29 @@
-
-// remember to set your websocket uri as an absolute path!
-var ws_uri = "ws://echo.websocket.org/";
+// Your websocket URI should be an absolute path. The following sets the base URI.
+var ws_uri = 'ws://' + window.location.hostname + (window.location.port == '' ? '' : (':' + window.location.port) );
+// remember to add the specific controller's path to your websocket URI.
+ws_uri += "/";
+// websocket variable.
var websocket = NaN
function init_websocket()
{
websocket = new WebSocket(ws_uri);
- websocket.onopen = function(e) { on_open(e) };
- websocket.onclose = function(e) { on_close(e) };
- websocket.onmessage = function(e) { on_message(e) };
- websocket.onerror = function(e) { on_error(e) }; }
-
- function on_open(e) {
+ websocket.onopen = function(e) {
// what do you want to do now?
- }
- function on_close(e) {
+ };
+
+ websocket.onclose = function(e) {
// you probably want to reopen the websocket if it closes.
init_websocket()
- }
- function on_message(e) {
+ };
+ websocket.onerror = function(e) {
// what do you want to do now?
- }
- function on_error(e) {
+ };
+ websocket.onmessage = function(e) {
// what do you want to do now?
- }
+ console.log(e.data);
+ // to use JSON, use:
+ // msg = JSON.parse(e.data); // remember to use JSON also in your Plezi controller.
+ };
}
-window.addEventListener("load", init, false);
\ No newline at end of file
+window.addEventListener("load", init_websocket, false);