mouseover on clicks will show client data
[realtime-mouse-tracking.git] / c.js
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
var host = "/";
 
function loadJs(i,s,o,g,c){
    a=s.createElement(o);m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m);
    a.onload=function(){
        c();
    }
}
loadJs(window,document,'script',host + 'socket.io-client/socket.io.js', function(){NRTT()});
 
function NRTT() {
    var connected = false;
 
    var mouseAction = {enabled: false, interval:100};
    var clickAction = {enabled : true};
 
    var cursorX, cursorY;
    document.onmousemove = function(e){
        cursorX = e.pageX;
        cursorY = e.pageY;
    }
    document.onclick = function(e){
        if (connected && clickAction.enabled) {
            cSocket.emit('t:click', {x:e.pageX, y:e.pageY});
        }
    }
    var cSocket = io();
    var color = null;
    if(typeof(Storage) !== "undefined") {
        color = localStorage.getItem('tcolor');
    }
    cSocket.emit('t:connect', {w:window.width, h:window.height, color:color});
    cSocket.on('t:connected', function(msg){
        connected = true;
        if(typeof(Storage) !== "undefined") {
            if (msg.color) {
                localStorage.setItem("tcolor", msg.color);
            }
        }
    });
    cSocket.on('disconnect', function(){
        connected = false;
    });
    cSocket.on('t:changemm', function(msg){
        mouseAction = msg;
    });
 
    cSocket.on('t:changec', function(msg){
        clickAction = msg;
    });
 
    setInterval(function(){
        if (connected && mouseAction.enabled) {
            cSocket.emit('t:mousemove', {x:cursorX,y:cursorY});
        }
    }, mouseAction.interval);
}
 
comments