1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
var ws = null;
function global_init()
{
var cb;
var el;
var parent_el;
var ws1;
/* Open Websocket */
ws1 = new WebSocket("ws://" + window.location.host + "/ws/renderer", ['json']);
ws1.onopen = function()
{
ws = this;
console.log("websocket open :)");
};
ws1.onclose = function()
{
ws = null;
console.log("websocket closed :(");
};
ws1.onerror = function(evt)
{
ws = null;
console.log("websocket error " + evt.data);
};
ws1.onmessage = function(evt)
{
console.log("Got message " + evt.data);
};
parent_el = document.getElementById("td_msg_1");
cb = new Object();
cb.func = function()
{
if(!ws)
return;
var str;
var dict = new Object();
var msg = msg_create(1, 2);
dict_set_string(dict, "meta1", "Bla1");
dict_set_int(dict, "meta2", 123);
msg_set_arg_int(msg, 0, 123);
msg_set_arg_float(msg, 1, 1.23);
msg_set_arg_long(msg, 2, 1234567890);
msg_set_arg_string(msg, 3, "Hallo" );
msg_set_arg_dictionary(msg, 4, dict );
/* TODO: Array, rgb, rgba, position */
str = JSON.stringify(msg);
console.log("Sending message: " + str);
ws.send(str);
};
el = gui_make_button("icon-info", cb, null, "");
parent_el.appendChild(el);
parent_el = document.getElementById("td_msg_2");
cb = new Object();
cb.func = function() { console.log("Button 2 pressed"); };
el = gui_make_button("icon-info", cb, null, "");
parent_el.appendChild(el);
}
|