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