* ascii string is sent down it every 50ms.
* If you send "reset\n" on the websocket, then
* the incrementing number is reset to 0.
- *
+ *
+ * lws-mirror-protocol: copies any received packet to every connection also
+ * using this protocol, including the sender
*/
/* lws-mirror_protocol */
#define MAX_MESSAGE_QUEUE 64
-const int MAX_COMMUNE_MEMBERS = 20;
struct per_session_data__lws_mirror {
struct libwebsocket * wsi;
};
struct a_message {
- struct per_session_data * sender;
void * payload;
size_t len;
};
static int ringbuffer_head;
-struct per_session_data * all_members;
-
-
static int
callback_lws_mirror(struct libwebsocket * wsi,
enum libwebsocket_callback_reasons reason,
break;
case LWS_CALLBACK_RECEIVE:
-// fprintf(stderr, "Received %d bytes payload\n", (int)len);
+ if (ringbuffer[ringbuffer_head].payload)
+ free(ringbuffer[ringbuffer_head].payload );
+
ringbuffer[ringbuffer_head].payload =
malloc(LWS_SEND_BUFFER_PRE_PADDING + len +
LWS_SEND_BUFFER_POST_PADDING);
ringbuffer[ringbuffer_head].len = len;
- ringbuffer[ringbuffer_head].sender = pss;
memcpy(ringbuffer[ringbuffer_head].payload +
LWS_SEND_BUFFER_PRE_PADDING, in, len);
if (ringbuffer_head == (MAX_MESSAGE_QUEUE - 1))
try {
socket_di.onopen = function() {
- wsdi_statustd.style.backgroundColor = "#40ff40";
- wsdi_status.textContent = " websocket connection opened ";
+ document.getElementById("wsdi_statustd").style.backgroundColor = "#40ff40";
+ document.getElementById("wsdi_status").textContent = " websocket connection opened ";
}
socket_di.onmessage =function got_packet(msg) {
- number.textContent = msg.data + "\n";
+ document.getElementById("number").textContent = msg.data + "\n";
}
socket_di.onclose = function(){
- wsdi_statustd.style.backgroundColor = "#ff4040";
- wsdi_status.textContent = " websocket connection closed ";
+ document.getElementById("wsdi_statustd").style.backgroundColor = "#ff4040";
+ document.getElementById("wsdi_status").textContent = " websocket connection CLOSED ";
}
} catch(exception) {
alert('<p>Error' + exception);
var down = 0;
var no_last = 1;
- var last_x, last_y;
+ var last_x = 0, last_y = 0;
var ctx;
var socket_lm = new WebSocket(get_appropriate_ws_url("127.0.0.1:7681"),
"lws-mirror-protocol");
try {
socket_lm.onopen = function() {
- wslm_statustd.style.backgroundColor = "#40ff40";
- wslm_status.textContent = " websocket connection opened ";
+ document.getElementById("wslm_statustd").style.backgroundColor = "#40ff40";
+ document.getElementById("wslm_status").textContent = " websocket connection opened ";
}
socket_lm.onmessage =function got_packet(msg) {
if (i[0] == 'd') {
ctx.strokeStyle = i[1];
ctx.beginPath();
- ctx.moveTo(i[2], i[3]);
- ctx.lineTo(i[4], i[5]);
+ ctx.moveTo(+(i[2]), +(i[3]));
+ ctx.lineTo(+(i[4]), +(i[5]));
ctx.stroke();
}
}
socket_lm.onclose = function(){
- wslm_statustd.style.backgroundColor = "#ff4040";
- wslm_status.textContent = " websocket connection closed ";
+ document.getElementById("wslm_statustd").style.backgroundColor = "#ff4040";
+ document.getElementById("wslm_status").textContent = " websocket connection CLOSED ";
}
} catch(exception) {
alert('<p>Error' + exception);
canvas.addEventListener('mousedown', ev_mousedown, false);
canvas.addEventListener('mouseup', ev_mouseup, false);
+ offsetX = offsetY = 0;
+ element = canvas;
+ if (element.offsetParent) {
+ do {
+ offsetX += element.offsetLeft;
+ offsetY += element.offsetTop;
+ } while ((element = element.offsetParent));
+ }
+
function update_color() {
color = document.getElementById("color").value;
}
function ev_mousemove (ev) {
var x, y;
- x = ev.offsetX;
- y = ev.offsetY;
+ if (ev.offsetX) {
+ x = ev.offsetX;
+ y = ev.offsetY;
+ } else {
+ x = ev.layerX - offsetX;
+ y = ev.layerY - offsetY;
+
+ }
if (!down)
return;