|
27
|
1 |
|
|
|
2 |
var test = 0; |
|
25
|
3 |
|
|
|
4 |
(function() { |
|
|
5 |
var TUIO = function() { |
|
|
6 |
// Listener class |
|
|
7 |
|
|
|
8 |
this.Listener = function(impl) { |
|
|
9 |
if (impl != undefined) { |
|
|
10 |
// override original method implementation |
|
|
11 |
for (var key in impl) { |
|
|
12 |
this[key] = impl[key]; |
|
|
13 |
} |
|
|
14 |
} |
|
|
15 |
} |
|
|
16 |
this.Listener.prototype = { |
|
|
17 |
object_add: function(data) { }, |
|
|
18 |
object_update: function(data) { }, |
|
|
19 |
object_remove: function(data) { }, |
|
|
20 |
cursor_add: function(data) { }, |
|
|
21 |
cursor_update: function(data) { }, |
|
27
|
22 |
cursor_remove: function(data) { }, |
|
|
23 |
string_add: function(data) { }, |
|
|
24 |
string_update: function(data) { }, |
|
|
25 |
string_remove: function(data) { } |
|
25
|
26 |
} |
|
|
27 |
|
|
|
28 |
// Instance variables |
|
|
29 |
|
|
|
30 |
this.objects = []; |
|
|
31 |
this.cursors = []; |
|
27
|
32 |
this.strings = []; |
|
25
|
33 |
|
|
|
34 |
this._data = {}; |
|
|
35 |
|
|
|
36 |
this._default_listener = new this.Listener(); |
|
|
37 |
this._listeners = [this._default_listener]; |
|
|
38 |
|
|
|
39 |
this._connector = undefined; |
|
|
40 |
|
|
|
41 |
}; |
|
|
42 |
TUIO.prototype = { |
|
|
43 |
start: function(name) { |
|
|
44 |
var c = this._connector; |
|
|
45 |
if (c != undefined) { |
|
|
46 |
if (c.start != undefined) { |
|
|
47 |
c.start(); |
|
|
48 |
} |
|
|
49 |
} |
|
|
50 |
}, |
|
|
51 |
|
|
|
52 |
stop: function() { |
|
|
53 |
var c = this._connector; |
|
|
54 |
if (c != undefined) { |
|
|
55 |
if (c.stop != undefined) { |
|
|
56 |
c.stop(); |
|
|
57 |
} |
|
|
58 |
} |
|
|
59 |
}, |
|
|
60 |
|
|
|
61 |
setConnector: function(connector) { |
|
|
62 |
this._connector = connector; |
|
|
63 |
}, |
|
|
64 |
|
|
|
65 |
addListener: function(listener) { |
|
|
66 |
this._listeners.push(listener); |
|
|
67 |
}, |
|
|
68 |
removeListener: function(listener) { |
|
|
69 |
this._listeners.splice(this._listeners.indexOf(listener), 1); |
|
|
70 |
}, |
|
|
71 |
|
|
|
72 |
_invoke: function(method, data) { |
|
|
73 |
var i, len = this._listeners.length; |
|
|
74 |
for (i=0; i<len; i++) { |
|
|
75 |
var listener = this._listeners[i]; |
|
|
76 |
listener[method](data); |
|
|
77 |
} |
|
|
78 |
}, |
|
|
79 |
|
|
27
|
80 |
cursorCallback: function(type, sid, fid, x, y, z, angle) { |
|
|
81 |
if(type >= 6) |
|
|
82 |
return; |
|
|
83 |
|
|
25
|
84 |
var data; |
|
|
85 |
|
|
|
86 |
if ((type != 0) && (type != 3)) { |
|
|
87 |
data = this._data[sid]; |
|
|
88 |
} |
|
|
89 |
else { |
|
|
90 |
data = { |
|
|
91 |
sid: sid, |
|
|
92 |
fid: fid, |
|
|
93 |
path: [] |
|
|
94 |
} |
|
|
95 |
this._data[sid] = data; |
|
|
96 |
} |
|
|
97 |
|
|
26
|
98 |
data.path.push([x, y, z]); |
|
25
|
99 |
|
|
|
100 |
data.x = x; |
|
|
101 |
data.y = y; |
|
26
|
102 |
data.z = z; |
|
25
|
103 |
|
|
|
104 |
if (type < 3) { |
|
|
105 |
data.angle = angle; |
|
|
106 |
} |
|
|
107 |
|
|
|
108 |
switch (type) { |
|
|
109 |
case 0: |
|
|
110 |
this.objects.push(data); |
|
|
111 |
this._invoke('object_add', data); |
|
|
112 |
break; |
|
|
113 |
|
|
|
114 |
case 1: |
|
|
115 |
this._invoke('object_update', data); |
|
|
116 |
break; |
|
|
117 |
|
|
|
118 |
case 2: |
|
|
119 |
this.objects.splice(this.objects.indexOf(data), 1); |
|
|
120 |
this._invoke('object_remove', data); |
|
|
121 |
break; |
|
|
122 |
|
|
|
123 |
case 3: |
|
|
124 |
this.cursors.push(data); |
|
|
125 |
this._invoke('cursor_add', data); |
|
|
126 |
break; |
|
|
127 |
|
|
|
128 |
case 4: |
|
|
129 |
this._invoke('cursor_update', data); |
|
|
130 |
break; |
|
|
131 |
|
|
|
132 |
case 5: |
|
|
133 |
this.cursors.splice(this.cursors.indexOf(data), 1); |
|
|
134 |
this._invoke('cursor_remove', data); |
|
|
135 |
break; |
|
|
136 |
|
|
|
137 |
default: |
|
|
138 |
break; |
|
|
139 |
} |
|
|
140 |
|
|
|
141 |
if ((type == 2) || (type == 5)) { |
|
|
142 |
delete this._data[sid]; |
|
|
143 |
} |
|
|
144 |
}, |
|
27
|
145 |
|
|
|
146 |
stringCallback: function(type, sid, code) { |
|
|
147 |
if(type < 6) |
|
|
148 |
return; |
|
|
149 |
|
|
|
150 |
var data; |
|
|
151 |
|
|
|
152 |
if ((type != 6)) { |
|
|
153 |
data = this._data[sid]; |
|
|
154 |
} |
|
|
155 |
else { |
|
|
156 |
data = { |
|
|
157 |
sid: sid, |
|
|
158 |
code: code |
|
|
159 |
} |
|
|
160 |
this._data[sid] = data; |
|
|
161 |
} |
|
|
162 |
|
|
|
163 |
//data.code = code; |
|
|
164 |
|
|
|
165 |
switch (type) { |
|
|
166 |
case 6: |
|
|
167 |
if(this.strings != null && this.strings.length <= 0) |
|
|
168 |
{ |
|
|
169 |
this.strings.push(data); |
|
|
170 |
this._invoke('string_add', data); |
|
|
171 |
test++; |
|
|
172 |
//alert(test); |
|
|
173 |
} |
|
|
174 |
break; |
|
|
175 |
|
|
|
176 |
case 7: |
|
|
177 |
this._invoke('string_update', data); |
|
|
178 |
break; |
|
|
179 |
|
|
|
180 |
case 8: |
|
|
181 |
//var str = ""; |
|
|
182 |
//for(var j = 0 ; j < this.strings.length ; j++) |
|
|
183 |
//str += "(" + this.strings[i].sid + ")" + this.strings[i].code + " "; |
|
|
184 |
//alert(str); |
|
|
185 |
//this.strings.splice(this.strings.indexOf(data), 1); |
|
|
186 |
this.strings.length = 0; |
|
|
187 |
this._invoke('string_remove', data); |
|
|
188 |
test--; |
|
|
189 |
alert(test); |
|
|
190 |
break; |
|
|
191 |
|
|
|
192 |
default: |
|
|
193 |
break; |
|
|
194 |
} |
|
|
195 |
|
|
|
196 |
if ((type == 8)) { |
|
|
197 |
delete this._data[sid]; |
|
|
198 |
} |
|
|
199 |
}, |
|
25
|
200 |
|
|
|
201 |
// Convenient callbacks set |
|
|
202 |
|
|
|
203 |
object_add: function(f) { this._default_listener.object_add = f; }, |
|
|
204 |
object_update: function(f) { this._default_listener.object_update = f; }, |
|
|
205 |
object_remove: function(f) { this._default_listener.object_remove = f; }, |
|
|
206 |
cursor_add: function(f) { this._default_listener.cursor_add = f; }, |
|
|
207 |
cursor_update: function(f) { this._default_listener.cursor_update = f; }, |
|
27
|
208 |
cursor_remove: function(f) { this._default_listener.cursor_remove = f; }, |
|
|
209 |
string_add: function(f) { this._default_listener.string_add = f; }, |
|
|
210 |
string_update: function(f) { this._default_listener.string_update = f; }, |
|
|
211 |
string_remove: function(f) { this._default_listener.string_remove = f; } |
|
25
|
212 |
|
|
|
213 |
}; |
|
|
214 |
this.tuio = new TUIO(); |
|
|
215 |
})(); |
|
|
216 |
|