-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Make tuio.Listener as an overridable class
- Restructur the "tuio" object
- Loading branch information
Showing
6 changed files
with
134 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
|
||
tuio.connector.add('stomp', { | ||
|
||
tuio.setConnector({ | ||
_host: 'localhost', | ||
_port: 61613, | ||
_user: 'guest', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
}); | ||
|
||
function init() { | ||
tuio.connector.start(); | ||
tuio.start(); | ||
} | ||
|
||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,128 +1,145 @@ | ||
|
||
var tuio = { | ||
cursors: [], | ||
objects: [], | ||
|
||
_data: { }, | ||
|
||
_cb_object_add: function(data) { }, | ||
_cb_object_update: function(data) { }, | ||
_cb_object_remove: function(data) { }, | ||
_cb_cursor_add: function(data) { }, | ||
_cb_cursor_update: function(data) { }, | ||
_cb_cursor_remove: function(data) { }, | ||
|
||
_connectors: { }, | ||
|
||
// Callback from the main event handler | ||
|
||
callback: function(type, sid, fid, x, y, angle) { | ||
var data; | ||
|
||
if ((type != 0) && (type != 3)) { | ||
data = this._data[sid]; | ||
} | ||
else { | ||
data = { | ||
sid: sid, | ||
fid: fid | ||
(function() { | ||
var TUIO = function() { | ||
// Listener class | ||
|
||
this.Listener = function(impl) { | ||
if (impl != undefined) { | ||
// override original method implementation | ||
for (var key in impl) { | ||
this[key] = impl[key]; | ||
} | ||
} | ||
this._data[sid] = data; | ||
} | ||
|
||
data.x = x; | ||
data.y = y; | ||
|
||
if (type < 3) { | ||
data.angle = angle; | ||
} | ||
|
||
switch (type) { | ||
case 0: | ||
this.objects.push(data); | ||
this._cb_object_add(data); | ||
break; | ||
|
||
case 1: | ||
this._cb_object_update(data); | ||
break; | ||
|
||
case 2: | ||
this.objects.splice(this.objects.indexOf(data), 1); | ||
this._cb_object_remove(data); | ||
break; | ||
|
||
case 3: | ||
this.cursors.push(data); | ||
this._cb_cursor_add(data); | ||
break; | ||
|
||
case 4: | ||
this._cb_cursor_update(data); | ||
break; | ||
|
||
case 5: | ||
this.cursors.splice(this.cursors.indexOf(data), 1); | ||
this._cb_cursor_remove(data); | ||
break; | ||
|
||
default: | ||
break; | ||
this.Listener.prototype = { | ||
object_add: function(data) { }, | ||
object_update: function(data) { }, | ||
object_remove: function(data) { }, | ||
cursor_add: function(data) { }, | ||
cursor_update: function(data) { }, | ||
cursor_remove: function(data) { } | ||
} | ||
|
||
if ((type == 2) || (type == 5)) { | ||
delete this._data[sid]; | ||
} | ||
}, | ||
|
||
// Callbacks for you, developers! | ||
|
||
object_add: function(f) { this._cb_object_add = f; }, | ||
object_update: function(f) { this._cb_object_update = f; }, | ||
object_remove: function(f) { this._cb_object_remove = f; }, | ||
cursor_add: function(f) { this._cb_cursor_add = f; }, | ||
cursor_update: function(f) { this._cb_cursor_update = f; }, | ||
cursor_remove: function(f) { this._cb_cursor_remove = f; }, | ||
|
||
// Connectors. To be implemented separately. | ||
// Instance variables | ||
|
||
} | ||
this.objects = []; | ||
this.cursors = []; | ||
|
||
tuio.connector = { | ||
this._data = {}; | ||
|
||
// Register | ||
this._default_listener = new this.Listener(); | ||
this._listeners = [this._default_listener]; | ||
|
||
add: function(name, impl) { | ||
tuio._connectors[name] = impl; | ||
}, | ||
this._connector = undefined; | ||
|
||
// Start | ||
|
||
start: function(name) { | ||
this._call(name, 'start'); | ||
}, | ||
|
||
// Stop | ||
}; | ||
TUIO.prototype = { | ||
start: function(name) { | ||
var c = this._connector; | ||
if (c != undefined) { | ||
if (c.start != undefined) { | ||
c.start(); | ||
} | ||
} | ||
}, | ||
|
||
stop: function() { | ||
var c = this._connector; | ||
if (c != undefined) { | ||
if (c.stop != undefined) { | ||
c.stop(); | ||
} | ||
} | ||
}, | ||
|
||
stop: function(name) { | ||
this._call(name, 'stop'); | ||
}, | ||
setConnector: function(connector) { | ||
this._connector = connector; | ||
}, | ||
|
||
addListener: function(listener) { | ||
this._listeners.push(listener); | ||
}, | ||
removeListener: function(listener) { | ||
this._listeners.splice(this._listeners.indexOf(listener), 1); | ||
}, | ||
|
||
_invoke: function(method, data) { | ||
var i, len = this._listeners.length; | ||
for (i=0; i<len; i++) { | ||
var listener = this._listeners[i]; | ||
listener[method](data); | ||
} | ||
}, | ||
|
||
_call: function(name, method) { | ||
if (name == undefined) { | ||
for (key in tuio._connectors) { | ||
name = key; | ||
break; | ||
callback: function(type, sid, fid, x, y, angle) { | ||
var data; | ||
|
||
if ((type != 0) && (type != 3)) { | ||
data = this._data[sid]; | ||
} | ||
} | ||
else { | ||
data = { | ||
sid: sid, | ||
fid: fid | ||
} | ||
this._data[sid] = data; | ||
} | ||
|
||
data.x = x; | ||
data.y = y; | ||
|
||
if (type < 3) { | ||
data.angle = angle; | ||
} | ||
|
||
switch (type) { | ||
case 0: | ||
this.objects.push(data); | ||
this._invoke('object_add', data); | ||
break; | ||
|
||
case 1: | ||
this._invoke('object_update', data); | ||
break; | ||
|
||
case 2: | ||
this.objects.splice(this.objects.indexOf(data), 1); | ||
this._invoke('object_remove', data); | ||
break; | ||
|
||
case 3: | ||
this.cursors.push(data); | ||
this._invoke('cursor_add', data); | ||
break; | ||
|
||
case 4: | ||
this._invoke('cursor_update', data); | ||
break; | ||
|
||
case 5: | ||
this.cursors.splice(this.cursors.indexOf(data), 1); | ||
this._invoke('cursor_remove', data); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
if ((type == 2) || (type == 5)) { | ||
delete this._data[sid]; | ||
} | ||
}, | ||
|
||
if (name != undefined) { | ||
tuio._connectors[name][method](); | ||
} | ||
else { | ||
// TODO: alert user | ||
} | ||
}, | ||
// Convenient callbacks set | ||
|
||
object_add: function(f) { this._default_listener.object_add = f; }, | ||
object_update: function(f) { this._default_listener.object_update = f; }, | ||
object_remove: function(f) { this._default_listener.object_remove = f; }, | ||
cursor_add: function(f) { this._default_listener.cursor_add = f; }, | ||
cursor_update: function(f) { this._default_listener.cursor_update = f; }, | ||
cursor_remove: function(f) { this._default_listener.cursor_remove = f; } | ||
|
||
} | ||
}; | ||
this.tuio = new TUIO(); | ||
})(); | ||
|