-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
77 lines (64 loc) · 1.64 KB
/
app.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var App = function() {
var that = this
this.minDelta = 0.05
this.x = null
this.y = null
this.windowX = 0
this.windowY = 0
this.serverAddress = null
this.serverRemoteHost = null
this.serverRemotePort = null
this.socket = null
this.run = function() {
// init socket connection
that.socket = socketConnect(that.socket, that.serverAddress);
that.socket.emit('connectToRemote', {
host: that.serverRemoteHost,
port: that.serverRemotePort
})
// register listeners
$(window).on('resize orientationchange', function() {
indicateWindowSize()
})
indicateWindowSize()
$(document).on('vmousemove', function(e) {
e.preventDefault(); // prevent scroll
var x = e.pageX / that.windowX
var y = e.pageY / that.windowY
if(that.x == null || that.y == null || Math.abs(that.x - x) > that.minDelta || Math.abs(that.y - y) > that.minDelta) {
that.x = x
that.y = y
var data = {
x: x,
y: y
}
that.socket.emit('mouseMoveToPercent', data)
//console.log(data)
//$('body').text('w:' + that.windowX + ', h: ' + that.windowY + '; x: ' + x + ', y: ' + y).html()
}
})
}
var indicateWindowSize = function() {
that.windowX = $(window).width()
that.windowY = $(window).height()
}
var socketConnect = function(socket, endpoint) {
var socket;
if(!socket) {
socket = io.connect(endpoint, {
reconnect: false
});
} else {
socket.removeAllListeners();
socket.disconnect();
socket.socket.connect(endpoint);
}
return socket;
};
var socketDisconnect = function(socket) {
if(socket) {
socket.disconnect();
socket.removeAllListeners();
}
};
}