socky-client-rails 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +8 -0
- data/VERSION +1 -1
- data/generators/socky/socky_generator.rb +10 -0
- data/generators/socky/templates/socky.rake +5 -0
- data/lib/tasks/socky-client-rails.rake +45 -33
- metadata +5 -5
- data/assets/socky/WebSocketMain.swf +0 -0
- data/assets/socky.js +0 -1604
data/assets/socky.js
DELETED
@@ -1,1604 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Socky push-server JavaScript client
|
3
|
-
*
|
4
|
-
* @version 0.4.1
|
5
|
-
* @author Bernard Potocki <bernard.potocki@imanel.org>
|
6
|
-
* @license The MIT license.
|
7
|
-
* @source http://github.com/socky/socky-js
|
8
|
-
*
|
9
|
-
*/
|
10
|
-
|
11
|
-
// Set URL of your WebSocketMain.swf here:
|
12
|
-
WEB_SOCKET_SWF_LOCATION = "WebSocketMain.swf";
|
13
|
-
// Set this to dump debug message from Flash to console.log:
|
14
|
-
WEB_SOCKET_DEBUG = false;
|
15
|
-
|
16
|
-
Socky = function(host, port, params) {
|
17
|
-
this.host = host;
|
18
|
-
this.port = port;
|
19
|
-
this.params = params;
|
20
|
-
this.connect();
|
21
|
-
};
|
22
|
-
|
23
|
-
// Socky states
|
24
|
-
Socky.CONNECTING = 0;
|
25
|
-
Socky.AUTHENTICATING = 1;
|
26
|
-
Socky.OPEN = 2;
|
27
|
-
Socky.CLOSED = 3;
|
28
|
-
Socky.UNAUTHENTICATED = 4;
|
29
|
-
|
30
|
-
Socky.prototype.connect = function() {
|
31
|
-
var instance = this;
|
32
|
-
instance.state = Socky.CONNECTING;
|
33
|
-
|
34
|
-
var ws = new WebSocket(this.host + ':' + this.port + '/?' + this.params);
|
35
|
-
ws.onopen = function() { instance.onopen(); };
|
36
|
-
ws.onmessage = function(evt) { instance.onmessage(evt); };
|
37
|
-
ws.onclose = function() { instance.onclose(); };
|
38
|
-
ws.onerror = function() { instance.onerror(); };
|
39
|
-
};
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
// ***** Private methods *****
|
44
|
-
// Try to avoid any modification of these methods
|
45
|
-
// Modification of these methods may cause script to work invalid
|
46
|
-
// Please see 'public methods' below
|
47
|
-
// ***************************
|
48
|
-
|
49
|
-
// Called when connection is opened
|
50
|
-
Socky.prototype.onopen = function() {
|
51
|
-
this.state = Socky.AUTHENTICATING;
|
52
|
-
this.respond_to_connect();
|
53
|
-
};
|
54
|
-
|
55
|
-
// Called when socket message is received
|
56
|
-
Socky.prototype.onmessage = function(evt) {
|
57
|
-
try {
|
58
|
-
var request = JSON.parse(evt.data);
|
59
|
-
switch (request.type) {
|
60
|
-
case "message":
|
61
|
-
this.respond_to_message(request.body);
|
62
|
-
break;
|
63
|
-
case "authentication":
|
64
|
-
if(request.body == "success") {
|
65
|
-
this.state = Socky.OPEN;
|
66
|
-
this.respond_to_authentication_success();
|
67
|
-
} else {
|
68
|
-
this.state = Socky.UNAUTHENTICATED;
|
69
|
-
this.respond_to_authentication_failure();
|
70
|
-
}
|
71
|
-
break;
|
72
|
-
}
|
73
|
-
} catch (e) {
|
74
|
-
console.error(e.toString());
|
75
|
-
}
|
76
|
-
};
|
77
|
-
|
78
|
-
// Called when socket connection is closed
|
79
|
-
Socky.prototype.onclose = function() {
|
80
|
-
if(this.state != Socky.CLOSED && this.state != Socky.UNAUTHENTICATED) {
|
81
|
-
this.respond_to_disconnect();
|
82
|
-
}
|
83
|
-
};
|
84
|
-
|
85
|
-
// Called when error occurs
|
86
|
-
// Currently unused
|
87
|
-
Socky.prototype.onerror = function() {};
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
// ***** Public methods *****
|
92
|
-
// These methods can be freely modified.
|
93
|
-
// The change should not affect the normal operation of the script.
|
94
|
-
// **************************
|
95
|
-
|
96
|
-
// Called after connection but before authentication confirmation is received
|
97
|
-
// At this point user is still not allowed to receive messages
|
98
|
-
Socky.prototype.respond_to_connect = function() {
|
99
|
-
};
|
100
|
-
|
101
|
-
// Called when authentication confirmation is received.
|
102
|
-
// At this point user will be able to receive messages
|
103
|
-
Socky.prototype.respond_to_authentication_success = function() {
|
104
|
-
};
|
105
|
-
|
106
|
-
// Called when authentication is rejected by server
|
107
|
-
// This usually means that secret is invalid or that authentication server is unavailable
|
108
|
-
// This method will NOT be called if connection with Socky server will be broken - see respond_to_disconnect
|
109
|
-
Socky.prototype.respond_to_authentication_failure = function() {
|
110
|
-
};
|
111
|
-
|
112
|
-
// Called when new message is received
|
113
|
-
// Note that msg is not sanitized - it can be any script received.
|
114
|
-
Socky.prototype.respond_to_message = function(msg) {
|
115
|
-
eval(msg);
|
116
|
-
};
|
117
|
-
|
118
|
-
// Called when connection is broken between client and server
|
119
|
-
// This usually happens when user lost his connection or when Socky server is down.
|
120
|
-
// At default it will try to reconnect after 1 second.
|
121
|
-
Socky.prototype.respond_to_disconnect = function() {
|
122
|
-
var instance = this;
|
123
|
-
setTimeout(function() { instance.connect(); }, 1000);
|
124
|
-
}
|
125
|
-
/*
|
126
|
-
http://www.JSON.org/json2.js
|
127
|
-
2010-08-25
|
128
|
-
|
129
|
-
Public Domain.
|
130
|
-
|
131
|
-
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
132
|
-
|
133
|
-
See http://www.JSON.org/js.html
|
134
|
-
|
135
|
-
|
136
|
-
This code should be minified before deployment.
|
137
|
-
See http://javascript.crockford.com/jsmin.html
|
138
|
-
|
139
|
-
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
140
|
-
NOT CONTROL.
|
141
|
-
|
142
|
-
|
143
|
-
This file creates a global JSON object containing two methods: stringify
|
144
|
-
and parse.
|
145
|
-
|
146
|
-
JSON.stringify(value, replacer, space)
|
147
|
-
value any JavaScript value, usually an object or array.
|
148
|
-
|
149
|
-
replacer an optional parameter that determines how object
|
150
|
-
values are stringified for objects. It can be a
|
151
|
-
function or an array of strings.
|
152
|
-
|
153
|
-
space an optional parameter that specifies the indentation
|
154
|
-
of nested structures. If it is omitted, the text will
|
155
|
-
be packed without extra whitespace. If it is a number,
|
156
|
-
it will specify the number of spaces to indent at each
|
157
|
-
level. If it is a string (such as '\t' or ' '),
|
158
|
-
it contains the characters used to indent at each level.
|
159
|
-
|
160
|
-
This method produces a JSON text from a JavaScript value.
|
161
|
-
|
162
|
-
When an object value is found, if the object contains a toJSON
|
163
|
-
method, its toJSON method will be called and the result will be
|
164
|
-
stringified. A toJSON method does not serialize: it returns the
|
165
|
-
value represented by the name/value pair that should be serialized,
|
166
|
-
or undefined if nothing should be serialized. The toJSON method
|
167
|
-
will be passed the key associated with the value, and this will be
|
168
|
-
bound to the value
|
169
|
-
|
170
|
-
For example, this would serialize Dates as ISO strings.
|
171
|
-
|
172
|
-
Date.prototype.toJSON = function (key) {
|
173
|
-
function f(n) {
|
174
|
-
// Format integers to have at least two digits.
|
175
|
-
return n < 10 ? '0' + n : n;
|
176
|
-
}
|
177
|
-
|
178
|
-
return this.getUTCFullYear() + '-' +
|
179
|
-
f(this.getUTCMonth() + 1) + '-' +
|
180
|
-
f(this.getUTCDate()) + 'T' +
|
181
|
-
f(this.getUTCHours()) + ':' +
|
182
|
-
f(this.getUTCMinutes()) + ':' +
|
183
|
-
f(this.getUTCSeconds()) + 'Z';
|
184
|
-
};
|
185
|
-
|
186
|
-
You can provide an optional replacer method. It will be passed the
|
187
|
-
key and value of each member, with this bound to the containing
|
188
|
-
object. The value that is returned from your method will be
|
189
|
-
serialized. If your method returns undefined, then the member will
|
190
|
-
be excluded from the serialization.
|
191
|
-
|
192
|
-
If the replacer parameter is an array of strings, then it will be
|
193
|
-
used to select the members to be serialized. It filters the results
|
194
|
-
such that only members with keys listed in the replacer array are
|
195
|
-
stringified.
|
196
|
-
|
197
|
-
Values that do not have JSON representations, such as undefined or
|
198
|
-
functions, will not be serialized. Such values in objects will be
|
199
|
-
dropped; in arrays they will be replaced with null. You can use
|
200
|
-
a replacer function to replace those with JSON values.
|
201
|
-
JSON.stringify(undefined) returns undefined.
|
202
|
-
|
203
|
-
The optional space parameter produces a stringification of the
|
204
|
-
value that is filled with line breaks and indentation to make it
|
205
|
-
easier to read.
|
206
|
-
|
207
|
-
If the space parameter is a non-empty string, then that string will
|
208
|
-
be used for indentation. If the space parameter is a number, then
|
209
|
-
the indentation will be that many spaces.
|
210
|
-
|
211
|
-
Example:
|
212
|
-
|
213
|
-
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
214
|
-
// text is '["e",{"pluribus":"unum"}]'
|
215
|
-
|
216
|
-
|
217
|
-
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
218
|
-
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
219
|
-
|
220
|
-
text = JSON.stringify([new Date()], function (key, value) {
|
221
|
-
return this[key] instanceof Date ?
|
222
|
-
'Date(' + this[key] + ')' : value;
|
223
|
-
});
|
224
|
-
// text is '["Date(---current time---)"]'
|
225
|
-
|
226
|
-
|
227
|
-
JSON.parse(text, reviver)
|
228
|
-
This method parses a JSON text to produce an object or array.
|
229
|
-
It can throw a SyntaxError exception.
|
230
|
-
|
231
|
-
The optional reviver parameter is a function that can filter and
|
232
|
-
transform the results. It receives each of the keys and values,
|
233
|
-
and its return value is used instead of the original value.
|
234
|
-
If it returns what it received, then the structure is not modified.
|
235
|
-
If it returns undefined then the member is deleted.
|
236
|
-
|
237
|
-
Example:
|
238
|
-
|
239
|
-
// Parse the text. Values that look like ISO date strings will
|
240
|
-
// be converted to Date objects.
|
241
|
-
|
242
|
-
myData = JSON.parse(text, function (key, value) {
|
243
|
-
var a;
|
244
|
-
if (typeof value === 'string') {
|
245
|
-
a =
|
246
|
-
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
247
|
-
if (a) {
|
248
|
-
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
249
|
-
+a[5], +a[6]));
|
250
|
-
}
|
251
|
-
}
|
252
|
-
return value;
|
253
|
-
});
|
254
|
-
|
255
|
-
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
256
|
-
var d;
|
257
|
-
if (typeof value === 'string' &&
|
258
|
-
value.slice(0, 5) === 'Date(' &&
|
259
|
-
value.slice(-1) === ')') {
|
260
|
-
d = new Date(value.slice(5, -1));
|
261
|
-
if (d) {
|
262
|
-
return d;
|
263
|
-
}
|
264
|
-
}
|
265
|
-
return value;
|
266
|
-
});
|
267
|
-
|
268
|
-
|
269
|
-
This is a reference implementation. You are free to copy, modify, or
|
270
|
-
redistribute.
|
271
|
-
*/
|
272
|
-
|
273
|
-
/*jslint evil: true, strict: false */
|
274
|
-
|
275
|
-
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
276
|
-
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
277
|
-
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
278
|
-
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
279
|
-
test, toJSON, toString, valueOf
|
280
|
-
*/
|
281
|
-
|
282
|
-
|
283
|
-
// Create a JSON object only if one does not already exist. We create the
|
284
|
-
// methods in a closure to avoid creating global variables.
|
285
|
-
|
286
|
-
if (!this.JSON) {
|
287
|
-
this.JSON = {};
|
288
|
-
}
|
289
|
-
|
290
|
-
(function () {
|
291
|
-
|
292
|
-
function f(n) {
|
293
|
-
// Format integers to have at least two digits.
|
294
|
-
return n < 10 ? '0' + n : n;
|
295
|
-
}
|
296
|
-
|
297
|
-
if (typeof Date.prototype.toJSON !== 'function') {
|
298
|
-
|
299
|
-
Date.prototype.toJSON = function (key) {
|
300
|
-
|
301
|
-
return isFinite(this.valueOf()) ?
|
302
|
-
this.getUTCFullYear() + '-' +
|
303
|
-
f(this.getUTCMonth() + 1) + '-' +
|
304
|
-
f(this.getUTCDate()) + 'T' +
|
305
|
-
f(this.getUTCHours()) + ':' +
|
306
|
-
f(this.getUTCMinutes()) + ':' +
|
307
|
-
f(this.getUTCSeconds()) + 'Z' : null;
|
308
|
-
};
|
309
|
-
|
310
|
-
String.prototype.toJSON =
|
311
|
-
Number.prototype.toJSON =
|
312
|
-
Boolean.prototype.toJSON = function (key) {
|
313
|
-
return this.valueOf();
|
314
|
-
};
|
315
|
-
}
|
316
|
-
|
317
|
-
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
318
|
-
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
319
|
-
gap,
|
320
|
-
indent,
|
321
|
-
meta = { // table of character substitutions
|
322
|
-
'\b': '\\b',
|
323
|
-
'\t': '\\t',
|
324
|
-
'\n': '\\n',
|
325
|
-
'\f': '\\f',
|
326
|
-
'\r': '\\r',
|
327
|
-
'"' : '\\"',
|
328
|
-
'\\': '\\\\'
|
329
|
-
},
|
330
|
-
rep;
|
331
|
-
|
332
|
-
|
333
|
-
function quote(string) {
|
334
|
-
|
335
|
-
// If the string contains no control characters, no quote characters, and no
|
336
|
-
// backslash characters, then we can safely slap some quotes around it.
|
337
|
-
// Otherwise we must also replace the offending characters with safe escape
|
338
|
-
// sequences.
|
339
|
-
|
340
|
-
escapable.lastIndex = 0;
|
341
|
-
return escapable.test(string) ?
|
342
|
-
'"' + string.replace(escapable, function (a) {
|
343
|
-
var c = meta[a];
|
344
|
-
return typeof c === 'string' ? c :
|
345
|
-
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
346
|
-
}) + '"' :
|
347
|
-
'"' + string + '"';
|
348
|
-
}
|
349
|
-
|
350
|
-
|
351
|
-
function str(key, holder) {
|
352
|
-
|
353
|
-
// Produce a string from holder[key].
|
354
|
-
|
355
|
-
var i, // The loop counter.
|
356
|
-
k, // The member key.
|
357
|
-
v, // The member value.
|
358
|
-
length,
|
359
|
-
mind = gap,
|
360
|
-
partial,
|
361
|
-
value = holder[key];
|
362
|
-
|
363
|
-
// If the value has a toJSON method, call it to obtain a replacement value.
|
364
|
-
|
365
|
-
if (value && typeof value === 'object' &&
|
366
|
-
typeof value.toJSON === 'function') {
|
367
|
-
value = value.toJSON(key);
|
368
|
-
}
|
369
|
-
|
370
|
-
// If we were called with a replacer function, then call the replacer to
|
371
|
-
// obtain a replacement value.
|
372
|
-
|
373
|
-
if (typeof rep === 'function') {
|
374
|
-
value = rep.call(holder, key, value);
|
375
|
-
}
|
376
|
-
|
377
|
-
// What happens next depends on the value's type.
|
378
|
-
|
379
|
-
switch (typeof value) {
|
380
|
-
case 'string':
|
381
|
-
return quote(value);
|
382
|
-
|
383
|
-
case 'number':
|
384
|
-
|
385
|
-
// JSON numbers must be finite. Encode non-finite numbers as null.
|
386
|
-
|
387
|
-
return isFinite(value) ? String(value) : 'null';
|
388
|
-
|
389
|
-
case 'boolean':
|
390
|
-
case 'null':
|
391
|
-
|
392
|
-
// If the value is a boolean or null, convert it to a string. Note:
|
393
|
-
// typeof null does not produce 'null'. The case is included here in
|
394
|
-
// the remote chance that this gets fixed someday.
|
395
|
-
|
396
|
-
return String(value);
|
397
|
-
|
398
|
-
// If the type is 'object', we might be dealing with an object or an array or
|
399
|
-
// null.
|
400
|
-
|
401
|
-
case 'object':
|
402
|
-
|
403
|
-
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
404
|
-
// so watch out for that case.
|
405
|
-
|
406
|
-
if (!value) {
|
407
|
-
return 'null';
|
408
|
-
}
|
409
|
-
|
410
|
-
// Make an array to hold the partial results of stringifying this object value.
|
411
|
-
|
412
|
-
gap += indent;
|
413
|
-
partial = [];
|
414
|
-
|
415
|
-
// Is the value an array?
|
416
|
-
|
417
|
-
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
418
|
-
|
419
|
-
// The value is an array. Stringify every element. Use null as a placeholder
|
420
|
-
// for non-JSON values.
|
421
|
-
|
422
|
-
length = value.length;
|
423
|
-
for (i = 0; i < length; i += 1) {
|
424
|
-
partial[i] = str(i, value) || 'null';
|
425
|
-
}
|
426
|
-
|
427
|
-
// Join all of the elements together, separated with commas, and wrap them in
|
428
|
-
// brackets.
|
429
|
-
|
430
|
-
v = partial.length === 0 ? '[]' :
|
431
|
-
gap ? '[\n' + gap +
|
432
|
-
partial.join(',\n' + gap) + '\n' +
|
433
|
-
mind + ']' :
|
434
|
-
'[' + partial.join(',') + ']';
|
435
|
-
gap = mind;
|
436
|
-
return v;
|
437
|
-
}
|
438
|
-
|
439
|
-
// If the replacer is an array, use it to select the members to be stringified.
|
440
|
-
|
441
|
-
if (rep && typeof rep === 'object') {
|
442
|
-
length = rep.length;
|
443
|
-
for (i = 0; i < length; i += 1) {
|
444
|
-
k = rep[i];
|
445
|
-
if (typeof k === 'string') {
|
446
|
-
v = str(k, value);
|
447
|
-
if (v) {
|
448
|
-
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
449
|
-
}
|
450
|
-
}
|
451
|
-
}
|
452
|
-
} else {
|
453
|
-
|
454
|
-
// Otherwise, iterate through all of the keys in the object.
|
455
|
-
|
456
|
-
for (k in value) {
|
457
|
-
if (Object.hasOwnProperty.call(value, k)) {
|
458
|
-
v = str(k, value);
|
459
|
-
if (v) {
|
460
|
-
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
461
|
-
}
|
462
|
-
}
|
463
|
-
}
|
464
|
-
}
|
465
|
-
|
466
|
-
// Join all of the member texts together, separated with commas,
|
467
|
-
// and wrap them in braces.
|
468
|
-
|
469
|
-
v = partial.length === 0 ? '{}' :
|
470
|
-
gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
|
471
|
-
mind + '}' : '{' + partial.join(',') + '}';
|
472
|
-
gap = mind;
|
473
|
-
return v;
|
474
|
-
}
|
475
|
-
}
|
476
|
-
|
477
|
-
// If the JSON object does not yet have a stringify method, give it one.
|
478
|
-
|
479
|
-
if (typeof JSON.stringify !== 'function') {
|
480
|
-
JSON.stringify = function (value, replacer, space) {
|
481
|
-
|
482
|
-
// The stringify method takes a value and an optional replacer, and an optional
|
483
|
-
// space parameter, and returns a JSON text. The replacer can be a function
|
484
|
-
// that can replace values, or an array of strings that will select the keys.
|
485
|
-
// A default replacer method can be provided. Use of the space parameter can
|
486
|
-
// produce text that is more easily readable.
|
487
|
-
|
488
|
-
var i;
|
489
|
-
gap = '';
|
490
|
-
indent = '';
|
491
|
-
|
492
|
-
// If the space parameter is a number, make an indent string containing that
|
493
|
-
// many spaces.
|
494
|
-
|
495
|
-
if (typeof space === 'number') {
|
496
|
-
for (i = 0; i < space; i += 1) {
|
497
|
-
indent += ' ';
|
498
|
-
}
|
499
|
-
|
500
|
-
// If the space parameter is a string, it will be used as the indent string.
|
501
|
-
|
502
|
-
} else if (typeof space === 'string') {
|
503
|
-
indent = space;
|
504
|
-
}
|
505
|
-
|
506
|
-
// If there is a replacer, it must be a function or an array.
|
507
|
-
// Otherwise, throw an error.
|
508
|
-
|
509
|
-
rep = replacer;
|
510
|
-
if (replacer && typeof replacer !== 'function' &&
|
511
|
-
(typeof replacer !== 'object' ||
|
512
|
-
typeof replacer.length !== 'number')) {
|
513
|
-
throw new Error('JSON.stringify');
|
514
|
-
}
|
515
|
-
|
516
|
-
// Make a fake root object containing our value under the key of ''.
|
517
|
-
// Return the result of stringifying the value.
|
518
|
-
|
519
|
-
return str('', {'': value});
|
520
|
-
};
|
521
|
-
}
|
522
|
-
|
523
|
-
|
524
|
-
// If the JSON object does not yet have a parse method, give it one.
|
525
|
-
|
526
|
-
if (typeof JSON.parse !== 'function') {
|
527
|
-
JSON.parse = function (text, reviver) {
|
528
|
-
|
529
|
-
// The parse method takes a text and an optional reviver function, and returns
|
530
|
-
// a JavaScript value if the text is a valid JSON text.
|
531
|
-
|
532
|
-
var j;
|
533
|
-
|
534
|
-
function walk(holder, key) {
|
535
|
-
|
536
|
-
// The walk method is used to recursively walk the resulting structure so
|
537
|
-
// that modifications can be made.
|
538
|
-
|
539
|
-
var k, v, value = holder[key];
|
540
|
-
if (value && typeof value === 'object') {
|
541
|
-
for (k in value) {
|
542
|
-
if (Object.hasOwnProperty.call(value, k)) {
|
543
|
-
v = walk(value, k);
|
544
|
-
if (v !== undefined) {
|
545
|
-
value[k] = v;
|
546
|
-
} else {
|
547
|
-
delete value[k];
|
548
|
-
}
|
549
|
-
}
|
550
|
-
}
|
551
|
-
}
|
552
|
-
return reviver.call(holder, key, value);
|
553
|
-
}
|
554
|
-
|
555
|
-
|
556
|
-
// Parsing happens in four stages. In the first stage, we replace certain
|
557
|
-
// Unicode characters with escape sequences. JavaScript handles many characters
|
558
|
-
// incorrectly, either silently deleting them, or treating them as line endings.
|
559
|
-
|
560
|
-
text = String(text);
|
561
|
-
cx.lastIndex = 0;
|
562
|
-
if (cx.test(text)) {
|
563
|
-
text = text.replace(cx, function (a) {
|
564
|
-
return '\\u' +
|
565
|
-
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
566
|
-
});
|
567
|
-
}
|
568
|
-
|
569
|
-
// In the second stage, we run the text against regular expressions that look
|
570
|
-
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
571
|
-
// because they can cause invocation, and '=' because it can cause mutation.
|
572
|
-
// But just to be safe, we want to reject all unexpected forms.
|
573
|
-
|
574
|
-
// We split the second stage into 4 regexp operations in order to work around
|
575
|
-
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
576
|
-
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
577
|
-
// replace all simple value tokens with ']' characters. Third, we delete all
|
578
|
-
// open brackets that follow a colon or comma or that begin the text. Finally,
|
579
|
-
// we look to see that the remaining characters are only whitespace or ']' or
|
580
|
-
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
581
|
-
|
582
|
-
if (/^[\],:{}\s]*$/
|
583
|
-
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
584
|
-
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
585
|
-
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
586
|
-
|
587
|
-
// In the third stage we use the eval function to compile the text into a
|
588
|
-
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
589
|
-
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
590
|
-
// in parens to eliminate the ambiguity.
|
591
|
-
|
592
|
-
j = eval('(' + text + ')');
|
593
|
-
|
594
|
-
// In the optional fourth stage, we recursively walk the new structure, passing
|
595
|
-
// each name/value pair to a reviver function for possible transformation.
|
596
|
-
|
597
|
-
return typeof reviver === 'function' ?
|
598
|
-
walk({'': j}, '') : j;
|
599
|
-
}
|
600
|
-
|
601
|
-
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
602
|
-
|
603
|
-
throw new SyntaxError('JSON.parse');
|
604
|
-
};
|
605
|
-
}
|
606
|
-
}());
|
607
|
-
/* SWFObject v2.2 <http://code.google.com/p/swfobject/>
|
608
|
-
is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
|
609
|
-
*/
|
610
|
-
var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]()}}function K(X){if(J){X()}else{U[U.length]=X}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false)}else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false)}else{if(typeof O.attachEvent!=D){i(O,"onload",Y)}else{if(typeof O.onload=="function"){var X=O.onload;O.onload=function(){X();Y()}}else{O.onload=Y}}}}}function h(){if(T){V()}else{H()}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return}}X.removeChild(aa);Z=null;H()})()}else{H()}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value")}}P(ai,ah,Y,ab)}else{p(ae);if(ab){ab(aa)}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z}ab(aa)}}}}}function z(aa){var X=null;var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z}}}return X}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312)}function P(aa,ab,X,Z){a=true;E=Z||null;B={success:false,id:X};var ae=c(X);if(ae){if(ae.nodeName=="OBJECT"){l=g(ae);Q=null}else{l=ae;Q=X}aa.id=R;if(typeof aa.width==D||(!/%$/.test(aa.width)&&parseInt(aa.width,10)<310)){aa.width="310"}if(typeof aa.height==D||(!/%$/.test(aa.height)&&parseInt(aa.height,10)<137)){aa.height="137"}j.title=j.title.slice(0,47)+" - Flash Player Installation";var ad=M.ie&&M.win?"ActiveX":"PlugIn",ac="MMredirectURL="+O.location.toString().replace(/&/g,"%26")+"&MMplayerType="+ad+"&MMdoctitle="+j.title;if(typeof ab.flashvars!=D){ab.flashvars+="&"+ac}else{ab.flashvars=ac}if(M.ie&&M.win&&ae.readyState!=4){var Y=C("div");X+="SWFObjectNew";Y.setAttribute("id",X);ae.parentNode.insertBefore(Y,ae);ae.style.display="none";(function(){if(ae.readyState==4){ae.parentNode.removeChild(ae)}else{setTimeout(arguments.callee,10)}})()}u(aa,ab,X)}}function p(Y){if(M.ie&&M.win&&Y.readyState!=4){var X=C("div");Y.parentNode.insertBefore(X,Y);X.parentNode.replaceChild(g(Y),X);Y.style.display="none";(function(){if(Y.readyState==4){Y.parentNode.removeChild(Y)}else{setTimeout(arguments.callee,10)}})()}else{Y.parentNode.replaceChild(g(Y),Y)}}function g(ab){var aa=C("div");if(M.win&&M.ie){aa.innerHTML=ab.innerHTML}else{var Y=ab.getElementsByTagName(r)[0];if(Y){var ad=Y.childNodes;if(ad){var X=ad.length;for(var Z=0;Z<X;Z++){if(!(ad[Z].nodeType==1&&ad[Z].nodeName=="PARAM")&&!(ad[Z].nodeType==8)){aa.appendChild(ad[Z].cloneNode(true))}}}}}return aa}function u(ai,ag,Y){var X,aa=c(Y);if(M.wk&&M.wk<312){return X}if(aa){if(typeof ai.id==D){ai.id=Y}if(M.ie&&M.win){var ah="";for(var ae in ai){if(ai[ae]!=Object.prototype[ae]){if(ae.toLowerCase()=="data"){ag.movie=ai[ae]}else{if(ae.toLowerCase()=="styleclass"){ah+=' class="'+ai[ae]+'"'}else{if(ae.toLowerCase()!="classid"){ah+=" "+ae+'="'+ai[ae]+'"'}}}}}var af="";for(var ad in ag){if(ag[ad]!=Object.prototype[ad]){af+='<param name="'+ad+'" value="'+ag[ad]+'" />'}}aa.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+ah+">"+af+"</object>";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab<ac;ab++){I[ab][0].detachEvent(I[ab][1],I[ab][2])}var Z=N.length;for(var aa=0;aa<Z;aa++){y(N[aa])}for(var Y in M){M[Y]=null}M=null;for(var X in swfobject){swfobject[X]=null}swfobject=null})}}();return{registerObject:function(ab,X,aa,Z){if(M.w3&&ab&&X){var Y={};Y.id=ab;Y.swfVersion=X;Y.expressInstall=aa;Y.callbackFn=Z;o[o.length]=Y;w(ab,false)}else{if(Z){Z({success:false,id:ab})}}},getObjectById:function(X){if(M.w3){return z(X)}},embedSWF:function(ab,ah,ae,ag,Y,aa,Z,ad,af,ac){var X={success:false,id:ah};if(M.w3&&!(M.wk&&M.wk<312)&&ab&&ah&&ae&&ag&&Y){w(ah,false);K(function(){ae+="";ag+="";var aj={};if(af&&typeof af===r){for(var al in af){aj[al]=af[al]}}aj.data=ab;aj.width=ae;aj.height=ag;var am={};if(ad&&typeof ad===r){for(var ak in ad){am[ak]=ad[ak]}}if(Z&&typeof Z===r){for(var ai in Z){if(typeof am.flashvars!=D){am.flashvars+="&"+ai+"="+Z[ai]}else{am.flashvars=ai+"="+Z[ai]}}}if(F(Y)){var an=u(aj,am,ah);if(aj.id==ah){w(ah,true)}X.success=true;X.ref=an}else{if(aa&&A()){aj.data=aa;P(aj,am,ah,ac);return}else{w(ah,true)}}if(ac){ac(X)}})}else{if(ac){ac(X)}}},switchOffAutoHideShow:function(){m=false},ua:M,getFlashPlayerVersion:function(){return{major:M.pv[0],minor:M.pv[1],release:M.pv[2]}},hasFlashPlayerVersion:F,createSWF:function(Z,Y,X){if(M.w3){return u(Z,Y,X)}else{return undefined}},showExpressInstall:function(Z,aa,X,Y){if(M.w3&&A()){P(Z,aa,X,Y)}},removeSWF:function(X){if(M.w3){y(X)}},createCSS:function(aa,Z,Y,X){if(M.w3){v(aa,Z,Y,X)}},addDomLoadEvent:K,addLoadEvent:s,getQueryParamValue:function(aa){var Z=j.location.search||j.location.hash;if(Z){if(/\?/.test(Z)){Z=Z.split("?")[1]}if(aa==null){return L(Z)}var Y=Z.split("&");for(var X=0;X<Y.length;X++){if(Y[X].substring(0,Y[X].indexOf("="))==aa){return L(Y[X].substring((Y[X].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(a){var X=c(R);if(X&&l){X.parentNode.replaceChild(l,X);if(Q){w(Q,true);if(M.ie&&M.win){l.style.display="block"}}if(E){E(B)}}a=false}}}}();
|
611
|
-
/*
|
612
|
-
/*
|
613
|
-
Copyright 2006 Adobe Systems Incorporated
|
614
|
-
|
615
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
616
|
-
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
617
|
-
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
618
|
-
|
619
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
620
|
-
|
621
|
-
|
622
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
623
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
624
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
625
|
-
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
626
|
-
|
627
|
-
*/
|
628
|
-
|
629
|
-
|
630
|
-
/*
|
631
|
-
* The Bridge class, responsible for navigating AS instances
|
632
|
-
*/
|
633
|
-
function FABridge(target,bridgeName)
|
634
|
-
{
|
635
|
-
this.target = target;
|
636
|
-
this.remoteTypeCache = {};
|
637
|
-
this.remoteInstanceCache = {};
|
638
|
-
this.remoteFunctionCache = {};
|
639
|
-
this.localFunctionCache = {};
|
640
|
-
this.bridgeID = FABridge.nextBridgeID++;
|
641
|
-
this.name = bridgeName;
|
642
|
-
this.nextLocalFuncID = 0;
|
643
|
-
FABridge.instances[this.name] = this;
|
644
|
-
FABridge.idMap[this.bridgeID] = this;
|
645
|
-
|
646
|
-
return this;
|
647
|
-
}
|
648
|
-
|
649
|
-
// type codes for packed values
|
650
|
-
FABridge.TYPE_ASINSTANCE = 1;
|
651
|
-
FABridge.TYPE_ASFUNCTION = 2;
|
652
|
-
|
653
|
-
FABridge.TYPE_JSFUNCTION = 3;
|
654
|
-
FABridge.TYPE_ANONYMOUS = 4;
|
655
|
-
|
656
|
-
FABridge.initCallbacks = {};
|
657
|
-
FABridge.userTypes = {};
|
658
|
-
|
659
|
-
FABridge.addToUserTypes = function()
|
660
|
-
{
|
661
|
-
for (var i = 0; i < arguments.length; i++)
|
662
|
-
{
|
663
|
-
FABridge.userTypes[arguments[i]] = {
|
664
|
-
'typeName': arguments[i],
|
665
|
-
'enriched': false
|
666
|
-
};
|
667
|
-
}
|
668
|
-
}
|
669
|
-
|
670
|
-
FABridge.argsToArray = function(args)
|
671
|
-
{
|
672
|
-
var result = [];
|
673
|
-
for (var i = 0; i < args.length; i++)
|
674
|
-
{
|
675
|
-
result[i] = args[i];
|
676
|
-
}
|
677
|
-
return result;
|
678
|
-
}
|
679
|
-
|
680
|
-
function instanceFactory(objID)
|
681
|
-
{
|
682
|
-
this.fb_instance_id = objID;
|
683
|
-
return this;
|
684
|
-
}
|
685
|
-
|
686
|
-
function FABridge__invokeJSFunction(args)
|
687
|
-
{
|
688
|
-
var funcID = args[0];
|
689
|
-
var throughArgs = args.concat();//FABridge.argsToArray(arguments);
|
690
|
-
throughArgs.shift();
|
691
|
-
|
692
|
-
var bridge = FABridge.extractBridgeFromID(funcID);
|
693
|
-
return bridge.invokeLocalFunction(funcID, throughArgs);
|
694
|
-
}
|
695
|
-
|
696
|
-
FABridge.addInitializationCallback = function(bridgeName, callback)
|
697
|
-
{
|
698
|
-
var inst = FABridge.instances[bridgeName];
|
699
|
-
if (inst != undefined)
|
700
|
-
{
|
701
|
-
callback.call(inst);
|
702
|
-
return;
|
703
|
-
}
|
704
|
-
|
705
|
-
var callbackList = FABridge.initCallbacks[bridgeName];
|
706
|
-
if(callbackList == null)
|
707
|
-
{
|
708
|
-
FABridge.initCallbacks[bridgeName] = callbackList = [];
|
709
|
-
}
|
710
|
-
|
711
|
-
callbackList.push(callback);
|
712
|
-
}
|
713
|
-
|
714
|
-
// updated for changes to SWFObject2
|
715
|
-
function FABridge__bridgeInitialized(bridgeName) {
|
716
|
-
var objects = document.getElementsByTagName("object");
|
717
|
-
var ol = objects.length;
|
718
|
-
var activeObjects = [];
|
719
|
-
if (ol > 0) {
|
720
|
-
for (var i = 0; i < ol; i++) {
|
721
|
-
if (typeof objects[i].SetVariable != "undefined") {
|
722
|
-
activeObjects[activeObjects.length] = objects[i];
|
723
|
-
}
|
724
|
-
}
|
725
|
-
}
|
726
|
-
var embeds = document.getElementsByTagName("embed");
|
727
|
-
var el = embeds.length;
|
728
|
-
var activeEmbeds = [];
|
729
|
-
if (el > 0) {
|
730
|
-
for (var j = 0; j < el; j++) {
|
731
|
-
if (typeof embeds[j].SetVariable != "undefined") {
|
732
|
-
activeEmbeds[activeEmbeds.length] = embeds[j];
|
733
|
-
}
|
734
|
-
}
|
735
|
-
}
|
736
|
-
var aol = activeObjects.length;
|
737
|
-
var ael = activeEmbeds.length;
|
738
|
-
var searchStr = "bridgeName="+ bridgeName;
|
739
|
-
if ((aol == 1 && !ael) || (aol == 1 && ael == 1)) {
|
740
|
-
FABridge.attachBridge(activeObjects[0], bridgeName);
|
741
|
-
}
|
742
|
-
else if (ael == 1 && !aol) {
|
743
|
-
FABridge.attachBridge(activeEmbeds[0], bridgeName);
|
744
|
-
}
|
745
|
-
else {
|
746
|
-
var flash_found = false;
|
747
|
-
if (aol > 1) {
|
748
|
-
for (var k = 0; k < aol; k++) {
|
749
|
-
var params = activeObjects[k].childNodes;
|
750
|
-
for (var l = 0; l < params.length; l++) {
|
751
|
-
var param = params[l];
|
752
|
-
if (param.nodeType == 1 && param.tagName.toLowerCase() == "param" && param["name"].toLowerCase() == "flashvars" && param["value"].indexOf(searchStr) >= 0) {
|
753
|
-
FABridge.attachBridge(activeObjects[k], bridgeName);
|
754
|
-
flash_found = true;
|
755
|
-
break;
|
756
|
-
}
|
757
|
-
}
|
758
|
-
if (flash_found) {
|
759
|
-
break;
|
760
|
-
}
|
761
|
-
}
|
762
|
-
}
|
763
|
-
if (!flash_found && ael > 1) {
|
764
|
-
for (var m = 0; m < ael; m++) {
|
765
|
-
var flashVars = activeEmbeds[m].attributes.getNamedItem("flashVars").nodeValue;
|
766
|
-
if (flashVars.indexOf(searchStr) >= 0) {
|
767
|
-
FABridge.attachBridge(activeEmbeds[m], bridgeName);
|
768
|
-
break;
|
769
|
-
}
|
770
|
-
}
|
771
|
-
}
|
772
|
-
}
|
773
|
-
return true;
|
774
|
-
}
|
775
|
-
|
776
|
-
// used to track multiple bridge instances, since callbacks from AS are global across the page.
|
777
|
-
|
778
|
-
FABridge.nextBridgeID = 0;
|
779
|
-
FABridge.instances = {};
|
780
|
-
FABridge.idMap = {};
|
781
|
-
FABridge.refCount = 0;
|
782
|
-
|
783
|
-
FABridge.extractBridgeFromID = function(id)
|
784
|
-
{
|
785
|
-
var bridgeID = (id >> 16);
|
786
|
-
return FABridge.idMap[bridgeID];
|
787
|
-
}
|
788
|
-
|
789
|
-
FABridge.attachBridge = function(instance, bridgeName)
|
790
|
-
{
|
791
|
-
var newBridgeInstance = new FABridge(instance, bridgeName);
|
792
|
-
|
793
|
-
FABridge[bridgeName] = newBridgeInstance;
|
794
|
-
|
795
|
-
/* FABridge[bridgeName] = function() {
|
796
|
-
return newBridgeInstance.root();
|
797
|
-
}
|
798
|
-
*/
|
799
|
-
var callbacks = FABridge.initCallbacks[bridgeName];
|
800
|
-
if (callbacks == null)
|
801
|
-
{
|
802
|
-
return;
|
803
|
-
}
|
804
|
-
for (var i = 0; i < callbacks.length; i++)
|
805
|
-
{
|
806
|
-
callbacks[i].call(newBridgeInstance);
|
807
|
-
}
|
808
|
-
delete FABridge.initCallbacks[bridgeName]
|
809
|
-
}
|
810
|
-
|
811
|
-
// some methods can't be proxied. You can use the explicit get,set, and call methods if necessary.
|
812
|
-
|
813
|
-
FABridge.blockedMethods =
|
814
|
-
{
|
815
|
-
toString: true,
|
816
|
-
get: true,
|
817
|
-
set: true,
|
818
|
-
call: true
|
819
|
-
};
|
820
|
-
|
821
|
-
FABridge.prototype =
|
822
|
-
{
|
823
|
-
|
824
|
-
|
825
|
-
// bootstrapping
|
826
|
-
|
827
|
-
root: function()
|
828
|
-
{
|
829
|
-
return this.deserialize(this.target.getRoot());
|
830
|
-
},
|
831
|
-
//clears all of the AS objects in the cache maps
|
832
|
-
releaseASObjects: function()
|
833
|
-
{
|
834
|
-
return this.target.releaseASObjects();
|
835
|
-
},
|
836
|
-
//clears a specific object in AS from the type maps
|
837
|
-
releaseNamedASObject: function(value)
|
838
|
-
{
|
839
|
-
if(typeof(value) != "object")
|
840
|
-
{
|
841
|
-
return false;
|
842
|
-
}
|
843
|
-
else
|
844
|
-
{
|
845
|
-
var ret = this.target.releaseNamedASObject(value.fb_instance_id);
|
846
|
-
return ret;
|
847
|
-
}
|
848
|
-
},
|
849
|
-
//create a new AS Object
|
850
|
-
create: function(className)
|
851
|
-
{
|
852
|
-
return this.deserialize(this.target.create(className));
|
853
|
-
},
|
854
|
-
|
855
|
-
|
856
|
-
// utilities
|
857
|
-
|
858
|
-
makeID: function(token)
|
859
|
-
{
|
860
|
-
return (this.bridgeID << 16) + token;
|
861
|
-
},
|
862
|
-
|
863
|
-
|
864
|
-
// low level access to the flash object
|
865
|
-
|
866
|
-
//get a named property from an AS object
|
867
|
-
getPropertyFromAS: function(objRef, propName)
|
868
|
-
{
|
869
|
-
if (FABridge.refCount > 0)
|
870
|
-
{
|
871
|
-
throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
|
872
|
-
}
|
873
|
-
else
|
874
|
-
{
|
875
|
-
FABridge.refCount++;
|
876
|
-
retVal = this.target.getPropFromAS(objRef, propName);
|
877
|
-
retVal = this.handleError(retVal);
|
878
|
-
FABridge.refCount--;
|
879
|
-
return retVal;
|
880
|
-
}
|
881
|
-
},
|
882
|
-
//set a named property on an AS object
|
883
|
-
setPropertyInAS: function(objRef,propName, value)
|
884
|
-
{
|
885
|
-
if (FABridge.refCount > 0)
|
886
|
-
{
|
887
|
-
throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
|
888
|
-
}
|
889
|
-
else
|
890
|
-
{
|
891
|
-
FABridge.refCount++;
|
892
|
-
retVal = this.target.setPropInAS(objRef,propName, this.serialize(value));
|
893
|
-
retVal = this.handleError(retVal);
|
894
|
-
FABridge.refCount--;
|
895
|
-
return retVal;
|
896
|
-
}
|
897
|
-
},
|
898
|
-
|
899
|
-
//call an AS function
|
900
|
-
callASFunction: function(funcID, args)
|
901
|
-
{
|
902
|
-
if (FABridge.refCount > 0)
|
903
|
-
{
|
904
|
-
throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
|
905
|
-
}
|
906
|
-
else
|
907
|
-
{
|
908
|
-
FABridge.refCount++;
|
909
|
-
retVal = this.target.invokeASFunction(funcID, this.serialize(args));
|
910
|
-
retVal = this.handleError(retVal);
|
911
|
-
FABridge.refCount--;
|
912
|
-
return retVal;
|
913
|
-
}
|
914
|
-
},
|
915
|
-
//call a method on an AS object
|
916
|
-
callASMethod: function(objID, funcName, args)
|
917
|
-
{
|
918
|
-
if (FABridge.refCount > 0)
|
919
|
-
{
|
920
|
-
throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
|
921
|
-
}
|
922
|
-
else
|
923
|
-
{
|
924
|
-
FABridge.refCount++;
|
925
|
-
args = this.serialize(args);
|
926
|
-
retVal = this.target.invokeASMethod(objID, funcName, args);
|
927
|
-
retVal = this.handleError(retVal);
|
928
|
-
FABridge.refCount--;
|
929
|
-
return retVal;
|
930
|
-
}
|
931
|
-
},
|
932
|
-
|
933
|
-
// responders to remote calls from flash
|
934
|
-
|
935
|
-
//callback from flash that executes a local JS function
|
936
|
-
//used mostly when setting js functions as callbacks on events
|
937
|
-
invokeLocalFunction: function(funcID, args)
|
938
|
-
{
|
939
|
-
var result;
|
940
|
-
var func = this.localFunctionCache[funcID];
|
941
|
-
|
942
|
-
if(func != undefined)
|
943
|
-
{
|
944
|
-
result = this.serialize(func.apply(null, this.deserialize(args)));
|
945
|
-
}
|
946
|
-
|
947
|
-
return result;
|
948
|
-
},
|
949
|
-
|
950
|
-
// Object Types and Proxies
|
951
|
-
|
952
|
-
// accepts an object reference, returns a type object matching the obj reference.
|
953
|
-
getTypeFromName: function(objTypeName)
|
954
|
-
{
|
955
|
-
return this.remoteTypeCache[objTypeName];
|
956
|
-
},
|
957
|
-
//create an AS proxy for the given object ID and type
|
958
|
-
createProxy: function(objID, typeName)
|
959
|
-
{
|
960
|
-
var objType = this.getTypeFromName(typeName);
|
961
|
-
instanceFactory.prototype = objType;
|
962
|
-
var instance = new instanceFactory(objID);
|
963
|
-
this.remoteInstanceCache[objID] = instance;
|
964
|
-
return instance;
|
965
|
-
},
|
966
|
-
//return the proxy associated with the given object ID
|
967
|
-
getProxy: function(objID)
|
968
|
-
{
|
969
|
-
return this.remoteInstanceCache[objID];
|
970
|
-
},
|
971
|
-
|
972
|
-
// accepts a type structure, returns a constructed type
|
973
|
-
addTypeDataToCache: function(typeData)
|
974
|
-
{
|
975
|
-
var newType = new ASProxy(this, typeData.name);
|
976
|
-
var accessors = typeData.accessors;
|
977
|
-
for (var i = 0; i < accessors.length; i++)
|
978
|
-
{
|
979
|
-
this.addPropertyToType(newType, accessors[i]);
|
980
|
-
}
|
981
|
-
|
982
|
-
var methods = typeData.methods;
|
983
|
-
for (var i = 0; i < methods.length; i++)
|
984
|
-
{
|
985
|
-
if (FABridge.blockedMethods[methods[i]] == undefined)
|
986
|
-
{
|
987
|
-
this.addMethodToType(newType, methods[i]);
|
988
|
-
}
|
989
|
-
}
|
990
|
-
|
991
|
-
|
992
|
-
this.remoteTypeCache[newType.typeName] = newType;
|
993
|
-
return newType;
|
994
|
-
},
|
995
|
-
|
996
|
-
//add a property to a typename; used to define the properties that can be called on an AS proxied object
|
997
|
-
addPropertyToType: function(ty, propName)
|
998
|
-
{
|
999
|
-
var c = propName.charAt(0);
|
1000
|
-
var setterName;
|
1001
|
-
var getterName;
|
1002
|
-
if(c >= "a" && c <= "z")
|
1003
|
-
{
|
1004
|
-
getterName = "get" + c.toUpperCase() + propName.substr(1);
|
1005
|
-
setterName = "set" + c.toUpperCase() + propName.substr(1);
|
1006
|
-
}
|
1007
|
-
else
|
1008
|
-
{
|
1009
|
-
getterName = "get" + propName;
|
1010
|
-
setterName = "set" + propName;
|
1011
|
-
}
|
1012
|
-
ty[setterName] = function(val)
|
1013
|
-
{
|
1014
|
-
this.bridge.setPropertyInAS(this.fb_instance_id, propName, val);
|
1015
|
-
}
|
1016
|
-
ty[getterName] = function()
|
1017
|
-
{
|
1018
|
-
return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id, propName));
|
1019
|
-
}
|
1020
|
-
},
|
1021
|
-
|
1022
|
-
//add a method to a typename; used to define the methods that can be callefd on an AS proxied object
|
1023
|
-
addMethodToType: function(ty, methodName)
|
1024
|
-
{
|
1025
|
-
ty[methodName] = function()
|
1026
|
-
{
|
1027
|
-
return this.bridge.deserialize(this.bridge.callASMethod(this.fb_instance_id, methodName, FABridge.argsToArray(arguments)));
|
1028
|
-
}
|
1029
|
-
},
|
1030
|
-
|
1031
|
-
// Function Proxies
|
1032
|
-
|
1033
|
-
//returns the AS proxy for the specified function ID
|
1034
|
-
getFunctionProxy: function(funcID)
|
1035
|
-
{
|
1036
|
-
var bridge = this;
|
1037
|
-
if (this.remoteFunctionCache[funcID] == null)
|
1038
|
-
{
|
1039
|
-
this.remoteFunctionCache[funcID] = function()
|
1040
|
-
{
|
1041
|
-
bridge.callASFunction(funcID, FABridge.argsToArray(arguments));
|
1042
|
-
}
|
1043
|
-
}
|
1044
|
-
return this.remoteFunctionCache[funcID];
|
1045
|
-
},
|
1046
|
-
|
1047
|
-
//reutrns the ID of the given function; if it doesnt exist it is created and added to the local cache
|
1048
|
-
getFunctionID: function(func)
|
1049
|
-
{
|
1050
|
-
if (func.__bridge_id__ == undefined)
|
1051
|
-
{
|
1052
|
-
func.__bridge_id__ = this.makeID(this.nextLocalFuncID++);
|
1053
|
-
this.localFunctionCache[func.__bridge_id__] = func;
|
1054
|
-
}
|
1055
|
-
return func.__bridge_id__;
|
1056
|
-
},
|
1057
|
-
|
1058
|
-
// serialization / deserialization
|
1059
|
-
|
1060
|
-
serialize: function(value)
|
1061
|
-
{
|
1062
|
-
var result = {};
|
1063
|
-
|
1064
|
-
var t = typeof(value);
|
1065
|
-
//primitives are kept as such
|
1066
|
-
if (t == "number" || t == "string" || t == "boolean" || t == null || t == undefined)
|
1067
|
-
{
|
1068
|
-
result = value;
|
1069
|
-
}
|
1070
|
-
else if (value instanceof Array)
|
1071
|
-
{
|
1072
|
-
//arrays are serializesd recursively
|
1073
|
-
result = [];
|
1074
|
-
for (var i = 0; i < value.length; i++)
|
1075
|
-
{
|
1076
|
-
result[i] = this.serialize(value[i]);
|
1077
|
-
}
|
1078
|
-
}
|
1079
|
-
else if (t == "function")
|
1080
|
-
{
|
1081
|
-
//js functions are assigned an ID and stored in the local cache
|
1082
|
-
result.type = FABridge.TYPE_JSFUNCTION;
|
1083
|
-
result.value = this.getFunctionID(value);
|
1084
|
-
}
|
1085
|
-
else if (value instanceof ASProxy)
|
1086
|
-
{
|
1087
|
-
result.type = FABridge.TYPE_ASINSTANCE;
|
1088
|
-
result.value = value.fb_instance_id;
|
1089
|
-
}
|
1090
|
-
else
|
1091
|
-
{
|
1092
|
-
result.type = FABridge.TYPE_ANONYMOUS;
|
1093
|
-
result.value = value;
|
1094
|
-
}
|
1095
|
-
|
1096
|
-
return result;
|
1097
|
-
},
|
1098
|
-
|
1099
|
-
//on deserialization we always check the return for the specific error code that is used to marshall NPE's into JS errors
|
1100
|
-
// the unpacking is done by returning the value on each pachet for objects/arrays
|
1101
|
-
deserialize: function(packedValue)
|
1102
|
-
{
|
1103
|
-
|
1104
|
-
var result;
|
1105
|
-
|
1106
|
-
var t = typeof(packedValue);
|
1107
|
-
if (t == "number" || t == "string" || t == "boolean" || packedValue == null || packedValue == undefined)
|
1108
|
-
{
|
1109
|
-
result = this.handleError(packedValue);
|
1110
|
-
}
|
1111
|
-
else if (packedValue instanceof Array)
|
1112
|
-
{
|
1113
|
-
result = [];
|
1114
|
-
for (var i = 0; i < packedValue.length; i++)
|
1115
|
-
{
|
1116
|
-
result[i] = this.deserialize(packedValue[i]);
|
1117
|
-
}
|
1118
|
-
}
|
1119
|
-
else if (t == "object")
|
1120
|
-
{
|
1121
|
-
for(var i = 0; i < packedValue.newTypes.length; i++)
|
1122
|
-
{
|
1123
|
-
this.addTypeDataToCache(packedValue.newTypes[i]);
|
1124
|
-
}
|
1125
|
-
for (var aRefID in packedValue.newRefs)
|
1126
|
-
{
|
1127
|
-
this.createProxy(aRefID, packedValue.newRefs[aRefID]);
|
1128
|
-
}
|
1129
|
-
if (packedValue.type == FABridge.TYPE_PRIMITIVE)
|
1130
|
-
{
|
1131
|
-
result = packedValue.value;
|
1132
|
-
}
|
1133
|
-
else if (packedValue.type == FABridge.TYPE_ASFUNCTION)
|
1134
|
-
{
|
1135
|
-
result = this.getFunctionProxy(packedValue.value);
|
1136
|
-
}
|
1137
|
-
else if (packedValue.type == FABridge.TYPE_ASINSTANCE)
|
1138
|
-
{
|
1139
|
-
result = this.getProxy(packedValue.value);
|
1140
|
-
}
|
1141
|
-
else if (packedValue.type == FABridge.TYPE_ANONYMOUS)
|
1142
|
-
{
|
1143
|
-
result = packedValue.value;
|
1144
|
-
}
|
1145
|
-
}
|
1146
|
-
return result;
|
1147
|
-
},
|
1148
|
-
//increases the reference count for the given object
|
1149
|
-
addRef: function(obj)
|
1150
|
-
{
|
1151
|
-
this.target.incRef(obj.fb_instance_id);
|
1152
|
-
},
|
1153
|
-
//decrease the reference count for the given object and release it if needed
|
1154
|
-
release:function(obj)
|
1155
|
-
{
|
1156
|
-
this.target.releaseRef(obj.fb_instance_id);
|
1157
|
-
},
|
1158
|
-
|
1159
|
-
// check the given value for the components of the hard-coded error code : __FLASHERROR
|
1160
|
-
// used to marshall NPE's into flash
|
1161
|
-
|
1162
|
-
handleError: function(value)
|
1163
|
-
{
|
1164
|
-
if (typeof(value)=="string" && value.indexOf("__FLASHERROR")==0)
|
1165
|
-
{
|
1166
|
-
var myErrorMessage = value.split("||");
|
1167
|
-
if(FABridge.refCount > 0 )
|
1168
|
-
{
|
1169
|
-
FABridge.refCount--;
|
1170
|
-
}
|
1171
|
-
throw new Error(myErrorMessage[1]);
|
1172
|
-
return value;
|
1173
|
-
}
|
1174
|
-
else
|
1175
|
-
{
|
1176
|
-
return value;
|
1177
|
-
}
|
1178
|
-
}
|
1179
|
-
};
|
1180
|
-
|
1181
|
-
// The root ASProxy class that facades a flash object
|
1182
|
-
|
1183
|
-
ASProxy = function(bridge, typeName)
|
1184
|
-
{
|
1185
|
-
this.bridge = bridge;
|
1186
|
-
this.typeName = typeName;
|
1187
|
-
return this;
|
1188
|
-
};
|
1189
|
-
//methods available on each ASProxy object
|
1190
|
-
ASProxy.prototype =
|
1191
|
-
{
|
1192
|
-
get: function(propName)
|
1193
|
-
{
|
1194
|
-
return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id, propName));
|
1195
|
-
},
|
1196
|
-
|
1197
|
-
set: function(propName, value)
|
1198
|
-
{
|
1199
|
-
this.bridge.setPropertyInAS(this.fb_instance_id, propName, value);
|
1200
|
-
},
|
1201
|
-
|
1202
|
-
call: function(funcName, args)
|
1203
|
-
{
|
1204
|
-
this.bridge.callASMethod(this.fb_instance_id, funcName, args);
|
1205
|
-
},
|
1206
|
-
|
1207
|
-
addRef: function() {
|
1208
|
-
this.bridge.addRef(this);
|
1209
|
-
},
|
1210
|
-
|
1211
|
-
release: function() {
|
1212
|
-
this.bridge.release(this);
|
1213
|
-
}
|
1214
|
-
};
|
1215
|
-
|
1216
|
-
// Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
|
1217
|
-
// License: New BSD License
|
1218
|
-
// Reference: http://dev.w3.org/html5/websockets/
|
1219
|
-
// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol
|
1220
|
-
|
1221
|
-
(function() {
|
1222
|
-
|
1223
|
-
if (window.WebSocket) return;
|
1224
|
-
|
1225
|
-
var console = window.console;
|
1226
|
-
if (!console) console = {log: function(){ }, error: function(){ }};
|
1227
|
-
|
1228
|
-
if (!swfobject.hasFlashPlayerVersion("9.0.0")) {
|
1229
|
-
console.error("Flash Player is not installed.");
|
1230
|
-
return;
|
1231
|
-
}
|
1232
|
-
if (location.protocol == "file:") {
|
1233
|
-
console.error(
|
1234
|
-
"WARNING: web-socket-js doesn't work in file:///... URL " +
|
1235
|
-
"unless you set Flash Security Settings properly. " +
|
1236
|
-
"Open the page via Web server i.e. http://...");
|
1237
|
-
}
|
1238
|
-
|
1239
|
-
WebSocket = function(url, protocol, proxyHost, proxyPort, headers) {
|
1240
|
-
var self = this;
|
1241
|
-
self.readyState = WebSocket.CONNECTING;
|
1242
|
-
self.bufferedAmount = 0;
|
1243
|
-
// Uses setTimeout() to make sure __createFlash() runs after the caller sets ws.onopen etc.
|
1244
|
-
// Otherwise, when onopen fires immediately, onopen is called before it is set.
|
1245
|
-
setTimeout(function() {
|
1246
|
-
WebSocket.__addTask(function() {
|
1247
|
-
self.__createFlash(url, protocol, proxyHost, proxyPort, headers);
|
1248
|
-
});
|
1249
|
-
}, 1);
|
1250
|
-
}
|
1251
|
-
|
1252
|
-
WebSocket.prototype.__createFlash = function(url, protocol, proxyHost, proxyPort, headers) {
|
1253
|
-
var self = this;
|
1254
|
-
self.__flash =
|
1255
|
-
WebSocket.__flash.create(url, protocol, proxyHost || null, proxyPort || 0, headers || null);
|
1256
|
-
|
1257
|
-
self.__flash.addEventListener("open", function(fe) {
|
1258
|
-
try {
|
1259
|
-
self.readyState = self.__flash.getReadyState();
|
1260
|
-
if (self.__timer) clearInterval(self.__timer);
|
1261
|
-
if (window.opera) {
|
1262
|
-
// Workaround for weird behavior of Opera which sometimes drops events.
|
1263
|
-
self.__timer = setInterval(function () {
|
1264
|
-
self.__handleMessages();
|
1265
|
-
}, 500);
|
1266
|
-
}
|
1267
|
-
if (self.onopen) self.onopen();
|
1268
|
-
} catch (e) {
|
1269
|
-
console.error(e.toString());
|
1270
|
-
}
|
1271
|
-
});
|
1272
|
-
|
1273
|
-
self.__flash.addEventListener("close", function(fe) {
|
1274
|
-
try {
|
1275
|
-
self.readyState = self.__flash.getReadyState();
|
1276
|
-
if (self.__timer) clearInterval(self.__timer);
|
1277
|
-
if (self.onclose) self.onclose();
|
1278
|
-
} catch (e) {
|
1279
|
-
console.error(e.toString());
|
1280
|
-
}
|
1281
|
-
});
|
1282
|
-
|
1283
|
-
self.__flash.addEventListener("message", function() {
|
1284
|
-
try {
|
1285
|
-
self.__handleMessages();
|
1286
|
-
} catch (e) {
|
1287
|
-
console.error(e.toString());
|
1288
|
-
}
|
1289
|
-
});
|
1290
|
-
|
1291
|
-
self.__flash.addEventListener("error", function(fe) {
|
1292
|
-
try {
|
1293
|
-
if (self.__timer) clearInterval(self.__timer);
|
1294
|
-
if (self.onerror) self.onerror();
|
1295
|
-
} catch (e) {
|
1296
|
-
console.error(e.toString());
|
1297
|
-
}
|
1298
|
-
});
|
1299
|
-
|
1300
|
-
self.__flash.addEventListener("stateChange", function(fe) {
|
1301
|
-
try {
|
1302
|
-
self.readyState = self.__flash.getReadyState();
|
1303
|
-
self.bufferedAmount = fe.getBufferedAmount();
|
1304
|
-
} catch (e) {
|
1305
|
-
console.error(e.toString());
|
1306
|
-
}
|
1307
|
-
});
|
1308
|
-
|
1309
|
-
//console.log("[WebSocket] Flash object is ready");
|
1310
|
-
};
|
1311
|
-
|
1312
|
-
WebSocket.prototype.send = function(data) {
|
1313
|
-
if (this.__flash) {
|
1314
|
-
this.readyState = this.__flash.getReadyState();
|
1315
|
-
}
|
1316
|
-
if (!this.__flash || this.readyState == WebSocket.CONNECTING) {
|
1317
|
-
throw "INVALID_STATE_ERR: Web Socket connection has not been established";
|
1318
|
-
}
|
1319
|
-
// We use encodeURIComponent() here, because FABridge doesn't work if
|
1320
|
-
// the argument includes some characters. We don't use escape() here
|
1321
|
-
// because of this:
|
1322
|
-
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#escape_and_unescape_Functions
|
1323
|
-
// But it looks decodeURIComponent(encodeURIComponent(s)) doesn't
|
1324
|
-
// preserve all Unicode characters either e.g. "\uffff" in Firefox.
|
1325
|
-
var result = this.__flash.send(encodeURIComponent(data));
|
1326
|
-
if (result < 0) { // success
|
1327
|
-
return true;
|
1328
|
-
} else {
|
1329
|
-
this.bufferedAmount = result;
|
1330
|
-
return false;
|
1331
|
-
}
|
1332
|
-
};
|
1333
|
-
|
1334
|
-
WebSocket.prototype.close = function() {
|
1335
|
-
var self = this;
|
1336
|
-
if (!self.__flash) return;
|
1337
|
-
self.readyState = self.__flash.getReadyState();
|
1338
|
-
if (self.readyState == WebSocket.CLOSED || self.readyState == WebSocket.CLOSING) return;
|
1339
|
-
self.__flash.close();
|
1340
|
-
// Sets/calls them manually here because Flash WebSocketConnection.close cannot fire events
|
1341
|
-
// which causes weird error:
|
1342
|
-
// > You are trying to call recursively into the Flash Player which is not allowed.
|
1343
|
-
self.readyState = WebSocket.CLOSED;
|
1344
|
-
if (self.__timer) clearInterval(self.__timer);
|
1345
|
-
if (self.onclose) {
|
1346
|
-
// Make it asynchronous so that it looks more like an actual
|
1347
|
-
// close event
|
1348
|
-
setTimeout(self.onclose, 1);
|
1349
|
-
}
|
1350
|
-
};
|
1351
|
-
|
1352
|
-
/**
|
1353
|
-
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
1354
|
-
*
|
1355
|
-
* @param {string} type
|
1356
|
-
* @param {function} listener
|
1357
|
-
* @param {boolean} useCapture !NB Not implemented yet
|
1358
|
-
* @return void
|
1359
|
-
*/
|
1360
|
-
WebSocket.prototype.addEventListener = function(type, listener, useCapture) {
|
1361
|
-
if (!('__events' in this)) {
|
1362
|
-
this.__events = {};
|
1363
|
-
}
|
1364
|
-
if (!(type in this.__events)) {
|
1365
|
-
this.__events[type] = [];
|
1366
|
-
if ('function' == typeof this['on' + type]) {
|
1367
|
-
this.__events[type].defaultHandler = this['on' + type];
|
1368
|
-
this['on' + type] = this.__createEventHandler(this, type);
|
1369
|
-
}
|
1370
|
-
}
|
1371
|
-
this.__events[type].push(listener);
|
1372
|
-
};
|
1373
|
-
|
1374
|
-
/**
|
1375
|
-
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
1376
|
-
*
|
1377
|
-
* @param {string} type
|
1378
|
-
* @param {function} listener
|
1379
|
-
* @param {boolean} useCapture NB! Not implemented yet
|
1380
|
-
* @return void
|
1381
|
-
*/
|
1382
|
-
WebSocket.prototype.removeEventListener = function(type, listener, useCapture) {
|
1383
|
-
if (!('__events' in this)) {
|
1384
|
-
this.__events = {};
|
1385
|
-
}
|
1386
|
-
if (!(type in this.__events)) return;
|
1387
|
-
for (var i = this.__events.length; i > -1; --i) {
|
1388
|
-
if (listener === this.__events[type][i]) {
|
1389
|
-
this.__events[type].splice(i, 1);
|
1390
|
-
break;
|
1391
|
-
}
|
1392
|
-
}
|
1393
|
-
};
|
1394
|
-
|
1395
|
-
/**
|
1396
|
-
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
1397
|
-
*
|
1398
|
-
* @param {WebSocketEvent} event
|
1399
|
-
* @return void
|
1400
|
-
*/
|
1401
|
-
WebSocket.prototype.dispatchEvent = function(event) {
|
1402
|
-
if (!('__events' in this)) throw 'UNSPECIFIED_EVENT_TYPE_ERR';
|
1403
|
-
if (!(event.type in this.__events)) throw 'UNSPECIFIED_EVENT_TYPE_ERR';
|
1404
|
-
|
1405
|
-
for (var i = 0, l = this.__events[event.type].length; i < l; ++ i) {
|
1406
|
-
this.__events[event.type][i](event);
|
1407
|
-
if (event.cancelBubble) break;
|
1408
|
-
}
|
1409
|
-
|
1410
|
-
if (false !== event.returnValue &&
|
1411
|
-
'function' == typeof this.__events[event.type].defaultHandler)
|
1412
|
-
{
|
1413
|
-
this.__events[event.type].defaultHandler(event);
|
1414
|
-
}
|
1415
|
-
};
|
1416
|
-
|
1417
|
-
WebSocket.prototype.__handleMessages = function() {
|
1418
|
-
// Gets data using readSocketData() instead of getting it from event object
|
1419
|
-
// of Flash event. This is to make sure to keep message order.
|
1420
|
-
// It seems sometimes Flash events don't arrive in the same order as they are sent.
|
1421
|
-
var arr = this.__flash.readSocketData();
|
1422
|
-
for (var i = 0; i < arr.length; i++) {
|
1423
|
-
var data = decodeURIComponent(arr[i]);
|
1424
|
-
try {
|
1425
|
-
if (this.onmessage) {
|
1426
|
-
var e;
|
1427
|
-
if (window.MessageEvent && !window.opera) {
|
1428
|
-
e = document.createEvent("MessageEvent");
|
1429
|
-
e.initMessageEvent("message", false, false, data, null, null, window, null);
|
1430
|
-
} else { // IE and Opera, the latter one truncates the data parameter after any 0x00 bytes
|
1431
|
-
e = {data: data};
|
1432
|
-
}
|
1433
|
-
this.onmessage(e);
|
1434
|
-
}
|
1435
|
-
} catch (e) {
|
1436
|
-
console.error(e.toString());
|
1437
|
-
}
|
1438
|
-
}
|
1439
|
-
};
|
1440
|
-
|
1441
|
-
/**
|
1442
|
-
* @param {object} object
|
1443
|
-
* @param {string} type
|
1444
|
-
*/
|
1445
|
-
WebSocket.prototype.__createEventHandler = function(object, type) {
|
1446
|
-
return function(data) {
|
1447
|
-
var event = new WebSocketEvent();
|
1448
|
-
event.initEvent(type, true, true);
|
1449
|
-
event.target = event.currentTarget = object;
|
1450
|
-
for (var key in data) {
|
1451
|
-
event[key] = data[key];
|
1452
|
-
}
|
1453
|
-
object.dispatchEvent(event, arguments);
|
1454
|
-
};
|
1455
|
-
}
|
1456
|
-
|
1457
|
-
/**
|
1458
|
-
* Basic implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-interface">DOM 2 EventInterface</a>}
|
1459
|
-
*
|
1460
|
-
* @class
|
1461
|
-
* @constructor
|
1462
|
-
*/
|
1463
|
-
function WebSocketEvent(){}
|
1464
|
-
|
1465
|
-
/**
|
1466
|
-
*
|
1467
|
-
* @type boolean
|
1468
|
-
*/
|
1469
|
-
WebSocketEvent.prototype.cancelable = true;
|
1470
|
-
|
1471
|
-
/**
|
1472
|
-
*
|
1473
|
-
* @type boolean
|
1474
|
-
*/
|
1475
|
-
WebSocketEvent.prototype.cancelBubble = false;
|
1476
|
-
|
1477
|
-
/**
|
1478
|
-
*
|
1479
|
-
* @return void
|
1480
|
-
*/
|
1481
|
-
WebSocketEvent.prototype.preventDefault = function() {
|
1482
|
-
if (this.cancelable) {
|
1483
|
-
this.returnValue = false;
|
1484
|
-
}
|
1485
|
-
};
|
1486
|
-
|
1487
|
-
/**
|
1488
|
-
*
|
1489
|
-
* @return void
|
1490
|
-
*/
|
1491
|
-
WebSocketEvent.prototype.stopPropagation = function() {
|
1492
|
-
this.cancelBubble = true;
|
1493
|
-
};
|
1494
|
-
|
1495
|
-
/**
|
1496
|
-
*
|
1497
|
-
* @param {string} eventTypeArg
|
1498
|
-
* @param {boolean} canBubbleArg
|
1499
|
-
* @param {boolean} cancelableArg
|
1500
|
-
* @return void
|
1501
|
-
*/
|
1502
|
-
WebSocketEvent.prototype.initEvent = function(eventTypeArg, canBubbleArg, cancelableArg) {
|
1503
|
-
this.type = eventTypeArg;
|
1504
|
-
this.cancelable = cancelableArg;
|
1505
|
-
this.timeStamp = new Date();
|
1506
|
-
};
|
1507
|
-
|
1508
|
-
|
1509
|
-
WebSocket.CONNECTING = 0;
|
1510
|
-
WebSocket.OPEN = 1;
|
1511
|
-
WebSocket.CLOSING = 2;
|
1512
|
-
WebSocket.CLOSED = 3;
|
1513
|
-
|
1514
|
-
WebSocket.__tasks = [];
|
1515
|
-
|
1516
|
-
WebSocket.__initialize = function() {
|
1517
|
-
if (WebSocket.__swfLocation) {
|
1518
|
-
// For backword compatibility.
|
1519
|
-
window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation;
|
1520
|
-
}
|
1521
|
-
if (!window.WEB_SOCKET_SWF_LOCATION) {
|
1522
|
-
console.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf");
|
1523
|
-
return;
|
1524
|
-
}
|
1525
|
-
var container = document.createElement("div");
|
1526
|
-
container.id = "webSocketContainer";
|
1527
|
-
// Hides Flash box. We cannot use display: none or visibility: hidden because it prevents
|
1528
|
-
// Flash from loading at least in IE. So we move it out of the screen at (-100, -100).
|
1529
|
-
// But this even doesn't work with Flash Lite (e.g. in Droid Incredible). So with Flash
|
1530
|
-
// Lite, we put it at (0, 0). This shows 1x1 box visible at left-top corner but this is
|
1531
|
-
// the best we can do as far as we know now.
|
1532
|
-
container.style.position = "absolute";
|
1533
|
-
if (WebSocket.__isFlashLite()) {
|
1534
|
-
container.style.left = "0px";
|
1535
|
-
container.style.top = "0px";
|
1536
|
-
} else {
|
1537
|
-
container.style.left = "-100px";
|
1538
|
-
container.style.top = "-100px";
|
1539
|
-
}
|
1540
|
-
var holder = document.createElement("div");
|
1541
|
-
holder.id = "webSocketFlash";
|
1542
|
-
container.appendChild(holder);
|
1543
|
-
document.body.appendChild(container);
|
1544
|
-
// See this article for hasPriority:
|
1545
|
-
// http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
|
1546
|
-
swfobject.embedSWF(
|
1547
|
-
WEB_SOCKET_SWF_LOCATION, "webSocketFlash",
|
1548
|
-
"1" /* width */, "1" /* height */, "9.0.0" /* SWF version */,
|
1549
|
-
null, {bridgeName: "webSocket"}, {hasPriority: true, allowScriptAccess: "always"}, null,
|
1550
|
-
function(e) {
|
1551
|
-
if (!e.success) console.error("[WebSocket] swfobject.embedSWF failed");
|
1552
|
-
}
|
1553
|
-
);
|
1554
|
-
FABridge.addInitializationCallback("webSocket", function() {
|
1555
|
-
try {
|
1556
|
-
//console.log("[WebSocket] FABridge initializad");
|
1557
|
-
WebSocket.__flash = FABridge.webSocket.root();
|
1558
|
-
WebSocket.__flash.setCallerUrl(location.href);
|
1559
|
-
WebSocket.__flash.setDebug(!!window.WEB_SOCKET_DEBUG);
|
1560
|
-
for (var i = 0; i < WebSocket.__tasks.length; ++i) {
|
1561
|
-
WebSocket.__tasks[i]();
|
1562
|
-
}
|
1563
|
-
WebSocket.__tasks = [];
|
1564
|
-
} catch (e) {
|
1565
|
-
console.error("[WebSocket] " + e.toString());
|
1566
|
-
}
|
1567
|
-
});
|
1568
|
-
};
|
1569
|
-
|
1570
|
-
WebSocket.__addTask = function(task) {
|
1571
|
-
if (WebSocket.__flash) {
|
1572
|
-
task();
|
1573
|
-
} else {
|
1574
|
-
WebSocket.__tasks.push(task);
|
1575
|
-
}
|
1576
|
-
};
|
1577
|
-
|
1578
|
-
WebSocket.__isFlashLite = function() {
|
1579
|
-
if (!window.navigator || !window.navigator.mimeTypes) return false;
|
1580
|
-
var mimeType = window.navigator.mimeTypes["application/x-shockwave-flash"];
|
1581
|
-
if (!mimeType || !mimeType.enabledPlugin || !mimeType.enabledPlugin.filename) return false;
|
1582
|
-
return mimeType.enabledPlugin.filename.match(/flashlite/i) ? true : false;
|
1583
|
-
};
|
1584
|
-
|
1585
|
-
// called from Flash
|
1586
|
-
window.webSocketLog = function(message) {
|
1587
|
-
console.log(decodeURIComponent(message));
|
1588
|
-
};
|
1589
|
-
|
1590
|
-
// called from Flash
|
1591
|
-
window.webSocketError = function(message) {
|
1592
|
-
console.error(decodeURIComponent(message));
|
1593
|
-
};
|
1594
|
-
|
1595
|
-
if (!window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION) {
|
1596
|
-
if (window.addEventListener) {
|
1597
|
-
window.addEventListener("load", WebSocket.__initialize, false);
|
1598
|
-
} else {
|
1599
|
-
window.attachEvent("onload", WebSocket.__initialize);
|
1600
|
-
}
|
1601
|
-
}
|
1602
|
-
|
1603
|
-
})();
|
1604
|
-
|