· 9 years ago · May 05, 2016, 09:12 PM
1if (!window.hasOwnProperty("altspace")) {
2 /**
3 * The main module for the AltspaceVR SDK.
4 * @module altspace
5 */
6 Object.defineProperty(window, 'altspace', {
7 configurable: false,
8 enumerable: true,
9 value: {},
10 writable: false
11 });
12
13 altspace._internal = {};
14 altspace._internal.Alt = window.Alt = {};
15}
16
17var inherits = function(constructor, superConstructor, overrides) {
18 function F() {}
19 F.prototype = superConstructor.prototype;
20 constructor.prototype = new F();
21 if(overrides) {
22 for(var prop in overrides)
23 constructor.prototype[prop] = overrides[prop];
24 }
25};
26/*
27 * Licensed to the Apache Software Foundation (ASF) under one
28 * or more contributor license agreements. See the NOTICE file
29 * distributed with this work for additional information
30 * regarding copyright ownership. The ASF licenses this file
31 * to you under the Apache License, Version 2.0 (the
32 * "License"); you may not use this file except in compliance
33 * with the License. You may obtain a copy of the License at
34 *
35 * http://www.apache.org/licenses/LICENSE-2.0
36 *
37 * Unless required by applicable law or agreed to in writing,
38 * software distributed under the License is distributed on an
39 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
40 * KIND, either express or implied. See the License for the
41 * specific language governing permissions and limitations
42 * under the License.
43 */
44var Thrift = {
45 Version: '0.8.0',
46/*
47 Description: 'JavaScript bindings for the Apache Thrift RPC system',
48 License: 'http://www.apache.org/licenses/LICENSE-2.0',
49 Homepage: 'http://thrift.apache.org',
50 BugReports: 'https://issues.apache.org/jira/browse/THRIFT',
51 Maintainer: 'dev@thrift.apache.org',
52*/
53
54 Type: {
55 'STOP' : 0,
56 'VOID' : 1,
57 'BOOL' : 2,
58 'BYTE' : 3,
59 'I08' : 3,
60 'DOUBLE' : 4,
61 'I16' : 6,
62 'I32' : 8,
63 'I64' : 10,
64 'STRING' : 11,
65 'UTF7' : 11,
66 'STRUCT' : 12,
67 'MAP' : 13,
68 'SET' : 14,
69 'LIST' : 15,
70 'UTF8' : 16,
71 'UTF16' : 17
72 },
73
74 MessageType: {
75 'CALL' : 1,
76 'REPLY' : 2,
77 'EXCEPTION' : 3
78 },
79
80 objectLength: function(obj) {
81 var length = 0;
82 for (var k in obj) {
83 if (obj.hasOwnProperty(k)) {
84 length++;
85 }
86 }
87
88 return length;
89 },
90
91 inherits: function(constructor, superConstructor) {
92 //Prototypal Inheritance http://javascript.crockford.com/prototypal.html
93 function F() {}
94 F.prototype = superConstructor.prototype;
95 constructor.prototype = new F();
96 }
97};
98
99
100
101Thrift.TException = function(message) {
102 this.message = message;
103};
104Thrift.inherits(Thrift.TException, Error);
105Thrift.TException.prototype.name = 'TException';
106
107Thrift.TApplicationExceptionType = {
108 'UNKNOWN' : 0,
109 'UNKNOWN_METHOD' : 1,
110 'INVALID_MESSAGE_TYPE' : 2,
111 'WRONG_METHOD_NAME' : 3,
112 'BAD_SEQUENCE_ID' : 4,
113 'MISSING_RESULT' : 5,
114 'INTERNAL_ERROR' : 6,
115 'PROTOCOL_ERROR' : 7
116};
117
118Thrift.TApplicationException = function(message, code) {
119 this.message = message;
120 this.code = (code === null) ? 0 : code;
121};
122Thrift.inherits(Thrift.TApplicationException, Thrift.TException);
123Thrift.TApplicationException.prototype.name = 'TApplicationException';
124
125Thrift.TApplicationException.prototype.read = function(input) {
126 while (1) {
127 var ret = input.readFieldBegin();
128
129 if (ret.ftype == Thrift.Type.STOP) {
130 break;
131 }
132
133 var fid = ret.fid;
134
135 switch (fid) {
136 case 1:
137 if (ret.ftype == Thrift.Type.STRING) {
138 ret = input.readString();
139 this.message = ret.value;
140 } else {
141 ret = input.skip(ret.ftype);
142 }
143 break;
144 case 2:
145 if (ret.ftype == Thrift.Type.I32) {
146 ret = input.readI32();
147 this.code = ret.value;
148 } else {
149 ret = input.skip(ret.ftype);
150 }
151 break;
152 default:
153 ret = input.skip(ret.ftype);
154 break;
155 }
156
157 input.readFieldEnd();
158 }
159
160 input.readStructEnd();
161};
162
163Thrift.TApplicationException.prototype.write = function(output) {
164 var xfer = 0;
165
166 output.writeStructBegin('TApplicationException');
167
168 if (this.message) {
169 output.writeFieldBegin('message', Thrift.Type.STRING, 1);
170 output.writeString(this.getMessage());
171 output.writeFieldEnd();
172 }
173
174 if (this.code) {
175 output.writeFieldBegin('type', Thrift.Type.I32, 2);
176 output.writeI32(this.code);
177 output.writeFieldEnd();
178 }
179
180 output.writeFieldStop();
181 output.writeStructEnd();
182};
183
184Thrift.TApplicationException.prototype.getCode = function() {
185 return this.code;
186};
187
188Thrift.TApplicationException.prototype.getMessage = function() {
189 return this.message;
190};
191
192/**
193 *If you do not specify a url then you must handle ajax on your own.
194 *This is how to use js bindings in a async fashion.
195 */
196Thrift.TXHRTransport = function(url) {
197 this.url = url;
198 this.wpos = 0;
199 this.rpos = 0;
200
201 this.send_buf = '';
202 this.recv_buf = '';
203};
204
205Thrift.TXHRTransport.prototype = {
206
207 //Gets the browser specific XmlHttpRequest Object
208 getXmlHttpRequestObject: function() {
209 try { return new XMLHttpRequest(); } catch (e1) { }
210 try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch (e2) { }
211 try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch (e3) { }
212
213 throw "Your browser doesn't support the XmlHttpRequest object.";
214 },
215
216 flush: function(async) {
217 //async mode
218 if (async || this.url === undefined || this.url === '') {
219 return this.send_buf;
220 }
221
222 var xreq = this.getXmlHttpRequestObject();
223
224 if (xreq.overrideMimeType) {
225 xreq.overrideMimeType('application/json');
226 }
227
228 xreq.open('POST', this.url, false);
229 xreq.send(this.send_buf);
230
231 if (xreq.readyState != 4) {
232 throw 'encountered an unknown ajax ready state: ' + xreq.readyState;
233 }
234
235 if (xreq.status != 200) {
236 throw 'encountered a unknown request status: ' + xreq.status;
237 }
238
239 this.recv_buf = xreq.responseText;
240 this.recv_buf_sz = this.recv_buf.length;
241 this.wpos = this.recv_buf.length;
242 this.rpos = 0;
243 },
244
245 jqRequest: function(client, postData, args, recv_method) {
246 if (typeof jQuery === 'undefined' ||
247 typeof jQuery.Deferred === 'undefined') {
248 throw 'Thrift.js requires jQuery 1.5+ to use asynchronous requests';
249 }
250
251 // Deferreds
252 var deferred = jQuery.Deferred();
253 var completeDfd = jQuery._Deferred();
254 var dfd = deferred.promise();
255 dfd.success = dfd.done;
256 dfd.error = dfd.fail;
257 dfd.complete = completeDfd.done;
258
259 var jqXHR = jQuery.ajax({
260 url: this.url,
261 data: postData,
262 type: 'POST',
263 cache: false,
264 dataType: 'text',
265 context: this,
266 success: this.jqResponse,
267 error: function(xhr, status, e) {
268 deferred.rejectWith(client, jQuery.merge([e], xhr.tArgs));
269 },
270 complete: function(xhr, status) {
271 completeDfd.resolveWith(client, [xhr, status]);
272 }
273 });
274
275 deferred.done(jQuery.makeArray(args).pop()); //pop callback from args
276 jqXHR.tArgs = args;
277 jqXHR.tClient = client;
278 jqXHR.tRecvFn = recv_method;
279 jqXHR.tDfd = deferred;
280 return dfd;
281 },
282
283 jqResponse: function(responseData, textStatus, jqXHR) {
284 this.setRecvBuffer(responseData);
285 try {
286 var value = jqXHR.tRecvFn.call(jqXHR.tClient);
287 jqXHR.tDfd.resolveWith(jqXHR, jQuery.merge([value], jqXHR.tArgs));
288 } catch (ex) {
289 jqXHR.tDfd.rejectWith(jqXHR, jQuery.merge([ex], jqXHR.tArgs));
290 }
291 },
292
293 setRecvBuffer: function(buf) {
294 this.recv_buf = buf;
295 this.recv_buf_sz = this.recv_buf.length;
296 this.wpos = this.recv_buf.length;
297 this.rpos = 0;
298 },
299
300 isOpen: function() {
301 return true;
302 },
303
304 open: function() {},
305
306 close: function() {},
307
308 read: function(len) {
309 var avail = this.wpos - this.rpos;
310
311 if (avail === 0) {
312 return '';
313 }
314
315 var give = len;
316
317 if (avail < len) {
318 give = avail;
319 }
320
321 var ret = this.read_buf.substr(this.rpos, give);
322 this.rpos += give;
323
324 //clear buf when complete?
325 return ret;
326 },
327
328 readAll: function() {
329 return this.recv_buf;
330 },
331
332 write: function(buf) {
333 this.send_buf = buf;
334 },
335
336 getSendBuffer: function() {
337 return this.send_buf;
338 }
339
340};
341
342Thrift.TStringTransport = function(recv_buf, callback) {
343 this.send_buf = '';
344 this.recv_buf = recv_buf || '';
345 this.onFlush = callback;
346};
347
348Thrift.TStringTransport.prototype = {
349
350 flush: function() {
351 if(this.onFlush)
352 this.onFlush(this.send_buf);
353 },
354
355 isOpen: function() {
356 return true;
357 },
358
359 open: function() {},
360
361 close: function() {},
362
363 read: function(len) {
364 return this.recv_buf;
365 },
366
367 readAll: function() {
368 return this.recv_buf;
369 },
370
371 write: function(buf) {
372 this.send_buf = buf;
373 }
374
375};
376
377Thrift.Protocol = function(transport) {
378 this.transport = transport;
379};
380
381Thrift.Protocol.Type = {};
382Thrift.Protocol.Type[Thrift.Type.BOOL] = '"tf"';
383Thrift.Protocol.Type[Thrift.Type.BYTE] = '"i8"';
384Thrift.Protocol.Type[Thrift.Type.I16] = '"i16"';
385Thrift.Protocol.Type[Thrift.Type.I32] = '"i32"';
386Thrift.Protocol.Type[Thrift.Type.I64] = '"i64"';
387Thrift.Protocol.Type[Thrift.Type.DOUBLE] = '"dbl"';
388Thrift.Protocol.Type[Thrift.Type.STRUCT] = '"rec"';
389Thrift.Protocol.Type[Thrift.Type.STRING] = '"str"';
390Thrift.Protocol.Type[Thrift.Type.MAP] = '"map"';
391Thrift.Protocol.Type[Thrift.Type.LIST] = '"lst"';
392Thrift.Protocol.Type[Thrift.Type.SET] = '"set"';
393
394
395Thrift.Protocol.RType = {};
396Thrift.Protocol.RType.tf = Thrift.Type.BOOL;
397Thrift.Protocol.RType.i8 = Thrift.Type.BYTE;
398Thrift.Protocol.RType.i16 = Thrift.Type.I16;
399Thrift.Protocol.RType.i32 = Thrift.Type.I32;
400Thrift.Protocol.RType.i64 = Thrift.Type.I64;
401Thrift.Protocol.RType.dbl = Thrift.Type.DOUBLE;
402Thrift.Protocol.RType.rec = Thrift.Type.STRUCT;
403Thrift.Protocol.RType.str = Thrift.Type.STRING;
404Thrift.Protocol.RType.map = Thrift.Type.MAP;
405Thrift.Protocol.RType.lst = Thrift.Type.LIST;
406Thrift.Protocol.RType.set = Thrift.Type.SET;
407
408Thrift.Protocol.Version = 1;
409
410Thrift.Protocol.prototype = {
411
412 getTransport: function() {
413 return this.transport;
414 },
415
416 //Write functions
417 writeMessageBegin: function(name, messageType, seqid) {
418 this.tstack = [];
419 this.tpos = [];
420
421 this.tstack.push([Thrift.Protocol.Version, '"' +
422 name + '"', messageType, seqid]);
423 },
424
425 writeMessageEnd: function() {
426 var obj = this.tstack.pop();
427
428 this.wobj = this.tstack.pop();
429 this.wobj.push(obj);
430
431 this.wbuf = '[' + this.wobj.join(',') + ']';
432
433 this.transport.write(this.wbuf);
434 },
435
436
437 writeStructBegin: function(name) {
438 this.tpos.push(this.tstack.length);
439 this.tstack.push({});
440 },
441
442 writeStructEnd: function() {
443
444 var p = this.tpos.pop();
445 var struct = this.tstack[p];
446 var str = '{';
447 var first = true;
448 for (var key in struct) {
449 if (first) {
450 first = false;
451 } else {
452 str += ',';
453 }
454
455 str += key + ':' + struct[key];
456 }
457
458 str += '}';
459 this.tstack[p] = str;
460 },
461
462 writeFieldBegin: function(name, fieldType, fieldId) {
463 this.tpos.push(this.tstack.length);
464 this.tstack.push({ 'fieldId': '"' +
465 fieldId + '"', 'fieldType': Thrift.Protocol.Type[fieldType]
466 });
467
468 },
469
470 writeFieldEnd: function() {
471 var value = this.tstack.pop();
472 var fieldInfo = this.tstack.pop();
473
474 this.tstack[this.tstack.length - 1][fieldInfo.fieldId] = '{' +
475 fieldInfo.fieldType + ':' + value + '}';
476 this.tpos.pop();
477 },
478
479 writeFieldStop: function() {
480 //na
481 },
482
483 writeMapBegin: function(keyType, valType, size) {
484 //size is invalid, we'll set it on end.
485 this.tpos.push(this.tstack.length);
486 this.tstack.push([Thrift.Protocol.Type[keyType],
487 Thrift.Protocol.Type[valType], 0]);
488 },
489
490 writeMapEnd: function() {
491 var p = this.tpos.pop();
492
493 if (p == this.tstack.length) {
494 return;
495 }
496
497 if ((this.tstack.length - p - 1) % 2 !== 0) {
498 this.tstack.push('');
499 }
500
501 var size = (this.tstack.length - p - 1) / 2;
502
503 this.tstack[p][this.tstack[p].length - 1] = size;
504
505 var map = '}';
506 var first = true;
507 while (this.tstack.length > p + 1) {
508 var v = this.tstack.pop();
509 var k = this.tstack.pop();
510 if (first) {
511 first = false;
512 } else {
513 map = ',' + map;
514 }
515
516 if (! isNaN(k)) { k = '"' + k + '"'; } //json "keys" need to be strings
517 map = k + ':' + v + map;
518 }
519 map = '{' + map;
520
521 this.tstack[p].push(map);
522 this.tstack[p] = '[' + this.tstack[p].join(',') + ']';
523 },
524
525 writeListBegin: function(elemType, size) {
526 this.tpos.push(this.tstack.length);
527 this.tstack.push([Thrift.Protocol.Type[elemType], size]);
528 },
529
530 writeListEnd: function() {
531 var p = this.tpos.pop();
532
533 while (this.tstack.length > p + 1) {
534 var tmpVal = this.tstack[p + 1];
535 this.tstack.splice(p + 1, 1);
536 this.tstack[p].push(tmpVal);
537 }
538
539 this.tstack[p] = '[' + this.tstack[p].join(',') + ']';
540 },
541
542 writeSetBegin: function(elemType, size) {
543 this.tpos.push(this.tstack.length);
544 this.tstack.push([Thrift.Protocol.Type[elemType], size]);
545 },
546
547 writeSetEnd: function() {
548 var p = this.tpos.pop();
549
550 while (this.tstack.length > p + 1) {
551 var tmpVal = this.tstack[p + 1];
552 this.tstack.splice(p + 1, 1);
553 this.tstack[p].push(tmpVal);
554 }
555
556 this.tstack[p] = '[' + this.tstack[p].join(',') + ']';
557 },
558
559 writeBool: function(value) {
560 this.tstack.push(value ? 1 : 0);
561 },
562
563 writeByte: function(i8) {
564 this.tstack.push(i8);
565 },
566
567 writeI16: function(i16) {
568 this.tstack.push(i16);
569 },
570
571 writeI32: function(i32) {
572 this.tstack.push(i32);
573 },
574
575 writeI64: function(i64) {
576 this.tstack.push(i64);
577 },
578
579 writeDouble: function(dbl) {
580 this.tstack.push(dbl);
581 },
582
583 writeString: function(str) {
584 // We do not encode uri components for wire transfer:
585 if (str === null) {
586 this.tstack.push(null);
587 } else {
588 // concat may be slower than building a byte buffer
589 var escapedString = '';
590 for (var i = 0; i < str.length; i++) {
591 var ch = str.charAt(i); // a single double quote: "
592 if (ch === '\"') {
593 escapedString += '\\\"'; // write out as: \"
594 } else if (ch === '\\') { // a single backslash: \
595 escapedString += '\\\\'; // write out as: \\
596 /* Currently escaped forward slashes break TJSONProtocol.
597 * As it stands, we can simply pass forward slashes into
598 * our strings across the wire without being escaped.
599 * I think this is the protocol's bug, not thrift.js
600 * } else if(ch === '/') { // a single forward slash: /
601 * escapedString += '\\/'; // write out as \/
602 * }
603 */
604 } else if (ch === '\b') { // a single backspace: invisible
605 escapedString += '\\b'; // write out as: \b"
606 } else if (ch === '\f') { // a single formfeed: invisible
607 escapedString += '\\f'; // write out as: \f"
608 } else if (ch === '\n') { // a single newline: invisible
609 escapedString += '\\n'; // write out as: \n"
610 } else if (ch === '\r') { // a single return: invisible
611 escapedString += '\\r'; // write out as: \r"
612 } else if (ch === '\t') { // a single tab: invisible
613 escapedString += '\\t'; // write out as: \t"
614 } else {
615 escapedString += ch; // Else it need not be escaped
616 }
617 }
618 this.tstack.push('"' + escapedString + '"');
619 }
620 },
621
622 writeBinary: function(str) {
623 this.writeString(str);
624 },
625
626
627
628 // Reading functions
629 readMessageBegin: function(name, messageType, seqid) {
630 this.rstack = [];
631 this.rpos = [];
632
633 if (typeof jQuery !== 'undefined') {
634 this.robj = jQuery.parseJSON(this.transport.readAll());
635 } else {
636 this.robj = eval(this.transport.readAll());
637 }
638
639 var r = {};
640 var version = this.robj.shift();
641
642 if (version != Thrift.Protocol.Version) {
643 throw 'Wrong thrift protocol version: ' + version;
644 }
645
646 r.fname = this.robj.shift();
647 r.mtype = this.robj.shift();
648 r.rseqid = this.robj.shift();
649
650
651 //get to the main obj
652 this.rstack.push(this.robj.shift());
653
654 return r;
655 },
656
657 readMessageEnd: function() {
658 },
659
660 readStructBegin: function(name) {
661 var r = {};
662 r.fname = '';
663
664 //incase this is an array of structs
665 if (this.rstack[this.rstack.length - 1] instanceof Array) {
666 this.rstack.push(this.rstack[this.rstack.length - 1].shift());
667 }
668
669 return r;
670 },
671
672 readStructEnd: function() {
673 if (this.rstack[this.rstack.length - 2] instanceof Array) {
674 this.rstack.pop();
675 }
676 },
677
678 readFieldBegin: function() {
679 var r = {};
680
681 var fid = -1;
682 var ftype = Thrift.Type.STOP;
683
684 //get a fieldId
685 for (var f in (this.rstack[this.rstack.length - 1])) {
686 if (f === null) {
687 continue;
688 }
689
690 fid = parseInt(f, 10);
691 this.rpos.push(this.rstack.length);
692
693 var field = this.rstack[this.rstack.length - 1][fid];
694
695 //remove so we don't see it again
696 delete this.rstack[this.rstack.length - 1][fid];
697
698 this.rstack.push(field);
699
700 break;
701 }
702
703 if (fid != -1) {
704
705 //should only be 1 of these but this is the only
706 //way to match a key
707 for (var i in (this.rstack[this.rstack.length - 1])) {
708 if (Thrift.Protocol.RType[i] === null) {
709 continue;
710 }
711
712 ftype = Thrift.Protocol.RType[i];
713 this.rstack[this.rstack.length - 1] =
714 this.rstack[this.rstack.length - 1][i];
715 }
716 }
717
718 r.fname = '';
719 r.ftype = ftype;
720 r.fid = fid;
721
722 return r;
723 },
724
725 readFieldEnd: function() {
726 var pos = this.rpos.pop();
727
728 //get back to the right place in the stack
729 while (this.rstack.length > pos) {
730 this.rstack.pop();
731 }
732
733 },
734
735 readMapBegin: function(keyType, valType, size) {
736 var map = this.rstack.pop();
737
738 var r = {};
739 r.ktype = Thrift.Protocol.RType[map.shift()];
740 r.vtype = Thrift.Protocol.RType[map.shift()];
741 r.size = map.shift();
742
743
744 this.rpos.push(this.rstack.length);
745 this.rstack.push(map.shift());
746
747 return r;
748 },
749
750 readMapEnd: function() {
751 this.readFieldEnd();
752 },
753
754 readListBegin: function(elemType, size) {
755 var list = this.rstack[this.rstack.length - 1];
756
757 var r = {};
758 r.etype = Thrift.Protocol.RType[list.shift()];
759 r.size = list.shift();
760
761 this.rpos.push(this.rstack.length);
762 this.rstack.push(list);
763
764 return r;
765 },
766
767 readListEnd: function() {
768 this.readFieldEnd();
769 },
770
771 readSetBegin: function(elemType, size) {
772 return this.readListBegin(elemType, size);
773 },
774
775 readSetEnd: function() {
776 return this.readListEnd();
777 },
778
779 readBool: function() {
780 var r = this.readI32();
781
782 if (r !== null && r.value == '1') {
783 r.value = true;
784 } else {
785 r.value = false;
786 }
787
788 return r;
789 },
790
791 readByte: function() {
792 return this.readI32();
793 },
794
795 readI16: function() {
796 return this.readI32();
797 },
798
799 readI32: function(f) {
800 if (f === undefined) {
801 f = this.rstack[this.rstack.length - 1];
802 }
803
804 var r = {};
805
806 if (f instanceof Array) {
807 if (f.length === 0) {
808 r.value = undefined;
809 } else {
810 r.value = f.shift();
811 }
812 } else if (f instanceof Object) {
813 for (var i in f) {
814 if (i === null) {
815 continue;
816 }
817 this.rstack.push(f[i]);
818 delete f[i];
819
820 r.value = i;
821 break;
822 }
823 } else {
824 r.value = f;
825 this.rstack.pop();
826 }
827
828 return r;
829 },
830
831 readI64: function() {
832 return this.readI32();
833 },
834
835 readDouble: function() {
836 return this.readI32();
837 },
838
839 readString: function() {
840 var r = this.readI32();
841 return r;
842 },
843
844 readBinary: function() {
845 return this.readString();
846 },
847
848
849 //Method to arbitrarily skip over data.
850 skip: function(type) {
851 throw 'skip not supported yet';
852 }
853};
854
855Thrift.TJSONProtocol = function(transport) {
856 this.transport = transport;
857 this.reset();
858};
859
860Thrift.TJSONProtocol.Type = {};
861Thrift.TJSONProtocol.Type[Thrift.Type.BOOL] = 'tf';
862Thrift.TJSONProtocol.Type[Thrift.Type.BYTE] = 'i8';
863Thrift.TJSONProtocol.Type[Thrift.Type.I16] = 'i16';
864Thrift.TJSONProtocol.Type[Thrift.Type.I32] = 'i32';
865Thrift.TJSONProtocol.Type[Thrift.Type.I64] = 'i64';
866Thrift.TJSONProtocol.Type[Thrift.Type.DOUBLE] = 'dbl';
867Thrift.TJSONProtocol.Type[Thrift.Type.STRUCT] = 'rec';
868Thrift.TJSONProtocol.Type[Thrift.Type.STRING] = 'str';
869Thrift.TJSONProtocol.Type[Thrift.Type.MAP] = 'map';
870Thrift.TJSONProtocol.Type[Thrift.Type.LIST] = 'lst';
871Thrift.TJSONProtocol.Type[Thrift.Type.SET] = 'set';
872
873Thrift.TJSONProtocol.getValueFromScope = function(scope) {
874 var listvalue = scope.listvalue;
875 return listvalue ? listvalue.shift() : scope.value;
876};
877
878Thrift.TJSONProtocol.getScopeFromScope = function(scope) {
879 var listvalue = scope.listvalue;
880 if(listvalue)
881 scope = {value:listvalue.shift()};
882 return scope;
883};
884
885Thrift.TJSONProtocol.prototype = {
886
887 reset: function() {
888 this.elementStack = [];
889 },
890
891 //Write functions
892 writeMessageBegin: function(name, messageType, seqid) {
893 throw new Error("TJSONProtocol: Message not supported");
894 },
895
896 writeMessageEnd: function() {
897 },
898
899 writeStructBegin: function(name) {
900 var container = {};
901 this.elementStack.unshift(container);
902 },
903
904 writeStructEnd: function() {
905 var container = this.elementStack.shift();
906 if(this.elementStack.length == 0)
907 this.transport.write(JSON.stringify(container));
908 else
909 this.elementStack[0].value.push(container);
910 },
911
912 writeFieldBegin: function(name, fieldType, fieldId) {
913 var field = {name:name, fieldType:Thrift.TJSONProtocol.Type[fieldType], fieldId:fieldId, value:[]};
914 this.elementStack.unshift(field);
915 },
916
917 writeFieldEnd: function() {
918 var field = this.elementStack.shift();
919 var fieldValue = {};
920 fieldValue[field.fieldType] = field.value[0];
921 this.elementStack[0][field.fieldId] = fieldValue;
922 },
923
924 writeFieldStop: function() {
925 //na
926 },
927
928 writeMapBegin: function(keyType, valType, size) {
929 var map = {value:[
930 Thrift.TJSONProtocol.Type[keyType],
931 Thrift.TJSONProtocol.Type[valType],
932 size
933 ]};
934 this.elementStack.unshift(map);
935 },
936
937 writeMapEnd: function() {
938 var map = this.elementStack.shift();
939 this.elementStack[0].value.push(map.value);
940 },
941
942 writeListBegin: function(elemType, size) {
943 var list = {name:name, value:[
944 Thrift.TJSONProtocol.Type[elemType],
945 size
946 ]};
947 this.elementStack.unshift(list);
948 },
949
950 writeListEnd: function() {
951 var list = this.elementStack.shift();
952 this.elementStack[0].value.push(list.value);
953 },
954
955 writeSetBegin: function(elemType, size) {
956 var set = {name:name, value:[
957 Thrift.TJSONProtocol.Type[elemType],
958 size
959 ]};
960 this.elementStack.unshift(set);
961 },
962
963 writeSetEnd: function() {
964 var set = this.elementStack.shift();
965 this.elementStack[0].value.push(set.value);
966 },
967
968 writeBool: function(value) {
969 this.elementStack[0].value.push(value ? 1 : 0);
970 },
971
972 writeByte: function(i8) {
973 this.elementStack[0].value.push(i8);
974 },
975
976 writeI16: function(i16) {
977 this.elementStack[0].value.push(i16);
978 },
979
980 writeI32: function(i32) {
981 this.elementStack[0].value.push(i32);
982 },
983
984 writeI64: function(i64) {
985 this.elementStack[0].value.push(i64);
986 },
987
988 writeDouble: function(dbl) {
989 this.elementStack[0].value.push(dbl);
990 },
991
992 writeString: function(str) {
993 this.elementStack[0].value.push(str);
994 },
995
996 writeBinary: function(str) {
997 this.elementStack[0].value.push(str);
998 },
999
1000 // Reading functions
1001 readMessageBegin: function(name, messageType, seqid) {
1002 throw new Error("TJSONProtocol: Message not supported");
1003 },
1004
1005 readMessageEnd: function() {
1006 },
1007
1008 readStructBegin: function(name) {
1009 var value;
1010 if(this.elementStack.length == 0)
1011 value = JSON.parse(this.transport.readAll());
1012 else
1013 value = Thrift.TJSONProtocol.getValueFromScope(this.elementStack[0]);
1014
1015 var fields = [];
1016 for(var field in value)
1017 fields.push(field);
1018 this.elementStack.unshift({
1019 fields:fields,
1020 value:value
1021 });
1022 return {
1023 fname:''
1024 }
1025 },
1026
1027 readStructEnd: function() {
1028 this.elementStack.shift();
1029 },
1030
1031 readFieldBegin: function() {
1032 var scope = this.elementStack[0];
1033 var scopeValue = Thrift.TJSONProtocol.getValueFromScope(scope);
1034 var fid = scope.fields.shift();
1035 if(!fid)
1036 return {fname:'', ftype:Thrift.Type.STOP};
1037
1038 var fieldValue = scopeValue[fid];
1039 for(var soleMember in fieldValue) {
1040 this.elementStack.unshift({value:fieldValue[soleMember]});
1041 return {
1042 fname:'',
1043 fid:Number(fid),
1044 ftype:Thrift.Protocol.RType[soleMember]
1045 };
1046 }
1047 /* there are no members, which is a format error */
1048 throw new Error("TJSONProtocol: parse error reading field value");
1049 },
1050
1051 readFieldEnd: function() {
1052 this.elementStack.shift();
1053 },
1054
1055 readMapBegin: function(keyType, valType, size) {
1056 var scope = this.elementStack[0];
1057 var value = Thrift.TJSONProtocol.getValueFromScope(scope);
1058 var result = {
1059 ktype:Thrift.Protocol.RType[value.shift()],
1060 vtype:Thrift.Protocol.RType[value.shift()],
1061 size:value.shift()
1062 };
1063 this.elementStack.unshift({listvalue:value});
1064 return result;
1065 },
1066
1067 readMapEnd: function() {
1068 this.elementStack.shift();
1069 },
1070
1071 readListBegin: function(elemType, size) {
1072 var scope = this.elementStack[0];
1073 var value = Thrift.TJSONProtocol.getValueFromScope(scope);
1074 var result = {
1075 etype:Thrift.Protocol.RType[value.shift()],
1076 size:value.shift()
1077 };
1078 this.elementStack.unshift({listvalue:value});
1079 return result;
1080 },
1081
1082 readListEnd: function() {
1083 this.elementStack.shift();
1084 },
1085
1086 readSetBegin: function(elemType, size) {
1087 var scope = this.elementStack[0];
1088 var value = Thrift.TJSONProtocol.getValueFromScope(scope);
1089 var result = {
1090 etype:Thrift.Protocol.RType[value.shift()],
1091 size:value.shift()
1092 };
1093 this.elementStack.unshift({listvalue:value});
1094 return result;
1095 },
1096
1097 readSetEnd: function() {
1098 this.elementStack.shift();
1099 },
1100
1101 readBool: function() {
1102 return !!Thrift.TJSONProtocol.getValueFromScope(this.elementStack[0]);
1103 },
1104
1105 readByte: function() {
1106 return Thrift.TJSONProtocol.getValueFromScope(this.elementStack[0]);
1107 },
1108
1109 readI16: function() {
1110 return Thrift.TJSONProtocol.getValueFromScope(this.elementStack[0]);
1111 },
1112
1113 readI32: function(f) {
1114 return Thrift.TJSONProtocol.getValueFromScope(this.elementStack[0]);
1115 },
1116
1117 readI64: function() {
1118 return Thrift.TJSONProtocol.getValueFromScope(this.elementStack[0]);
1119 },
1120
1121 readDouble: function() {
1122 return Thrift.TJSONProtocol.getValueFromScope(this.elementStack[0]);
1123 },
1124
1125 readString: function() {
1126 return Thrift.TJSONProtocol.getValueFromScope(this.elementStack[0]);
1127 },
1128
1129 readBinary: function() {
1130 return Thrift.TJSONProtocol.getValueFromScope(this.elementStack[0]);
1131 },
1132
1133 flush: function() {
1134 this.transport.flush();
1135 }
1136};
1137var Utf8 = {
1138 encode: function(string, view, off) {
1139 var pos = off;
1140 for(var n = 0; n < string.length; n++) {
1141 var c = string.charCodeAt(n);
1142 if (c < 128) {
1143 view.setInt8(pos++, c);
1144 } else if((c > 127) && (c < 2048)) {
1145 view.setInt8(pos++, (c >> 6) | 192);
1146 view.setInt8(pos++, (c & 63) | 128);
1147 } else {
1148 view.setInt8(pos++, (c >> 12) | 224);
1149 view.setInt8(pos++, ((c >> 6) & 63) | 128);
1150 view.setInt8(pos++, (c & 63) | 128);
1151 }
1152 }
1153 return (pos - off);
1154 },
1155 decode : function(view, off, length) {
1156 var string = "";
1157 var i = off;
1158 length += off;
1159 var c = c1 = c2 = 0;
1160 while ( i < length ) {
1161 c = view.getInt8(i++);
1162 if (c < 128) {
1163 string += String.fromCharCode(c);
1164 } else if((c > 191) && (c < 224)) {
1165 c2 = view.getInt8(i++);
1166 string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
1167 } else {
1168 c2 = view.getInt8(i++);
1169 c3 = view.getInt8(i++);
1170 string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
1171 }
1172 }
1173 return string;
1174 }
1175}
1176
1177/* constructor simply creates a buffer of a specified length */
1178var Buffer = function(length) {
1179 this.offset = 0;
1180 this.length = length;
1181 if(length) {
1182 var buf = this.buf = new ArrayBuffer(length);
1183 this.view = new DataView(buf);
1184 }
1185};
1186
1187Buffer.prototype = {
1188 getArray: function() {
1189 if(!this.array)
1190 this.array = new Uint8Array(this.buf, this.offset, this.length);
1191 return this.array;
1192 },
1193 slice: function(start, end) {
1194 start = start || 0;
1195 end = end || this.length;
1196 var result = new Buffer();
1197 var length = result.length = end - start;
1198 var offset = result.offset = this.offset + start;
1199 var buf = result.buf = this.buf;
1200 result.view = new DataView(buf, offset, length);
1201 return result;
1202 },
1203 getInt8: function(off) {
1204 return this.view.getInt8(off);
1205 },
1206 getInt16: function(off) {
1207 return this.view.getInt16(off, false);
1208 },
1209 getInt32: function(off) {
1210 return this.view.getInt32(off, false);
1211 },
1212 getInt64: function(off) {
1213 var hi = this.view.getInt32(off, false);
1214 var lo = this.view.getUint32(off + 4, false);
1215 return new Int64(hi, lo);
1216 },
1217 getFloat64: function(off) {
1218 return this.view.getFloat64(off, false);
1219 },
1220 getUtf8String: function(off, utflen) {
1221 return Utf8.decode(this.view, off, utflen);
1222 },
1223 setInt8: function(off, v) {
1224 this.view.setInt8(off, v);
1225 },
1226 setInt16: function(off, v) {
1227 this.view.setInt16(off, v, false);
1228 },
1229 setInt32: function(off, v) {
1230 this.view.setInt32(off, v, false);
1231 },
1232 setInt64: function(off, v) {
1233 this.getArray().set(v.buffer, off);
1234 },
1235 setFloat64: function(off, v) {
1236 this.view.setFloat64(off, v, false);
1237 },
1238 setBuffer: function(off, v) {
1239 this.getArray().set(v.getArray(), off);
1240 },
1241 setRawString: function(off, v) {
1242 var arr = this.getArray();
1243
1244 for (var i = 0, len = v.length; i < len; i++) {
1245 arr[i + off] = v.charCodeAt(i);
1246 }
1247 },
1248 setUtf8String: function(off, v) {
1249 return Utf8.encode(v, this.view, off);
1250 },
1251 inspect: function() {
1252 var result = 'length: ' + this.length + '\n';
1253 var idx = 0;
1254 while(idx < this.length) {
1255 for(var i = 0; (idx < this.length) && (i < 32); i++)
1256 result += this.view.getInt8(idx++).toString(16) + ' ';
1257 result += '\n';
1258 }
1259 return result;
1260 }
1261};
1262
1263var CheckedBuffer = Thrift.CheckedBuffer = function(length) {
1264 Buffer.call(this, length);
1265};
1266inherits(CheckedBuffer, Buffer, {
1267 grow: function(extra) {
1268 extra = extra || 0;
1269 var len = this.length + Math.max(extra, this.length*0.41);
1270 var src = getArray();
1271 this.buf = new ArrayBuffer(len);
1272 this.view = new DataView(this.buf);
1273 this.getArray().set(src);
1274 this.offset = 0;
1275 this.length = len;
1276 },
1277 checkAvailable: function(off, extra) {
1278 if(off + extra >= this.length)
1279 this.grow(extra);
1280 },
1281 setInt8: function(off, v) {
1282 this.checkAvailable(1);
1283 this.view.setInt8(off, v);
1284 },
1285 setInt16: function(off, v) {
1286 this.checkAvailable(2);
1287 this.view.setInt16(off, v, false);
1288 },
1289 setInt32: function(off, v) {
1290 this.checkAvailable(4);
1291 this.view.setInt32(off, v, false);
1292 },
1293 setInt64: function(off, v) {
1294 this.checkAvailable(8);
1295 this.getArray().set(v.buffer, off);
1296 },
1297 setFloat64: function(off, v) {
1298 this.checkAvailable(8);
1299 this.view.setFloat64(off, v, false);
1300 },
1301 setBuffer: function(off, v) {
1302 this.checkAvailable(v.length);
1303 this.getArray().set(v.getArray(), off);
1304 },
1305 setUtf8String: function(off, v) {
1306 while(true) {
1307 try {
1308 return Utf8.encode(v, this.view, off);
1309 } catch(e) {
1310 this.grow();
1311 }
1312 }
1313 }
1314});
1315var emptyBuf = new Buffer(0);
1316
1317var InputBufferUnderrunError = function() {
1318};
1319
1320var TTransport = Thrift.TTransport = function(buffer, callback) {
1321 this.buf = buffer || emptyBuf;
1322 this.onFlush = callback;
1323 this.reset();
1324};
1325
1326TTransport.receiver = function(callback) {
1327 return function(data) {
1328 callback(new TTransport(data));
1329 };
1330};
1331
1332TTransport.prototype = {
1333 commitPosition: function(){},
1334 rollbackPosition: function(){},
1335
1336 reset: function() {
1337 this.pos = 0;
1338 },
1339
1340 // TODO: Implement open/close support
1341 isOpen: function() {return true;},
1342 open: function() {},
1343 close: function() {},
1344
1345 read: function(len) { // this function will be used for each frames.
1346 var end = this.pos + len;
1347
1348 if (this.buf.length < end) {
1349 throw new Error('read(' + len + ') failed - not enough data');
1350 }
1351
1352 var buf = this.buf.slice(this.pos, end);
1353 this.pos = end;
1354 return buf;
1355 },
1356
1357 readByte: function() {
1358 return this.buf.getInt8(this.pos++);
1359 },
1360
1361 readI16: function() {
1362 var i16 = this.buf.getInt16(this.pos);
1363 this.pos += 2;
1364 return i16;
1365 },
1366
1367 readI32: function() {
1368 var i32 = this.buf.getInt32(this.pos);
1369 this.pos += 4;
1370 return i32;
1371 },
1372
1373 readDouble: function() {
1374 var d = this.buf.getFloat64(this.pos);
1375 this.pos += 8;
1376 return d;
1377 },
1378
1379 readString: function(len) {
1380 var str = this.buf.getUtf8String(this.pos, len);
1381 this.pos += len;
1382 return str;
1383 },
1384
1385 readAll: function() {
1386 return this.buf;
1387 },
1388
1389 writeByte: function(v) {
1390 this.buf.setInt8(this.pos++, v);
1391 },
1392
1393 writeI16: function(v) {
1394 this.buf.setInt16(this.pos, v);
1395 this.pos += 2;
1396 },
1397
1398 writeI32: function(v) {
1399 this.buf.setInt32(this.pos, v);
1400 this.pos += 4;
1401 },
1402
1403 writeI64: function(v) {
1404 this.buf.setInt64(this.pos, v);
1405 this.pos += 8;
1406 },
1407
1408 writeDouble: function(v) {
1409 this.buf.setFloat64(this.pos, v);
1410 this.pos += 8;
1411 },
1412
1413 write: function(buf) {
1414 if (typeof(buf) === 'string') {
1415 this.pos += this.setUtf8String(this.pos, buf);
1416 } else {
1417 this.setBuffer(this.pos, buf);
1418 this.pos += buf.length;
1419 }
1420 },
1421
1422 writeWithLength: function(buf) {
1423 var len;
1424 if (typeof(buf) === 'string') {
1425 len = this.buf.setUtf8String(this.pos + 4, buf);
1426 } else {
1427 this.buf.setBuffer(this.pos + 4, buf);
1428 len = buf.length;
1429 }
1430 this.buf.setInt32(this.pos, len);
1431 this.pos += len + 4;
1432 },
1433
1434 flush: function(flushCallback) {
1435 flushCallback = flushCallback || this.onFlush;
1436 if(flushCallback) {
1437 var out = this.buf.slice(0, this.pos);
1438 flushCallback(out);
1439 }
1440 }
1441};
1442
1443var TFramedTransport = Thrift.TFramedTransport = function(buffer, callback) {
1444 TTransport.call(this, buffer, callback);
1445};
1446
1447TFramedTransport.receiver = function(callback) {
1448 var frameLeft = 0,
1449 framePos = 0,
1450 frame = null;
1451 var residual = null;
1452
1453 return function(data) {
1454 // Prepend any residual data from our previous read
1455 if (residual) {
1456 var dat = new Buffer(data.length + residual.length);
1457 residual.copy(dat, 0, 0);
1458 data.copy(dat, residual.length, 0);
1459 residual = null;
1460 }
1461
1462 // framed transport
1463 while (data.length) {
1464 if (frameLeft === 0) {
1465 // TODO assumes we have all 4 bytes
1466 if (data.length < 4) {
1467 console.log("Expecting > 4 bytes, found only " + data.length);
1468 residual = data;
1469 break;
1470 //throw Error("Expecting > 4 bytes, found only " + data.length);
1471 }
1472 frameLeft = binary.readI32(data, 0);
1473 frame = new Buffer(frameLeft);
1474 framePos = 0;
1475 data = data.slice(4, data.length);
1476 }
1477
1478 if (data.length >= frameLeft) {
1479 data.copy(frame, framePos, 0, frameLeft);
1480 data = data.slice(frameLeft, data.length);
1481
1482 frameLeft = 0;
1483 callback(new TFramedTransport(frame));
1484 } else if (data.length) {
1485 data.copy(frame, framePos, 0, data.length);
1486 frameLeft -= data.length;
1487 framePos += data.length;
1488 data = data.slice(data.length, data.length);
1489 }
1490 }
1491 };
1492};
1493
1494inherits(TFramedTransport, TTransport, {
1495 flush: function() {
1496 var that = this;
1497 // TODO: optimize this better, allocate one buffer instead of both:
1498 var framedBuffer = function(out) {
1499 if(that.onFlush) {
1500 var msg = new Buffer(out.length + 4);
1501 binary.writeI32(msg, out.length);
1502 out.copy(msg, 4, 0, out.length);
1503 that.onFlush(msg);
1504 }
1505 };
1506 TTransport.prototype.flush.call(this, framedBuffer);
1507 }
1508});
1509/**
1510 * Support for handling 64-bit int numbers in Javascript (node.js)
1511 *
1512 * JS Numbers are IEEE-754 binary double-precision floats, which limits the
1513 * range of values that can be represented with integer precision to:
1514 *
1515 * 2^^53 <= N <= 2^53
1516 *
1517 * Int64 objects wrap a node Buffer that holds the 8-bytes of int64 data. These
1518 * objects operate directly on the buffer which means that if they are created
1519 * using an existing buffer then setting the value will modify the Buffer, and
1520 * vice-versa.
1521 *
1522 * Internal Representation
1523 *
1524 * The internal buffer format is Big Endian. I.e. the most-significant byte is
1525 * at buffer[0], the least-significant at buffer[7]. For the purposes of
1526 * converting to/from JS native numbers, the value is assumed to be a signed
1527 * integer stored in 2's complement form.
1528 *
1529 * For details about IEEE-754 see:
1530 * http://en.wikipedia.org/wiki/Double_precision_floating-point_format
1531 */
1532
1533// Useful masks and values for bit twiddling
1534var MASK31 = 0x7fffffff, VAL31 = 0x80000000;
1535var MASK32 = 0xffffffff, VAL32 = 0x100000000;
1536
1537// Map for converting hex octets to strings
1538var _HEX = [];
1539for (var i = 0; i < 256; i++) {
1540 _HEX[i] = (i > 0xF ? '' : '0') + i.toString(16);
1541}
1542
1543//
1544// Int64
1545//
1546
1547/**
1548 * Constructor accepts any of the following argument types:
1549 *
1550 * new Int64(buffer[, offset=0]) - Existing Array or Uint8Array with element offset
1551 * new Int64(string) - Hex string (throws if n is outside int64 range)
1552 * new Int64(number) - Number (throws if n is outside int64 range)
1553 * new Int64(hi, lo) - Raw bits as two 32-bit values
1554 */
1555var Int64 = function(a1, a2) {
1556 if (a1 instanceof Array) {
1557 this.buffer = a1;
1558 this.offset = a2 || 0;
1559 } else {
1560 this.buffer = this.buffer || new Array(8);
1561 this.offset = 0;
1562 this.setValue.apply(this, arguments);
1563 }
1564};
1565
1566
1567// Max integer value that JS can accurately represent
1568Int64.MAX_INT = Math.pow(2, 53);
1569
1570// Min integer value that JS can accurately represent
1571Int64.MIN_INT = -Math.pow(2, 53);
1572
1573Int64.prototype = {
1574 /**
1575 * Do in-place 2's compliment. See
1576 * http://en.wikipedia.org/wiki/Two's_complement
1577 */
1578 _2scomp: function() {
1579 var b = this.buffer, o = this.offset, carry = 1;
1580 for (var i = o + 7; i >= o; i--) {
1581 var v = (b[i] ^ 0xff) + carry;
1582 b[i] = v & 0xff;
1583 carry = v >> 8;
1584 }
1585 },
1586
1587 /**
1588 * Set the value. Takes any of the following arguments:
1589 *
1590 * setValue(string) - A hexidecimal string
1591 * setValue(number) - Number (throws if n is outside int64 range)
1592 * setValue(hi, lo) - Raw bits as two 32-bit values
1593 */
1594 setValue: function(hi, lo) {
1595 var negate = false;
1596 if (arguments.length == 1) {
1597 if (typeof(hi) == 'number') {
1598 // Simplify bitfield retrieval by using abs() value. We restore sign
1599 // later
1600 negate = hi < 0;
1601 hi = Math.abs(hi);
1602 lo = hi % VAL32;
1603 hi = hi / VAL32;
1604 if (hi > VAL32) throw new RangeError(hi + ' is outside Int64 range');
1605 hi = hi | 0;
1606 } else if (typeof(hi) == 'string') {
1607 hi = (hi + '').replace(/^0x/, '');
1608 lo = hi.substr(-8);
1609 hi = hi.length > 8 ? hi.substr(0, hi.length - 8) : '';
1610 hi = parseInt(hi, 16);
1611 lo = parseInt(lo, 16);
1612 } else {
1613 throw new Error(hi + ' must be a Number or String');
1614 }
1615 }
1616
1617 // Technically we should throw if hi or lo is outside int32 range here, but
1618 // it's not worth the effort. Anything past the 32'nd bit is ignored.
1619
1620 // Copy bytes to buffer
1621 var b = this.buffer, o = this.offset;
1622 for (var i = 7; i >= 0; i--) {
1623 b[o+i] = lo & 0xff;
1624 lo = i == 4 ? hi : lo >>> 8;
1625 }
1626
1627 // Restore sign of passed argument
1628 if (negate) this._2scomp();
1629 },
1630
1631 /**
1632 * Convert to a native JS number.
1633 *
1634 * WARNING: Do not expect this value to be accurate to integer precision for
1635 * large (positive or negative) numbers!
1636 *
1637 * @param allowImprecise If true, no check is performed to verify the
1638 * returned value is accurate to integer precision. If false, imprecise
1639 * numbers (very large positive or negative numbers) will be forced to +/-
1640 * Infinity.
1641 */
1642 toNumber: function(allowImprecise) {
1643 var b = this.buffer, o = this.offset;
1644
1645 // Running sum of octets, doing a 2's complement
1646 var negate = b[0] & 0x80, x = 0, carry = 1;
1647 for (var i = 7, m = 1; i >= 0; i--, m *= 256) {
1648 var v = b[o+i];
1649
1650 // 2's complement for negative numbers
1651 if (negate) {
1652 v = (v ^ 0xff) + carry;
1653 carry = v >> 8;
1654 v = v & 0xff;
1655 }
1656
1657 x += v * m;
1658 }
1659
1660 // Return Infinity if we've lost integer precision
1661 if (!allowImprecise && x >= Int64.MAX_INT) {
1662 return negate ? -Infinity : Infinity;
1663 }
1664
1665 return negate ? -x : x;
1666 },
1667
1668 /**
1669 * Convert to a JS Number. Returns +/-Infinity for values that can't be
1670 * represented to integer precision.
1671 */
1672 valueOf: function() {
1673 return this.toNumber(false);
1674 },
1675
1676 /**
1677 * Return string value
1678 *
1679 * @param radix Just like Number#toString()'s radix
1680 */
1681 toString: function(radix) {
1682 return this.valueOf().toString(radix || 10);
1683 },
1684
1685 /**
1686 * Return a string showing the buffer octets, with MSB on the left.
1687 *
1688 * @param sep separator string. default is '' (empty string)
1689 */
1690 toOctetString: function(sep) {
1691 var out = new Array(8);
1692 var b = this.buffer, o = this.offset;
1693 for (var i = 0; i < 8; i++) {
1694 out[i] = _HEX[b[o+i]];
1695 }
1696 return out.join(sep || '');
1697 },
1698
1699 /**
1700 * Pretty output in console.log
1701 */
1702 inspect: function() {
1703 return '[Int64 value:' + this + ' octets:' + this.toOctetString(' ') + ']';
1704 }
1705};/*
1706 * Licensed to the Apache Software Foundation (ASF) under one
1707 * or more contributor license agreements. See the NOTICE file
1708 * distributed with this work for additional information
1709 * regarding copyright ownership. The ASF licenses this file
1710 * to you under the Apache License, Version 2.0 (the
1711 * "License"); you may not use this file except in compliance
1712 * with the License. You may obtain a copy of the License at
1713 *
1714 * http://www.apache.org/licenses/LICENSE-2.0
1715 *
1716 * Unless required by applicable law or agreed to in writing,
1717 * software distributed under the License is distributed on an
1718 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1719 * KIND, either express or implied. See the License for the
1720 * specific language governing permissions and limitations
1721 * under the License.
1722 */
1723var Type = Thrift.Type;
1724
1725var UNKNOWN = 0,
1726 INVALID_DATA = 1,
1727 NEGATIVE_SIZE = 2,
1728 SIZE_LIMIT = 3,
1729 BAD_VERSION = 4;
1730
1731var TProtocolException = function(type, message) {
1732 Error.call(this, message);
1733 this.name = 'TProtocolException';
1734 this.type = type;
1735};
1736inherits(TProtocolException, Error);
1737
1738var TBinaryProtocol = Thrift.TBinaryProtocol = function(trans, strictRead, strictWrite) {
1739 this.trans = trans;
1740 this.strictRead = (strictRead !== undefined ? strictRead : false);
1741 this.strictWrite = (strictWrite !== undefined ? strictWrite : true);
1742};
1743
1744TBinaryProtocol.prototype.flush = function() {
1745 return this.trans.flush();
1746};
1747
1748// NastyHaxx. JavaScript forces hex constants to be
1749// positive, converting this into a long. If we hardcode the int value
1750// instead it'll stay in 32 bit-land.
1751
1752var VERSION_MASK = -65536, // 0xffff0000
1753 VERSION_1 = -2147418112, // 0x80010000
1754 TYPE_MASK = 0x000000ff;
1755
1756TBinaryProtocol.prototype.writeMessageBegin = function(name, type, seqid) {
1757 if (this.strictWrite) {
1758 this.writeI32(VERSION_1 | type);
1759 this.writeString(name);
1760 this.writeI32(seqid);
1761 } else {
1762 this.writeString(name);
1763 this.writeByte(type);
1764 this.writeI32(seqid);
1765 }
1766};
1767
1768TBinaryProtocol.prototype.writeMessageEnd = function() {
1769};
1770
1771TBinaryProtocol.prototype.writeStructBegin = function(name) {
1772};
1773
1774TBinaryProtocol.prototype.writeStructEnd = function() {
1775};
1776
1777TBinaryProtocol.prototype.writeFieldBegin = function(name, type, id) {
1778 this.writeByte(type);
1779 this.writeI16(id);
1780};
1781
1782TBinaryProtocol.prototype.writeFieldEnd = function() {
1783};
1784
1785TBinaryProtocol.prototype.writeFieldStop = function() {
1786 this.writeByte(Type.STOP);
1787};
1788
1789TBinaryProtocol.prototype.writeMapBegin = function(ktype, vtype, size) {
1790 this.writeByte(ktype);
1791 this.writeByte(vtype);
1792 this.writeI32(size);
1793};
1794
1795TBinaryProtocol.prototype.writeMapEnd = function() {
1796};
1797
1798TBinaryProtocol.prototype.writeListBegin = function(etype, size) {
1799 this.writeByte(etype);
1800 this.writeI32(size);
1801};
1802
1803TBinaryProtocol.prototype.writeListEnd = function() {
1804};
1805
1806TBinaryProtocol.prototype.writeSetBegin = function(etype, size) {
1807 this.writeByte(etype);
1808 this.writeI32(size);
1809};
1810
1811TBinaryProtocol.prototype.writeSetEnd = function() {
1812};
1813
1814TBinaryProtocol.prototype.writeBool = function(bool) {
1815 this.writeByte(bool ? 1 : 0);
1816};
1817
1818TBinaryProtocol.prototype.writeByte = function(i8) {
1819 this.trans.writeByte(i8);
1820};
1821
1822TBinaryProtocol.prototype.writeI16 = function(i16) {
1823 this.trans.writeI16(i16);
1824};
1825
1826TBinaryProtocol.prototype.writeI32 = function(i32) {
1827 this.trans.writeI32(i32);
1828};
1829
1830TBinaryProtocol.prototype.writeI64 = function(i64) {
1831 if (i64.buffer) {
1832 this.trans.writeI64(i64);
1833 } else {
1834 this.trans.writeI64(new Int64(i64))
1835 }
1836};
1837
1838TBinaryProtocol.prototype.writeDouble = function(dub) {
1839 this.trans.writeDouble(dub);
1840};
1841
1842TBinaryProtocol.prototype.writeString = function(arg) {
1843 this.trans.writeWithLength(arg);
1844};
1845
1846TBinaryProtocol.prototype.writeBinary = function(arg) {
1847 this.trans.writeWithLength(arg);
1848};
1849
1850TBinaryProtocol.prototype.readMessageBegin = function() {
1851 var sz = this.readI32();
1852 var type, name, seqid;
1853
1854 if (sz < 0) {
1855 var version = sz & VERSION_MASK;
1856 if (version != VERSION_1) {
1857 console.log("BAD: " + version);
1858 throw TProtocolException(BAD_VERSION, "Bad version in readMessageBegin: " + sz);
1859 }
1860 type = sz & TYPE_MASK;
1861 name = this.readString();
1862 seqid = this.readI32();
1863 } else {
1864 if (this.strictRead) {
1865 throw TProtocolException(BAD_VERSION, "No protocol version header");
1866 }
1867 name = this.trans.read(sz);
1868 type = this.readByte();
1869 seqid = this.readI32();
1870 }
1871 return {fname: name, mtype: type, rseqid: seqid};
1872};
1873
1874TBinaryProtocol.prototype.readMessageEnd = function() {
1875};
1876
1877TBinaryProtocol.prototype.readStructBegin = function() {
1878 return {fname: ''}
1879};
1880
1881TBinaryProtocol.prototype.readStructEnd = function() {
1882};
1883
1884TBinaryProtocol.prototype.readFieldBegin = function() {
1885 var type = this.readByte();
1886 if (type == Type.STOP) {
1887 return {fname: null, ftype: type, fid: 0};
1888 }
1889 var id = this.readI16();
1890 return {fname: null, ftype: type, fid: id};
1891};
1892
1893TBinaryProtocol.prototype.readFieldEnd = function() {
1894};
1895
1896TBinaryProtocol.prototype.readMapBegin = function() {
1897 var ktype = this.readByte();
1898 var vtype = this.readByte();
1899 var size = this.readI32();
1900 return {ktype: ktype, vtype: vtype, size: size};
1901};
1902
1903TBinaryProtocol.prototype.readMapEnd = function() {
1904};
1905
1906TBinaryProtocol.prototype.readListBegin = function() {
1907 var etype = this.readByte();
1908 var size = this.readI32();
1909 return {etype: etype, size: size};
1910};
1911
1912TBinaryProtocol.prototype.readListEnd = function() {
1913};
1914
1915TBinaryProtocol.prototype.readSetBegin = function() {
1916 var etype = this.readByte();
1917 var size = this.readI32();
1918 return {etype: etype, size: size};
1919};
1920
1921TBinaryProtocol.prototype.readSetEnd = function() {
1922};
1923
1924TBinaryProtocol.prototype.readBool = function() {
1925 var i8 = this.readByte();
1926 if (i8 == 0) {
1927 return false;
1928 }
1929 return true;
1930};
1931
1932TBinaryProtocol.prototype.readByte = function() {
1933 return this.trans.readByte();
1934};
1935
1936TBinaryProtocol.prototype.readI16 = function() {
1937 return this.trans.readI16();
1938};
1939
1940TBinaryProtocol.prototype.readI32 = function() {
1941 return this.trans.readI32();
1942};
1943
1944TBinaryProtocol.prototype.readI64 = function() {
1945 return this.trans.readI64();
1946};
1947
1948TBinaryProtocol.prototype.readDouble = function() {
1949 return this.trans.readDouble();
1950};
1951
1952TBinaryProtocol.prototype.readBinary = function() {
1953 var len = this.readI32();
1954 return this.trans.read(len);
1955};
1956
1957TBinaryProtocol.prototype.readString = function() {
1958 var len = this.readI32();
1959 return this.trans.readString(len);
1960};
1961
1962TBinaryProtocol.prototype.getTransport = function() {
1963 return this.trans;
1964};
1965
1966TBinaryProtocol.prototype.skip = function(type) {
1967 // console.log("skip: " + type);
1968 switch (type) {
1969 case Type.STOP:
1970 return;
1971 case Type.BOOL:
1972 this.readBool();
1973 break;
1974 case Type.BYTE:
1975 this.readByte();
1976 break;
1977 case Type.I16:
1978 this.readI16();
1979 break;
1980 case Type.I32:
1981 this.readI32();
1982 break;
1983 case Type.I64:
1984 this.readI64();
1985 break;
1986 case Type.DOUBLE:
1987 this.readDouble();
1988 break;
1989 case Type.STRING:
1990 this.readString();
1991 break;
1992 case Type.STRUCT:
1993 this.readStructBegin();
1994 while (true) {
1995 var r = this.readFieldBegin();
1996 if (r.ftype === Type.STOP) {
1997 break;
1998 }
1999 this.skip(r.ftype);
2000 this.readFieldEnd();
2001 }
2002 this.readStructEnd();
2003 break;
2004 case Type.MAP:
2005 var r = this.readMapBegin();
2006 for (var i = 0; i < r.size; ++i) {
2007 this.skip(r.ktype);
2008 this.skip(r.vtype);
2009 }
2010 this.readMapEnd();
2011 break;
2012 case Type.SET:
2013 var r = this.readSetBegin();
2014 for (var i = 0; i < r.size; ++i) {
2015 this.skip(r.etype);
2016 }
2017 this.readSetEnd();
2018 break;
2019 case Type.LIST:
2020 var r = this.readListBegin();
2021 for (var i = 0; i < r.size; ++i) {
2022 this.skip(r.etype);
2023 }
2024 this.readListEnd();
2025 break;
2026 default:
2027 throw Error("Invalid type: " + type);
2028 }
2029};
2030
2031altspace._internal.DynamicThriftBuffer = (function () {
2032 var constr = function() {
2033 var buffer;
2034 var transport;
2035 var protocol;
2036 var length;
2037 var bufferByteArray;
2038
2039 var switchToBufferOfLength = function(newLength) {
2040 buffer = new Buffer(newLength);
2041 bufferByteArray = new Uint8Array(buffer.buf);
2042 transport = new TFramedTransport(buffer);
2043 protocol = new TBinaryProtocol(transport);
2044 length = newLength;
2045 };
2046
2047 var grow = function() {
2048 // This reaches inside of the buffer object, kind of hacky.
2049 var oldArray = buffer.getArray();
2050 var oldLength = length;
2051
2052 length = Math.floor(length * 1.4);
2053
2054 switchToBufferOfLength(length);
2055 buffer.getArray().set(oldArray);
2056 buffer.offset = 0;
2057 buffer.length = length;
2058 };
2059
2060 this.getBinaryString = function(thriftObject) {
2061 transport.reset();
2062
2063 while (true) {
2064 try {
2065 thriftObject.write(protocol);
2066 break;
2067 } catch (e) {
2068 if (length < 1024 * 1024 * 64) {
2069 grow();
2070 } else {
2071 throw e;
2072 }
2073 }
2074 }
2075
2076 return constr.toBinaryString(bufferByteArray, transport.pos);
2077 };
2078
2079 // Start off with 1024 byte length.
2080 switchToBufferOfLength(1024);
2081 };
2082
2083 constr.toBinaryString = function (arr, len) {
2084 var chunkSize = 0xffff;
2085 var numChunks = Math.floor(len / chunkSize) + (len % chunkSize == 0 ? 0 : 1);
2086 var outputStr = new Array(numChunks);
2087
2088 for (var i = 0, c = 0; c < len; i++, c = i * chunkSize) {
2089 var lastIndex = i == numChunks - 1 ? len : (i + 1) * chunkSize;
2090 outputStr[i] = String.fromCharCode.apply(null, arr.subarray(c, lastIndex));
2091 }
2092
2093 return outputStr.join("");
2094 };
2095
2096 return constr;
2097}());
2098
2099
2100altspace._internal.ScratchThriftBuffer = new altspace._internal.DynamicThriftBuffer();
2101
2102/*jslint browser: true, nomen: true, plusplus: true */
2103
2104/// @file coherent.js
2105/// @namespace engine
2106
2107/// Coherent UI JavaScript interface.
2108/// The `engine` module contains all functions for communication between the UI and the game / application.
2109(function (factory) {
2110 if (typeof module === 'object' && module.exports) {
2111 module.exports = factory(global, global.engine, false);
2112 } else {
2113 window.engine = factory(window, window.engine, true);
2114 }
2115
2116 // altvr, fired so we can extend window.engine ourselves immediately
2117 document.dispatchEvent(new Event("WindowEngineCreated"));
2118})(function (global, engine, hasOnLoad) {
2119 'use strict';
2120
2121
2122 /**
2123 * Event emitter
2124 *
2125 * @class Emitter
2126 */
2127 function Emitter() {
2128 this.events = {};
2129 }
2130
2131 function Handler(code, context) {
2132 this.code = code;
2133 this.context = context;
2134 }
2135
2136 Emitter.prototype._createClear = function (object, name, handler) {
2137 return function() {
2138 var handlers = object.events[name];
2139 if (handlers) {
2140 var index = handlers.indexOf(handler);
2141 if (index != -1) {
2142 handlers.splice(index, 1);
2143 if (handlers.length === 0) {
2144 delete object.events[name];
2145 }
2146 }
2147 }
2148 };
2149 };
2150
2151 /// @file coherent.js
2152
2153 /**
2154 * Add a handler for an event
2155 *
2156 * @method on
2157 * @param name the event name
2158 * @param callback function to be called when the event is triggered
2159 * @param context this binding for executing the handler, defaults to the Emitter
2160 * @return connection object
2161 */
2162 Emitter.prototype.on = function (name, callback, context) {
2163 var handlers = this.events[name];
2164
2165 if (handlers === undefined) {
2166 handlers = this.events[name] = [];
2167 }
2168
2169 var handler = new Handler(callback, context || this);
2170 handlers.push(handler);
2171 return { clear: this._createClear(this, name, handler) };
2172 };
2173
2174 /**
2175 * Remove a handler from an event
2176 *
2177 * @method off
2178 * @param name the event name
2179 * @param callback function to be called when the event is triggered
2180 * @param context this binding for executing the handler, defaults to the Emitter
2181 * @return connection object
2182 */
2183 Emitter.prototype.off = function (name, handler, context) {
2184 var handlers = this.events[name];
2185
2186 if (handlers !== undefined) {
2187 context = context || this;
2188
2189 var index;
2190 var length = handlers.length;
2191 for (index = 0; index < length; ++index) {
2192 var reg = handlers[index];
2193 if (reg.code == handler && reg.context == context) {
2194 break;
2195 }
2196 }
2197 if (index < length) {
2198 handlers.splice(index, 1);
2199 if (handlers.length === 0) {
2200 delete this.events[name];
2201 }
2202 }
2203 }
2204 };
2205
2206 /**
2207 * Remove a handler from an event
2208 *
2209 * @method off
2210 * @param name the event name
2211 * @param callback function to be called when the event is triggered
2212 * @param context this binding for executing the handler, defaults to the Emitter
2213 * @return connection object
2214 */
2215 Emitter.prototype.trigger = function (name) {
2216 var handlers = this.events[name];
2217
2218 if (handlers !== undefined) {
2219 var args = Array.prototype.slice.call(arguments, 1);
2220
2221 handlers.forEach(function (handler) {
2222 handler.code.apply(handler.context, args);
2223 });
2224 }
2225 };
2226
2227 Emitter.prototype.merge = function (emitter) {
2228 var lhs = this.events,
2229 rhs = emitter.events,
2230 push = Array.prototype.push,
2231 events;
2232
2233 for (var e in rhs) {
2234 events = lhs[e] = lhs[e] || [];
2235 push.apply(events, rhs[e]);
2236 }
2237 };
2238
2239 var pending = 'pending';
2240 var fulfilled = 'fulfilled';
2241 var broken = 'broken';
2242
2243 function callAsync(code, context, argument) {
2244 var async = function () {
2245 code.call(context, argument);
2246 };
2247 setTimeout(async);
2248 }
2249
2250 function Promise () {
2251 this.emitter = new Emitter();
2252 this.state = pending;
2253 this.result = null;
2254 }
2255
2256 Promise.prototype.resolve = function (result) {
2257 this.state = fulfilled;
2258 this.result = result;
2259
2260 this.emitter.trigger(fulfilled, result);
2261 };
2262
2263 Promise.prototype.reject = function (result) {
2264 this.state = broken;
2265 this.result = result;
2266
2267 this.emitter.trigger(broken, result);
2268 };
2269
2270 Promise.prototype.success = function (code, context) {
2271 if (this.state !== fulfilled) {
2272 this.emitter.on(fulfilled, code, context);
2273 } else {
2274 callAsync(code, context || this, this.result);
2275 }
2276 return this;
2277 };
2278
2279 Promise.prototype.always = function (code, context) {
2280 this.success(code, context);
2281 this.otherwise(code, context);
2282 return this;
2283 };
2284
2285 Promise.prototype.otherwise = function (code, context) {
2286 if (this.state !== broken) {
2287 this.emitter.on(broken, code, context);
2288 } else {
2289 callAsync(code, context || this, this.result);
2290 }
2291 return this;
2292 };
2293
2294 Promise.prototype.merge = function (other) {
2295 if (this.state === pending) {
2296 this.emitter.merge(other.emitter);
2297 } else {
2298 var handlers = other.emitter.events[this.state];
2299 var self = this;
2300 if (handlers !== undefined) {
2301 handlers.forEach(function (handler) {
2302 handler.code.call(handler.context, self.result);
2303 });
2304 }
2305 }
2306 };
2307
2308 Promise.prototype.make_chain = function (handler, promise, ok) {
2309 return function (result) {
2310 var handlerResult;
2311 try {
2312 handlerResult = handler.code.call(handler.context, result);
2313 if (handlerResult instanceof Promise) {
2314 handlerResult.merge(promise);
2315 } else if (this.state === ok) {
2316 promise.resolve(handlerResult);
2317 } else {
2318 promise.reject(handlerResult);
2319 }
2320 } catch (error) {
2321 promise.reject(error);
2322 }
2323 };
2324 };
2325
2326 function makeDefaultHandler(promise) {
2327 return function () {
2328 return promise;
2329 };
2330 }
2331
2332 Promise.prototype.then = function (callback, errback) {
2333 var promise = new Promise();
2334
2335 var handler = new Handler(callback || makeDefaultHandler(this), this);
2336
2337 this.success(this.make_chain(handler, promise, fulfilled), this);
2338
2339 var errorHandler = new Handler(errback || makeDefaultHandler(this), this);
2340 this.otherwise(this.make_chain(errorHandler, promise, broken), this);
2341
2342
2343 return promise;
2344 };
2345
2346 var isAttached = engine !== undefined;
2347
2348 engine = engine || {};
2349
2350 engine.events = {};
2351 for (var property in Emitter.prototype) {
2352 engine[property] = Emitter.prototype[property];
2353 }
2354
2355 /// @function engine.on
2356 /// Register handler for and event
2357 /// @param {String} name name of the event
2358 /// @param {Function} callback callback function to be executed when the event has been triggered
2359 /// @param context *this* context for the function, by default the engine object
2360
2361 /// @function engine.off
2362 /// Remove handler for an event
2363 /// @param {String} name name of the event, by default removes all events
2364 /// @param {Function} callback the callback function to be removed, by default removes all callbacks for a given event
2365 /// @param context *this* context for the function, by default all removes all callbacks, regardless of context
2366 /// @warning Removing all handlers for `engine` will remove some *Coherent UI* internal events, breaking some functionality.
2367
2368 /// @function engine.trigger
2369 /// Trigger an event
2370 /// This function will trigger any C++ handler registered for this event with `Coherent::UI::View::RegisterForEvent`
2371 /// @param {String} name name of the event
2372 /// @param ... any extra arguments to be passed to the event handlers
2373
2374 engine._trigger = Emitter.prototype.trigger;
2375 var concatArguments = Array.prototype.concat;
2376 engine.trigger = function (name) {
2377 this._trigger.apply(this, arguments);
2378 if (this._eventHandles[name] === undefined)
2379 {
2380 this.TriggerEvent.apply(this, arguments);
2381 }
2382 if (this.events['all'] !== undefined) {
2383 var allArguments = concatArguments.apply(['all'], arguments);
2384 this._trigger.apply(this, allArguments);
2385 }
2386 };
2387
2388 engine.IsAttached = isAttached;
2389 engine._BindingsReady = false;
2390 engine._WindowLoaded = false;
2391 engine._RequestId = Math.floor(Math.random() * Math.pow(2, 15) - 1) << 16;//AltspaceVR, start each frame's RequestId at a random number so that they don't collide
2392 engine._ActiveRequests = {};
2393
2394 // Begin AltspaceVR //
2395 // This enables the cascading of _Return events to lower iframes
2396 var iframes = document.getElementsByTagName('iframe');//This is a live NodeList
2397 function propagateToIFrames(event) {
2398 if (!window.Alt || !window.Alt.shouldSupportIFrames) return;
2399
2400 for (var i = 0, max = iframes.length; i < max; i++) {
2401 var iframe = iframes[i];
2402 iframe.contentWindow.postMessage(event, '*');
2403 }
2404 }
2405 window.addEventListener('message', function (event) {
2406 if (event.data.isAltspaceIFrameResult) {
2407 engine._Result.apply(engine, event.data.args);
2408 }
2409 });
2410 // End AltspaceVR //
2411
2412 if (!engine.IsAttached) {
2413 engine.SendMessage = function (name, id) {
2414 var args = Array.prototype.slice.call(arguments, 2);
2415 var deferred = engine._ActiveRequests[id];
2416
2417 delete engine._ActiveRequests[id];
2418
2419 args.push(deferred);
2420
2421 var call = (function (name, args) {
2422 return function () {
2423 var mock = engine['Mock_' + name];
2424
2425 if (mock !== undefined) {
2426 var callMock = function () {
2427 mock.apply(engine, args);
2428 };
2429 window.setTimeout(callMock, 16);
2430 }
2431 };
2432 }(name, args));
2433
2434 window.setTimeout(call, 16);
2435 };
2436
2437 engine.TriggerEvent = function () {
2438 var args = Array.prototype.slice.call(arguments),
2439 trigger;
2440
2441 args[0] = 'Fake_' + args[0];
2442
2443 trigger = (function (args) {
2444 return function () {
2445 engine.trigger.apply(engine, args);
2446 };
2447 }(args));
2448
2449 window.setTimeout(trigger, 16);
2450 };
2451
2452 engine.BindingsReady = function () {
2453 engine._OnReady();
2454 };
2455
2456 engine.__observeLifetime = function () {
2457 };
2458 }
2459
2460 /// @function engine.createDeferred
2461 /// Create a new deferred object.
2462 /// Use this to create deferred / promises that can be used together with `engine.call`.
2463 /// @return {Deferred} a new deferred object
2464 /// @see @ref CustomizingPromises
2465 engine.createDeferred = (global.engineCreateDeferred === undefined) ?
2466 function () { return new Promise(); }
2467 : global.engineCreateDeferred;
2468
2469 /// @function engine.call
2470 /// Call asynchronously a C++ handler and retrieve the result
2471 /// The C++ handler must have been registered with `Coherent::UI::View::BindCall`
2472 /// @param {String} name name of the C++ handler to be called
2473 /// @param ... any extra parameters to be passed to the C++ handler
2474 /// @return {Deferred} deferred object whose promise is resolved with the result of the C++ handler
2475 engine.call = function () {
2476 engine._RequestId++;
2477 var id = engine._RequestId;
2478
2479 var deferred = engine.createDeferred();
2480 engine._ActiveRequests[id] = deferred;
2481 var messageArguments = Array.prototype.slice.call(arguments);
2482 messageArguments.splice(1, 0, id);
2483
2484 engine.SendMessage.apply(this, messageArguments);
2485 return deferred;
2486 };
2487
2488 engine._Result = function (requestId) {
2489 var deferred = engine._ActiveRequests[requestId];
2490 if (deferred !== undefined)
2491 {
2492 delete engine._ActiveRequests[requestId];
2493
2494 var resultArguments = Array.prototype.slice.call(arguments);
2495 resultArguments.shift();
2496 deferred.resolve.apply(deferred, resultArguments);
2497 } else // AltspaceVR, propagate any returned calls that we don't recognize to lower iframes (since they probabably made the call).
2498 {
2499 propagateToIFrames({ isAltspaceIFrameResult: true, args: Array.prototype.slice.call(arguments) });
2500 }
2501 };
2502
2503 engine._Errors = [ 'Success', 'ArgumentType', 'NoSuchMethod', 'NoResult' ];
2504
2505 engine._ForEachError = function (errors, callback) {
2506 var length = errors.length;
2507
2508 for (var i = 0; i < length; ++i) {
2509 callback(errors[i].first, errors[i].second);
2510 }
2511 };
2512
2513 engine._MapErrors = function (errors) {
2514 var length = errors.length;
2515
2516 for (var i = 0; i < length; ++i) {
2517 errors[i].first = engine._Errors[errors[i].first];
2518 }
2519 };
2520
2521 engine._TriggerError = function (type, message) {
2522 engine.trigger('Error', type, message);
2523 };
2524
2525 engine._OnError = function (requestId, errors) {
2526 engine._MapErrors(errors);
2527
2528 if (requestId === null || requestId === 0) {
2529 engine._ForEachError(errors, engine._TriggerError);
2530 }
2531 else {
2532 var deferred = engine._ActiveRequests[requestId];
2533
2534 delete engine._ActiveRequests[requestId];
2535
2536 deferred.reject(errors);
2537 }
2538 };
2539
2540 engine._eventHandles = {};
2541
2542 engine._Register = function (eventName) {
2543 var trigger = (function (name, engine) {
2544 return function () {
2545 var eventArguments = [name];
2546 eventArguments.push.apply(eventArguments, arguments);
2547 engine.TriggerEvent.apply(this, eventArguments);
2548 };
2549 }(eventName, engine));
2550
2551 engine._eventHandles[eventName] = engine.on(eventName, trigger);
2552 };
2553
2554 engine._removeEventThunk = function (name) {
2555 var handle = engine._eventHandles[name];
2556 handle.clear();
2557 delete engine._eventHandles[name];
2558 };
2559
2560 engine._Unregister = function (name) {
2561 if (typeof name === 'string') {
2562 engine._removeEventThunk(name);
2563 } else {
2564 name.forEach(engine._removeEventThunk, engine);
2565 }
2566 };
2567
2568 function createMethodStub(name) {
2569 var stub = function() {
2570 var args = Array.prototype.slice.call(arguments);
2571 args.splice(0, 0, name, this._id);
2572 return engine.call.apply(engine, args);
2573 };
2574 return stub;
2575 }
2576
2577 engine._boundTypes = {};
2578
2579 engine._createInstance = function (args) {
2580 var type = args[0],
2581 id = args[1],
2582 methods = args[2],
2583 constructor = engine._boundTypes[type];
2584
2585 if (constructor === undefined) {
2586 constructor = function (id) {
2587 this._id = id;
2588 };
2589 constructor.prototype.__Type = type;
2590 methods.forEach(function (name) {
2591 constructor.prototype[name] = createMethodStub(type + '_' + name);
2592 });
2593 engine._boundTypes[type] = constructor;
2594 }
2595
2596 var instance = new constructor(id);
2597 engine.__observeLifetime(instance);
2598 return instance;
2599 }
2600
2601 engine._OnReady = function () {
2602 engine._BindingsReady = true;
2603 if (engine._WindowLoaded) {
2604 engine.trigger('Ready');
2605 }
2606 };
2607
2608 engine._OnWindowLoaded = function () {
2609 engine._WindowLoaded = true;
2610 if (engine._BindingsReady) {
2611 engine.trigger('Ready');
2612 }
2613 };
2614
2615 if (hasOnLoad) {
2616 global.onload = (function (originalWindowLoaded) {
2617 return function () {
2618 if (originalWindowLoaded) {
2619 originalWindowLoaded();
2620 }
2621 engine._OnWindowLoaded();
2622 };
2623 }(global.onload));
2624 } else {
2625 engine._WindowLoaded = true;
2626 }
2627
2628 engine._coherentGlobalCanvas = document.createElement('canvas');
2629 engine._coherentGlobalCanvas.id = "coherentGlobalCanvas";
2630 engine._coherentGlobalCanvas.width = 1;
2631 engine._coherentGlobalCanvas.height = 1;
2632 engine._coherentGlobalCanvas.style.zIndex = 0;
2633 engine._coherentGlobalCanvas.style.position = "absolute";
2634 engine._coherentGlobalCanvas.style.border = "0px solid";
2635
2636 engine._coherentLiveImageData = new Array();
2637 engine._coherentCreateImageData = function(name, guid) {
2638 var ctx = engine._coherentGlobalCanvas.getContext("2d");
2639
2640 var coherentImage = ctx.coherentCreateImageData(guid);
2641 engine._coherentLiveImageData[name] = coherentImage;
2642 }
2643 engine._coherentUpdatedImageData = function(name) {
2644 engine._coherentLiveImageData[name].coherentUpdate();
2645 var canvases = document.getElementsByTagName('canvas');
2646 for(var i = 0; i < canvases.length; ++i) {
2647 if(canvases[i].onEngineImageDataUpdated != null) {
2648 canvases[i].onEngineImageDataUpdated(name,
2649 engine._coherentLiveImageData[name]);
2650 }
2651 }
2652 }
2653
2654 engine.on("_coherentCreateImageData", engine._coherentCreateImageData);
2655 engine.on("_coherentUpdatedImageData", engine._coherentUpdatedImageData);
2656
2657 engine.on('_Result', engine._Result, engine);
2658 engine.on('_Register', engine._Register, engine);
2659 engine.on('_Unregister', engine._Unregister, engine);
2660 engine.on('_OnReady', engine._OnReady, engine);
2661 engine.on('_OnError', engine._OnError, engine);
2662
2663 engine.BindingsReady();
2664
2665 return engine;
2666});
2667
2668
2669// Underscore.js 1.6.0
2670// http://underscorejs.org
2671// (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
2672// Underscore may be freely distributed under the MIT license.
2673
2674(function() {
2675
2676 // Baseline setup
2677 // --------------
2678
2679 // Establish the root object, `window` in the browser, or `exports` on the server.
2680 var root = this;
2681
2682 // Save the previous value of the `_` variable.
2683 var previousUnderscore = root._;
2684
2685 // Establish the object that gets returned to break out of a loop iteration.
2686 var breaker = {};
2687
2688 // Save bytes in the minified (but not gzipped) version:
2689 var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
2690
2691 // Create quick reference variables for speed access to core prototypes.
2692 var
2693 push = ArrayProto.push,
2694 slice = ArrayProto.slice,
2695 concat = ArrayProto.concat,
2696 toString = ObjProto.toString,
2697 hasOwnProperty = ObjProto.hasOwnProperty;
2698
2699 // All **ECMAScript 5** native function implementations that we hope to use
2700 // are declared here.
2701 var
2702 nativeForEach = ArrayProto.forEach,
2703 nativeMap = ArrayProto.map,
2704 nativeReduce = ArrayProto.reduce,
2705 nativeReduceRight = ArrayProto.reduceRight,
2706 nativeFilter = ArrayProto.filter,
2707 nativeEvery = ArrayProto.every,
2708 nativeSome = ArrayProto.some,
2709 nativeIndexOf = ArrayProto.indexOf,
2710 nativeLastIndexOf = ArrayProto.lastIndexOf,
2711 nativeIsArray = Array.isArray,
2712 nativeKeys = Object.keys,
2713 nativeBind = FuncProto.bind;
2714
2715 // Create a safe reference to the Underscore object for use below.
2716 var _ = function(obj) {
2717 if (obj instanceof _) return obj;
2718 if (!(this instanceof _)) return new _(obj);
2719 this._wrapped = obj;
2720 };
2721
2722 // Export the Underscore object for **Node.js**, with
2723 // backwards-compatibility for the old `require()` API. If we're in
2724 // the browser, add `_` as a global object via a string identifier,
2725 // for Closure Compiler "advanced" mode.
2726 if (typeof exports !== 'undefined') {
2727 if (typeof module !== 'undefined' && module.exports) {
2728 exports = module.exports = _;
2729 }
2730 exports._ = _;
2731 } else {
2732 root._ = _;
2733 }
2734
2735 // Current version.
2736 _.VERSION = '1.6.0';
2737
2738 // Collection Functions
2739 // --------------------
2740
2741 // The cornerstone, an `each` implementation, aka `forEach`.
2742 // Handles objects with the built-in `forEach`, arrays, and raw objects.
2743 // Delegates to **ECMAScript 5**'s native `forEach` if available.
2744 var each = _.each = _.forEach = function(obj, iterator, context) {
2745 if (obj == null) return obj;
2746 if (nativeForEach && obj.forEach === nativeForEach) {
2747 obj.forEach(iterator, context);
2748 } else if (obj.length === +obj.length) {
2749 for (var i = 0, length = obj.length; i < length; i++) {
2750 if (iterator.call(context, obj[i], i, obj) === breaker) return;
2751 }
2752 } else {
2753 var keys = _.keys(obj);
2754 for (var i = 0, length = keys.length; i < length; i++) {
2755 if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return;
2756 }
2757 }
2758 return obj;
2759 };
2760
2761 // Return the results of applying the iterator to each element.
2762 // Delegates to **ECMAScript 5**'s native `map` if available.
2763 _.map = _.collect = function(obj, iterator, context) {
2764 var results = [];
2765 if (obj == null) return results;
2766 if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
2767 each(obj, function(value, index, list) {
2768 results.push(iterator.call(context, value, index, list));
2769 });
2770 return results;
2771 };
2772
2773 var reduceError = 'Reduce of empty array with no initial value';
2774
2775 // **Reduce** builds up a single result from a list of values, aka `inject`,
2776 // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
2777 _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
2778 var initial = arguments.length > 2;
2779 if (obj == null) obj = [];
2780 if (nativeReduce && obj.reduce === nativeReduce) {
2781 if (context) iterator = _.bind(iterator, context);
2782 return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
2783 }
2784 each(obj, function(value, index, list) {
2785 if (!initial) {
2786 memo = value;
2787 initial = true;
2788 } else {
2789 memo = iterator.call(context, memo, value, index, list);
2790 }
2791 });
2792 if (!initial) throw new TypeError(reduceError);
2793 return memo;
2794 };
2795
2796 // The right-associative version of reduce, also known as `foldr`.
2797 // Delegates to **ECMAScript 5**'s native `reduceRight` if available.
2798 _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
2799 var initial = arguments.length > 2;
2800 if (obj == null) obj = [];
2801 if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
2802 if (context) iterator = _.bind(iterator, context);
2803 return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
2804 }
2805 var length = obj.length;
2806 if (length !== +length) {
2807 var keys = _.keys(obj);
2808 length = keys.length;
2809 }
2810 each(obj, function(value, index, list) {
2811 index = keys ? keys[--length] : --length;
2812 if (!initial) {
2813 memo = obj[index];
2814 initial = true;
2815 } else {
2816 memo = iterator.call(context, memo, obj[index], index, list);
2817 }
2818 });
2819 if (!initial) throw new TypeError(reduceError);
2820 return memo;
2821 };
2822
2823 // Return the first value which passes a truth test. Aliased as `detect`.
2824 _.find = _.detect = function(obj, predicate, context) {
2825 var result;
2826 any(obj, function(value, index, list) {
2827 if (predicate.call(context, value, index, list)) {
2828 result = value;
2829 return true;
2830 }
2831 });
2832 return result;
2833 };
2834
2835 // Return all the elements that pass a truth test.
2836 // Delegates to **ECMAScript 5**'s native `filter` if available.
2837 // Aliased as `select`.
2838 _.filter = _.select = function(obj, predicate, context) {
2839 var results = [];
2840 if (obj == null) return results;
2841 if (nativeFilter && obj.filter === nativeFilter) return obj.filter(predicate, context);
2842 each(obj, function(value, index, list) {
2843 if (predicate.call(context, value, index, list)) results.push(value);
2844 });
2845 return results;
2846 };
2847
2848 // Return all the elements for which a truth test fails.
2849 _.reject = function(obj, predicate, context) {
2850 return _.filter(obj, function(value, index, list) {
2851 return !predicate.call(context, value, index, list);
2852 }, context);
2853 };
2854
2855 // Determine whether all of the elements match a truth test.
2856 // Delegates to **ECMAScript 5**'s native `every` if available.
2857 // Aliased as `all`.
2858 _.every = _.all = function(obj, predicate, context) {
2859 predicate || (predicate = _.identity);
2860 var result = true;
2861 if (obj == null) return result;
2862 if (nativeEvery && obj.every === nativeEvery) return obj.every(predicate, context);
2863 each(obj, function(value, index, list) {
2864 if (!(result = result && predicate.call(context, value, index, list))) return breaker;
2865 });
2866 return !!result;
2867 };
2868
2869 // Determine if at least one element in the object matches a truth test.
2870 // Delegates to **ECMAScript 5**'s native `some` if available.
2871 // Aliased as `any`.
2872 var any = _.some = _.any = function(obj, predicate, context) {
2873 predicate || (predicate = _.identity);
2874 var result = false;
2875 if (obj == null) return result;
2876 if (nativeSome && obj.some === nativeSome) return obj.some(predicate, context);
2877 each(obj, function(value, index, list) {
2878 if (result || (result = predicate.call(context, value, index, list))) return breaker;
2879 });
2880 return !!result;
2881 };
2882
2883 // Determine if the array or object contains a given value (using `===`).
2884 // Aliased as `include`.
2885 _.contains = _.include = function(obj, target) {
2886 if (obj == null) return false;
2887 if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
2888 return any(obj, function(value) {
2889 return value === target;
2890 });
2891 };
2892
2893 // Invoke a method (with arguments) on every item in a collection.
2894 _.invoke = function(obj, method) {
2895 var args = slice.call(arguments, 2);
2896 var isFunc = _.isFunction(method);
2897 return _.map(obj, function(value) {
2898 return (isFunc ? method : value[method]).apply(value, args);
2899 });
2900 };
2901
2902 // Convenience version of a common use case of `map`: fetching a property.
2903 _.pluck = function(obj, key) {
2904 return _.map(obj, _.property(key));
2905 };
2906
2907 // Convenience version of a common use case of `filter`: selecting only objects
2908 // containing specific `key:value` pairs.
2909 _.where = function(obj, attrs) {
2910 return _.filter(obj, _.matches(attrs));
2911 };
2912
2913 // Convenience version of a common use case of `find`: getting the first object
2914 // containing specific `key:value` pairs.
2915 _.findWhere = function(obj, attrs) {
2916 return _.find(obj, _.matches(attrs));
2917 };
2918
2919 // Return the maximum element or (element-based computation).
2920 // Can't optimize arrays of integers longer than 65,535 elements.
2921 // See [WebKit Bug 80797](https://bugs.webkit.org/show_bug.cgi?id=80797)
2922 _.max = function(obj, iterator, context) {
2923 if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
2924 return Math.max.apply(Math, obj);
2925 }
2926 var result = -Infinity, lastComputed = -Infinity;
2927 each(obj, function(value, index, list) {
2928 var computed = iterator ? iterator.call(context, value, index, list) : value;
2929 if (computed > lastComputed) {
2930 result = value;
2931 lastComputed = computed;
2932 }
2933 });
2934 return result;
2935 };
2936
2937 // Return the minimum element (or element-based computation).
2938 _.min = function(obj, iterator, context) {
2939 if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
2940 return Math.min.apply(Math, obj);
2941 }
2942 var result = Infinity, lastComputed = Infinity;
2943 each(obj, function(value, index, list) {
2944 var computed = iterator ? iterator.call(context, value, index, list) : value;
2945 if (computed < lastComputed) {
2946 result = value;
2947 lastComputed = computed;
2948 }
2949 });
2950 return result;
2951 };
2952
2953 // Shuffle an array, using the modern version of the
2954 // [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
2955 _.shuffle = function(obj) {
2956 var rand;
2957 var index = 0;
2958 var shuffled = [];
2959 each(obj, function(value) {
2960 rand = _.random(index++);
2961 shuffled[index - 1] = shuffled[rand];
2962 shuffled[rand] = value;
2963 });
2964 return shuffled;
2965 };
2966
2967 // Sample **n** random values from a collection.
2968 // If **n** is not specified, returns a single random element.
2969 // The internal `guard` argument allows it to work with `map`.
2970 _.sample = function(obj, n, guard) {
2971 if (n == null || guard) {
2972 if (obj.length !== +obj.length) obj = _.values(obj);
2973 return obj[_.random(obj.length - 1)];
2974 }
2975 return _.shuffle(obj).slice(0, Math.max(0, n));
2976 };
2977
2978 // An internal function to generate lookup iterators.
2979 var lookupIterator = function(value) {
2980 if (value == null) return _.identity;
2981 if (_.isFunction(value)) return value;
2982 return _.property(value);
2983 };
2984
2985 // Sort the object's values by a criterion produced by an iterator.
2986 _.sortBy = function(obj, iterator, context) {
2987 iterator = lookupIterator(iterator);
2988 return _.pluck(_.map(obj, function(value, index, list) {
2989 return {
2990 value: value,
2991 index: index,
2992 criteria: iterator.call(context, value, index, list)
2993 };
2994 }).sort(function(left, right) {
2995 var a = left.criteria;
2996 var b = right.criteria;
2997 if (a !== b) {
2998 if (a > b || a === void 0) return 1;
2999 if (a < b || b === void 0) return -1;
3000 }
3001 return left.index - right.index;
3002 }), 'value');
3003 };
3004
3005 // An internal function used for aggregate "group by" operations.
3006 var group = function(behavior) {
3007 return function(obj, iterator, context) {
3008 var result = {};
3009 iterator = lookupIterator(iterator);
3010 each(obj, function(value, index) {
3011 var key = iterator.call(context, value, index, obj);
3012 behavior(result, key, value);
3013 });
3014 return result;
3015 };
3016 };
3017
3018 // Groups the object's values by a criterion. Pass either a string attribute
3019 // to group by, or a function that returns the criterion.
3020 _.groupBy = group(function(result, key, value) {
3021 _.has(result, key) ? result[key].push(value) : result[key] = [value];
3022 });
3023
3024 // Indexes the object's values by a criterion, similar to `groupBy`, but for
3025 // when you know that your index values will be unique.
3026 _.indexBy = group(function(result, key, value) {
3027 result[key] = value;
3028 });
3029
3030 // Counts instances of an object that group by a certain criterion. Pass
3031 // either a string attribute to count by, or a function that returns the
3032 // criterion.
3033 _.countBy = group(function(result, key) {
3034 _.has(result, key) ? result[key]++ : result[key] = 1;
3035 });
3036
3037 // Use a comparator function to figure out the smallest index at which
3038 // an object should be inserted so as to maintain order. Uses binary search.
3039 _.sortedIndex = function(array, obj, iterator, context) {
3040 iterator = lookupIterator(iterator);
3041 var value = iterator.call(context, obj);
3042 var low = 0, high = array.length;
3043 while (low < high) {
3044 var mid = (low + high) >>> 1;
3045 iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid;
3046 }
3047 return low;
3048 };
3049
3050 // Safely create a real, live array from anything iterable.
3051 _.toArray = function(obj) {
3052 if (!obj) return [];
3053 if (_.isArray(obj)) return slice.call(obj);
3054 if (obj.length === +obj.length) return _.map(obj, _.identity);
3055 return _.values(obj);
3056 };
3057
3058 // Return the number of elements in an object.
3059 _.size = function(obj) {
3060 if (obj == null) return 0;
3061 return (obj.length === +obj.length) ? obj.length : _.keys(obj).length;
3062 };
3063
3064 // Array Functions
3065 // ---------------
3066
3067 // Get the first element of an array. Passing **n** will return the first N
3068 // values in the array. Aliased as `head` and `take`. The **guard** check
3069 // allows it to work with `_.map`.
3070 _.first = _.head = _.take = function(array, n, guard) {
3071 if (array == null) return void 0;
3072 if ((n == null) || guard) return array[0];
3073 if (n < 0) return [];
3074 return slice.call(array, 0, n);
3075 };
3076
3077 // Returns everything but the last entry of the array. Especially useful on
3078 // the arguments object. Passing **n** will return all the values in
3079 // the array, excluding the last N. The **guard** check allows it to work with
3080 // `_.map`.
3081 _.initial = function(array, n, guard) {
3082 return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
3083 };
3084
3085 // Get the last element of an array. Passing **n** will return the last N
3086 // values in the array. The **guard** check allows it to work with `_.map`.
3087 _.last = function(array, n, guard) {
3088 if (array == null) return void 0;
3089 if ((n == null) || guard) return array[array.length - 1];
3090 return slice.call(array, Math.max(array.length - n, 0));
3091 };
3092
3093 // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
3094 // Especially useful on the arguments object. Passing an **n** will return
3095 // the rest N values in the array. The **guard**
3096 // check allows it to work with `_.map`.
3097 _.rest = _.tail = _.drop = function(array, n, guard) {
3098 return slice.call(array, (n == null) || guard ? 1 : n);
3099 };
3100
3101 // Trim out all falsy values from an array.
3102 _.compact = function(array) {
3103 return _.filter(array, _.identity);
3104 };
3105
3106 // Internal implementation of a recursive `flatten` function.
3107 var flatten = function(input, shallow, output) {
3108 if (shallow && _.every(input, _.isArray)) {
3109 return concat.apply(output, input);
3110 }
3111 each(input, function(value) {
3112 if (_.isArray(value) || _.isArguments(value)) {
3113 shallow ? push.apply(output, value) : flatten(value, shallow, output);
3114 } else {
3115 output.push(value);
3116 }
3117 });
3118 return output;
3119 };
3120
3121 // Flatten out an array, either recursively (by default), or just one level.
3122 _.flatten = function(array, shallow) {
3123 return flatten(array, shallow, []);
3124 };
3125
3126 // Return a version of the array that does not contain the specified value(s).
3127 _.without = function(array) {
3128 return _.difference(array, slice.call(arguments, 1));
3129 };
3130
3131 // Split an array into two arrays: one whose elements all satisfy the given
3132 // predicate, and one whose elements all do not satisfy the predicate.
3133 _.partition = function(array, predicate) {
3134 var pass = [], fail = [];
3135 each(array, function(elem) {
3136 (predicate(elem) ? pass : fail).push(elem);
3137 });
3138 return [pass, fail];
3139 };
3140
3141 // Produce a duplicate-free version of the array. If the array has already
3142 // been sorted, you have the option of using a faster algorithm.
3143 // Aliased as `unique`.
3144 _.uniq = _.unique = function(array, isSorted, iterator, context) {
3145 if (_.isFunction(isSorted)) {
3146 context = iterator;
3147 iterator = isSorted;
3148 isSorted = false;
3149 }
3150 var initial = iterator ? _.map(array, iterator, context) : array;
3151 var results = [];
3152 var seen = [];
3153 each(initial, function(value, index) {
3154 if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) {
3155 seen.push(value);
3156 results.push(array[index]);
3157 }
3158 });
3159 return results;
3160 };
3161
3162 // Produce an array that contains the union: each distinct element from all of
3163 // the passed-in arrays.
3164 _.union = function() {
3165 return _.uniq(_.flatten(arguments, true));
3166 };
3167
3168 // Produce an array that contains every item shared between all the
3169 // passed-in arrays.
3170 _.intersection = function(array) {
3171 var rest = slice.call(arguments, 1);
3172 return _.filter(_.uniq(array), function(item) {
3173 return _.every(rest, function(other) {
3174 return _.contains(other, item);
3175 });
3176 });
3177 };
3178
3179 // Take the difference between one array and a number of other arrays.
3180 // Only the elements present in just the first array will remain.
3181 _.difference = function(array) {
3182 var rest = concat.apply(ArrayProto, slice.call(arguments, 1));
3183 return _.filter(array, function(value){ return !_.contains(rest, value); });
3184 };
3185
3186 // Zip together multiple lists into a single array -- elements that share
3187 // an index go together.
3188 _.zip = function() {
3189 var length = _.max(_.pluck(arguments, 'length').concat(0));
3190 var results = new Array(length);
3191 for (var i = 0; i < length; i++) {
3192 results[i] = _.pluck(arguments, '' + i);
3193 }
3194 return results;
3195 };
3196
3197 // Converts lists into objects. Pass either a single array of `[key, value]`
3198 // pairs, or two parallel arrays of the same length -- one of keys, and one of
3199 // the corresponding values.
3200 _.object = function(list, values) {
3201 if (list == null) return {};
3202 var result = {};
3203 for (var i = 0, length = list.length; i < length; i++) {
3204 if (values) {
3205 result[list[i]] = values[i];
3206 } else {
3207 result[list[i][0]] = list[i][1];
3208 }
3209 }
3210 return result;
3211 };
3212
3213 // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
3214 // we need this function. Return the position of the first occurrence of an
3215 // item in an array, or -1 if the item is not included in the array.
3216 // Delegates to **ECMAScript 5**'s native `indexOf` if available.
3217 // If the array is large and already in sort order, pass `true`
3218 // for **isSorted** to use binary search.
3219 _.indexOf = function(array, item, isSorted) {
3220 if (array == null) return -1;
3221 var i = 0, length = array.length;
3222 if (isSorted) {
3223 if (typeof isSorted == 'number') {
3224 i = (isSorted < 0 ? Math.max(0, length + isSorted) : isSorted);
3225 } else {
3226 i = _.sortedIndex(array, item);
3227 return array[i] === item ? i : -1;
3228 }
3229 }
3230 if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
3231 for (; i < length; i++) if (array[i] === item) return i;
3232 return -1;
3233 };
3234
3235 // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
3236 _.lastIndexOf = function(array, item, from) {
3237 if (array == null) return -1;
3238 var hasIndex = from != null;
3239 if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) {
3240 return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item);
3241 }
3242 var i = (hasIndex ? from : array.length);
3243 while (i--) if (array[i] === item) return i;
3244 return -1;
3245 };
3246
3247 // Generate an integer Array containing an arithmetic progression. A port of
3248 // the native Python `range()` function. See
3249 // [the Python documentation](http://docs.python.org/library/functions.html#range).
3250 _.range = function(start, stop, step) {
3251 if (arguments.length <= 1) {
3252 stop = start || 0;
3253 start = 0;
3254 }
3255 step = arguments[2] || 1;
3256
3257 var length = Math.max(Math.ceil((stop - start) / step), 0);
3258 var idx = 0;
3259 var range = new Array(length);
3260
3261 while(idx < length) {
3262 range[idx++] = start;
3263 start += step;
3264 }
3265
3266 return range;
3267 };
3268
3269 // Function (ahem) Functions
3270 // ------------------
3271
3272 // Reusable constructor function for prototype setting.
3273 var ctor = function(){};
3274
3275 // Create a function bound to a given object (assigning `this`, and arguments,
3276 // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
3277 // available.
3278 _.bind = function(func, context) {
3279 var args, bound;
3280 if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
3281 if (!_.isFunction(func)) throw new TypeError;
3282 args = slice.call(arguments, 2);
3283 return bound = function() {
3284 if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
3285 ctor.prototype = func.prototype;
3286 var self = new ctor;
3287 ctor.prototype = null;
3288 var result = func.apply(self, args.concat(slice.call(arguments)));
3289 if (Object(result) === result) return result;
3290 return self;
3291 };
3292 };
3293
3294 // Partially apply a function by creating a version that has had some of its
3295 // arguments pre-filled, without changing its dynamic `this` context. _ acts
3296 // as a placeholder, allowing any combination of arguments to be pre-filled.
3297 _.partial = function(func) {
3298 var boundArgs = slice.call(arguments, 1);
3299 return function() {
3300 var position = 0;
3301 var args = boundArgs.slice();
3302 for (var i = 0, length = args.length; i < length; i++) {
3303 if (args[i] === _) args[i] = arguments[position++];
3304 }
3305 while (position < arguments.length) args.push(arguments[position++]);
3306 return func.apply(this, args);
3307 };
3308 };
3309
3310 // Bind a number of an object's methods to that object. Remaining arguments
3311 // are the method names to be bound. Useful for ensuring that all callbacks
3312 // defined on an object belong to it.
3313 _.bindAll = function(obj) {
3314 var funcs = slice.call(arguments, 1);
3315 if (funcs.length === 0) throw new Error('bindAll must be passed function names');
3316 each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
3317 return obj;
3318 };
3319
3320 // Memoize an expensive function by storing its results.
3321 _.memoize = function(func, hasher) {
3322 var memo = {};
3323 hasher || (hasher = _.identity);
3324 return function() {
3325 var key = hasher.apply(this, arguments);
3326 return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
3327 };
3328 };
3329
3330 // Delays a function for the given number of milliseconds, and then calls
3331 // it with the arguments supplied.
3332 _.delay = function(func, wait) {
3333 var args = slice.call(arguments, 2);
3334 return setTimeout(function(){ return func.apply(null, args); }, wait);
3335 };
3336
3337 // Defers a function, scheduling it to run after the current call stack has
3338 // cleared.
3339 _.defer = function(func) {
3340 return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
3341 };
3342
3343 // Returns a function, that, when invoked, will only be triggered at most once
3344 // during a given window of time. Normally, the throttled function will run
3345 // as much as it can, without ever going more than once per `wait` duration;
3346 // but if you'd like to disable the execution on the leading edge, pass
3347 // `{leading: false}`. To disable execution on the trailing edge, ditto.
3348 _.throttle = function(func, wait, options) {
3349 var context, args, result;
3350 var timeout = null;
3351 var previous = 0;
3352 options || (options = {});
3353 var later = function() {
3354 previous = options.leading === false ? 0 : _.now();
3355 timeout = null;
3356 result = func.apply(context, args);
3357 context = args = null;
3358 };
3359 return function() {
3360 var now = _.now();
3361 if (!previous && options.leading === false) previous = now;
3362 var remaining = wait - (now - previous);
3363 context = this;
3364 args = arguments;
3365 if (remaining <= 0) {
3366 clearTimeout(timeout);
3367 timeout = null;
3368 previous = now;
3369 result = func.apply(context, args);
3370 context = args = null;
3371 } else if (!timeout && options.trailing !== false) {
3372 timeout = setTimeout(later, remaining);
3373 }
3374 return result;
3375 };
3376 };
3377
3378 // Returns a function, that, as long as it continues to be invoked, will not
3379 // be triggered. The function will be called after it stops being called for
3380 // N milliseconds. If `immediate` is passed, trigger the function on the
3381 // leading edge, instead of the trailing.
3382 _.debounce = function(func, wait, immediate) {
3383 var timeout, args, context, timestamp, result;
3384
3385 var later = function() {
3386 var last = _.now() - timestamp;
3387 if (last < wait) {
3388 timeout = setTimeout(later, wait - last);
3389 } else {
3390 timeout = null;
3391 if (!immediate) {
3392 result = func.apply(context, args);
3393 context = args = null;
3394 }
3395 }
3396 };
3397
3398 return function() {
3399 context = this;
3400 args = arguments;
3401 timestamp = _.now();
3402 var callNow = immediate && !timeout;
3403 if (!timeout) {
3404 timeout = setTimeout(later, wait);
3405 }
3406 if (callNow) {
3407 result = func.apply(context, args);
3408 context = args = null;
3409 }
3410
3411 return result;
3412 };
3413 };
3414
3415 // Returns a function that will be executed at most one time, no matter how
3416 // often you call it. Useful for lazy initialization.
3417 _.once = function(func) {
3418 var ran = false, memo;
3419 return function() {
3420 if (ran) return memo;
3421 ran = true;
3422 memo = func.apply(this, arguments);
3423 func = null;
3424 return memo;
3425 };
3426 };
3427
3428 // Returns the first function passed as an argument to the second,
3429 // allowing you to adjust arguments, run code before and after, and
3430 // conditionally execute the original function.
3431 _.wrap = function(func, wrapper) {
3432 return _.partial(wrapper, func);
3433 };
3434
3435 // Returns a function that is the composition of a list of functions, each
3436 // consuming the return value of the function that follows.
3437 _.compose = function() {
3438 var funcs = arguments;
3439 return function() {
3440 var args = arguments;
3441 for (var i = funcs.length - 1; i >= 0; i--) {
3442 args = [funcs[i].apply(this, args)];
3443 }
3444 return args[0];
3445 };
3446 };
3447
3448 // Returns a function that will only be executed after being called N times.
3449 _.after = function(times, func) {
3450 return function() {
3451 if (--times < 1) {
3452 return func.apply(this, arguments);
3453 }
3454 };
3455 };
3456
3457 // Object Functions
3458 // ----------------
3459
3460 // Retrieve the names of an object's properties.
3461 // Delegates to **ECMAScript 5**'s native `Object.keys`
3462 _.keys = function(obj) {
3463 if (!_.isObject(obj)) return [];
3464 if (nativeKeys) return nativeKeys(obj);
3465 var keys = [];
3466 for (var key in obj) if (_.has(obj, key)) keys.push(key);
3467 return keys;
3468 };
3469
3470 // Retrieve the values of an object's properties.
3471 _.values = function(obj) {
3472 var keys = _.keys(obj);
3473 var length = keys.length;
3474 var values = new Array(length);
3475 for (var i = 0; i < length; i++) {
3476 values[i] = obj[keys[i]];
3477 }
3478 return values;
3479 };
3480
3481 // Convert an object into a list of `[key, value]` pairs.
3482 _.pairs = function(obj) {
3483 var keys = _.keys(obj);
3484 var length = keys.length;
3485 var pairs = new Array(length);
3486 for (var i = 0; i < length; i++) {
3487 pairs[i] = [keys[i], obj[keys[i]]];
3488 }
3489 return pairs;
3490 };
3491
3492 // Invert the keys and values of an object. The values must be serializable.
3493 _.invert = function(obj) {
3494 var result = {};
3495 var keys = _.keys(obj);
3496 for (var i = 0, length = keys.length; i < length; i++) {
3497 result[obj[keys[i]]] = keys[i];
3498 }
3499 return result;
3500 };
3501
3502 // Return a sorted list of the function names available on the object.
3503 // Aliased as `methods`
3504 _.functions = _.methods = function(obj) {
3505 var names = [];
3506 for (var key in obj) {
3507 if (_.isFunction(obj[key])) names.push(key);
3508 }
3509 return names.sort();
3510 };
3511
3512 // Extend a given object with all the properties in passed-in object(s).
3513 _.extend = function(obj) {
3514 each(slice.call(arguments, 1), function(source) {
3515 if (source) {
3516 for (var prop in source) {
3517 obj[prop] = source[prop];
3518 }
3519 }
3520 });
3521 return obj;
3522 };
3523
3524 // Return a copy of the object only containing the whitelisted properties.
3525 _.pick = function(obj) {
3526 var copy = {};
3527 var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
3528 each(keys, function(key) {
3529 if (key in obj) copy[key] = obj[key];
3530 });
3531 return copy;
3532 };
3533
3534 // Return a copy of the object without the blacklisted properties.
3535 _.omit = function(obj) {
3536 var copy = {};
3537 var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
3538 for (var key in obj) {
3539 if (!_.contains(keys, key)) copy[key] = obj[key];
3540 }
3541 return copy;
3542 };
3543
3544 // Fill in a given object with default properties.
3545 _.defaults = function(obj) {
3546 each(slice.call(arguments, 1), function(source) {
3547 if (source) {
3548 for (var prop in source) {
3549 if (obj[prop] === void 0) obj[prop] = source[prop];
3550 }
3551 }
3552 });
3553 return obj;
3554 };
3555
3556 // Create a (shallow-cloned) duplicate of an object.
3557 _.clone = function(obj) {
3558 if (!_.isObject(obj)) return obj;
3559 return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
3560 };
3561
3562 // Invokes interceptor with the obj, and then returns obj.
3563 // The primary purpose of this method is to "tap into" a method chain, in
3564 // order to perform operations on intermediate results within the chain.
3565 _.tap = function(obj, interceptor) {
3566 interceptor(obj);
3567 return obj;
3568 };
3569
3570 // Internal recursive comparison function for `isEqual`.
3571 var eq = function(a, b, aStack, bStack) {
3572 // Identical objects are equal. `0 === -0`, but they aren't identical.
3573 // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
3574 if (a === b) return a !== 0 || 1 / a == 1 / b;
3575 // A strict comparison is necessary because `null == undefined`.
3576 if (a == null || b == null) return a === b;
3577 // Unwrap any wrapped objects.
3578 if (a instanceof _) a = a._wrapped;
3579 if (b instanceof _) b = b._wrapped;
3580 // Compare `[[Class]]` names.
3581 var className = toString.call(a);
3582 if (className != toString.call(b)) return false;
3583 switch (className) {
3584 // Strings, numbers, dates, and booleans are compared by value.
3585 case '[object String]':
3586 // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
3587 // equivalent to `new String("5")`.
3588 return a == String(b);
3589 case '[object Number]':
3590 // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
3591 // other numeric values.
3592 return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
3593 case '[object Date]':
3594 case '[object Boolean]':
3595 // Coerce dates and booleans to numeric primitive values. Dates are compared by their
3596 // millisecond representations. Note that invalid dates with millisecond representations
3597 // of `NaN` are not equivalent.
3598 return +a == +b;
3599 // RegExps are compared by their source patterns and flags.
3600 case '[object RegExp]':
3601 return a.source == b.source &&
3602 a.global == b.global &&
3603 a.multiline == b.multiline &&
3604 a.ignoreCase == b.ignoreCase;
3605 }
3606 if (typeof a != 'object' || typeof b != 'object') return false;
3607 // Assume equality for cyclic structures. The algorithm for detecting cyclic
3608 // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
3609 var length = aStack.length;
3610 while (length--) {
3611 // Linear search. Performance is inversely proportional to the number of
3612 // unique nested structures.
3613 if (aStack[length] == a) return bStack[length] == b;
3614 }
3615 // Objects with different constructors are not equivalent, but `Object`s
3616 // from different frames are.
3617 var aCtor = a.constructor, bCtor = b.constructor;
3618 if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
3619 _.isFunction(bCtor) && (bCtor instanceof bCtor))
3620 && ('constructor' in a && 'constructor' in b)) {
3621 return false;
3622 }
3623 // Add the first object to the stack of traversed objects.
3624 aStack.push(a);
3625 bStack.push(b);
3626 var size = 0, result = true;
3627 // Recursively compare objects and arrays.
3628 if (className == '[object Array]') {
3629 // Compare array lengths to determine if a deep comparison is necessary.
3630 size = a.length;
3631 result = size == b.length;
3632 if (result) {
3633 // Deep compare the contents, ignoring non-numeric properties.
3634 while (size--) {
3635 if (!(result = eq(a[size], b[size], aStack, bStack))) break;
3636 }
3637 }
3638 } else {
3639 // Deep compare objects.
3640 for (var key in a) {
3641 if (_.has(a, key)) {
3642 // Count the expected number of properties.
3643 size++;
3644 // Deep compare each member.
3645 if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
3646 }
3647 }
3648 // Ensure that both objects contain the same number of properties.
3649 if (result) {
3650 for (key in b) {
3651 if (_.has(b, key) && !(size--)) break;
3652 }
3653 result = !size;
3654 }
3655 }
3656 // Remove the first object from the stack of traversed objects.
3657 aStack.pop();
3658 bStack.pop();
3659 return result;
3660 };
3661
3662 // Perform a deep comparison to check if two objects are equal.
3663 _.isEqual = function(a, b) {
3664 return eq(a, b, [], []);
3665 };
3666
3667 // Is a given array, string, or object empty?
3668 // An "empty" object has no enumerable own-properties.
3669 _.isEmpty = function(obj) {
3670 if (obj == null) return true;
3671 if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
3672 for (var key in obj) if (_.has(obj, key)) return false;
3673 return true;
3674 };
3675
3676 // Is a given value a DOM element?
3677 _.isElement = function(obj) {
3678 return !!(obj && obj.nodeType === 1);
3679 };
3680
3681 // Is a given value an array?
3682 // Delegates to ECMA5's native Array.isArray
3683 _.isArray = nativeIsArray || function(obj) {
3684 return toString.call(obj) == '[object Array]';
3685 };
3686
3687 // Is a given variable an object?
3688 _.isObject = function(obj) {
3689 return obj === Object(obj);
3690 };
3691
3692 // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
3693 each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
3694 _['is' + name] = function(obj) {
3695 return toString.call(obj) == '[object ' + name + ']';
3696 };
3697 });
3698
3699 // Define a fallback version of the method in browsers (ahem, IE), where
3700 // there isn't any inspectable "Arguments" type.
3701 if (!_.isArguments(arguments)) {
3702 _.isArguments = function(obj) {
3703 return !!(obj && _.has(obj, 'callee'));
3704 };
3705 }
3706
3707 // Optimize `isFunction` if appropriate.
3708 if (typeof (/./) !== 'function') {
3709 _.isFunction = function(obj) {
3710 return typeof obj === 'function';
3711 };
3712 }
3713
3714 // Is a given object a finite number?
3715 _.isFinite = function(obj) {
3716 return isFinite(obj) && !isNaN(parseFloat(obj));
3717 };
3718
3719 // Is the given value `NaN`? (NaN is the only number which does not equal itself).
3720 _.isNaN = function(obj) {
3721 return _.isNumber(obj) && obj != +obj;
3722 };
3723
3724 // Is a given value a boolean?
3725 _.isBoolean = function(obj) {
3726 return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
3727 };
3728
3729 // Is a given value equal to null?
3730 _.isNull = function(obj) {
3731 return obj === null;
3732 };
3733
3734 // Is a given variable undefined?
3735 _.isUndefined = function(obj) {
3736 return obj === void 0;
3737 };
3738
3739 // Shortcut function for checking if an object has a given property directly
3740 // on itself (in other words, not on a prototype).
3741 _.has = function(obj, key) {
3742 return hasOwnProperty.call(obj, key);
3743 };
3744
3745 // Utility Functions
3746 // -----------------
3747
3748 // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
3749 // previous owner. Returns a reference to the Underscore object.
3750 _.noConflict = function() {
3751 root._ = previousUnderscore;
3752 return this;
3753 };
3754
3755 // Keep the identity function around for default iterators.
3756 _.identity = function(value) {
3757 return value;
3758 };
3759
3760 _.constant = function(value) {
3761 return function () {
3762 return value;
3763 };
3764 };
3765
3766 _.property = function(key) {
3767 return function(obj) {
3768 return obj[key];
3769 };
3770 };
3771
3772 // Returns a predicate for checking whether an object has a given set of `key:value` pairs.
3773 _.matches = function(attrs) {
3774 return function(obj) {
3775 if (obj === attrs) return true; //avoid comparing an object to itself.
3776 for (var key in attrs) {
3777 if (attrs[key] !== obj[key])
3778 return false;
3779 }
3780 return true;
3781 }
3782 };
3783
3784 // Run a function **n** times.
3785 _.times = function(n, iterator, context) {
3786 var accum = Array(Math.max(0, n));
3787 for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i);
3788 return accum;
3789 };
3790
3791 // Return a random integer between min and max (inclusive).
3792 _.random = function(min, max) {
3793 if (max == null) {
3794 max = min;
3795 min = 0;
3796 }
3797 return min + Math.floor(Math.random() * (max - min + 1));
3798 };
3799
3800 // A (possibly faster) way to get the current timestamp as an integer.
3801 _.now = Date.now || function() { return new Date().getTime(); };
3802
3803 // List of HTML entities for escaping.
3804 var entityMap = {
3805 escape: {
3806 '&': '&',
3807 '<': '<',
3808 '>': '>',
3809 '"': '"',
3810 "'": '''
3811 }
3812 };
3813 entityMap.unescape = _.invert(entityMap.escape);
3814
3815 // Regexes containing the keys and values listed immediately above.
3816 var entityRegexes = {
3817 escape: new RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'),
3818 unescape: new RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g')
3819 };
3820
3821 // Functions for escaping and unescaping strings to/from HTML interpolation.
3822 _.each(['escape', 'unescape'], function(method) {
3823 _[method] = function(string) {
3824 if (string == null) return '';
3825 return ('' + string).replace(entityRegexes[method], function(match) {
3826 return entityMap[method][match];
3827 });
3828 };
3829 });
3830
3831 // If the value of the named `property` is a function then invoke it with the
3832 // `object` as context; otherwise, return it.
3833 _.result = function(object, property) {
3834 if (object == null) return void 0;
3835 var value = object[property];
3836 return _.isFunction(value) ? value.call(object) : value;
3837 };
3838
3839 // Add your own custom functions to the Underscore object.
3840 _.mixin = function(obj) {
3841 each(_.functions(obj), function(name) {
3842 var func = _[name] = obj[name];
3843 _.prototype[name] = function() {
3844 var args = [this._wrapped];
3845 push.apply(args, arguments);
3846 return result.call(this, func.apply(_, args));
3847 };
3848 });
3849 };
3850
3851 // Generate a unique integer id (unique within the entire client session).
3852 // Useful for temporary DOM ids.
3853 var idCounter = 0;
3854 _.uniqueId = function(prefix) {
3855 var id = ++idCounter + '';
3856 return prefix ? prefix + id : id;
3857 };
3858
3859 // By default, Underscore uses ERB-style template delimiters, change the
3860 // following template settings to use alternative delimiters.
3861 _.templateSettings = {
3862 evaluate : /<%([\s\S]+?)%>/g,
3863 interpolate : /<%=([\s\S]+?)%>/g,
3864 escape : /<%-([\s\S]+?)%>/g
3865 };
3866
3867 // When customizing `templateSettings`, if you don't want to define an
3868 // interpolation, evaluation or escaping regex, we need one that is
3869 // guaranteed not to match.
3870 var noMatch = /(.)^/;
3871
3872 // Certain characters need to be escaped so that they can be put into a
3873 // string literal.
3874 var escapes = {
3875 "'": "'",
3876 '\\': '\\',
3877 '\r': 'r',
3878 '\n': 'n',
3879 '\t': 't',
3880 '\u2028': 'u2028',
3881 '\u2029': 'u2029'
3882 };
3883
3884 var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
3885
3886 // JavaScript micro-templating, similar to John Resig's implementation.
3887 // Underscore templating handles arbitrary delimiters, preserves whitespace,
3888 // and correctly escapes quotes within interpolated code.
3889 _.template = function(text, data, settings) {
3890 var render;
3891 settings = _.defaults({}, settings, _.templateSettings);
3892
3893 // Combine delimiters into one regular expression via alternation.
3894 var matcher = new RegExp([
3895 (settings.escape || noMatch).source,
3896 (settings.interpolate || noMatch).source,
3897 (settings.evaluate || noMatch).source
3898 ].join('|') + '|$', 'g');
3899
3900 // Compile the template source, escaping string literals appropriately.
3901 var index = 0;
3902 var source = "__p+='";
3903 text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
3904 source += text.slice(index, offset)
3905 .replace(escaper, function(match) { return '\\' + escapes[match]; });
3906
3907 if (escape) {
3908 source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
3909 }
3910 if (interpolate) {
3911 source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
3912 }
3913 if (evaluate) {
3914 source += "';\n" + evaluate + "\n__p+='";
3915 }
3916 index = offset + match.length;
3917 return match;
3918 });
3919 source += "';\n";
3920
3921 // If a variable is not specified, place data values in local scope.
3922 if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
3923
3924 source = "var __t,__p='',__j=Array.prototype.join," +
3925 "print=function(){__p+=__j.call(arguments,'');};\n" +
3926 source + "return __p;\n";
3927
3928 try {
3929 render = new Function(settings.variable || 'obj', '_', source);
3930 } catch (e) {
3931 e.source = source;
3932 throw e;
3933 }
3934
3935 if (data) return render(data, _);
3936 var template = function(data) {
3937 return render.call(this, data, _);
3938 };
3939
3940 // Provide the compiled function source as a convenience for precompilation.
3941 template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}';
3942
3943 return template;
3944 };
3945
3946 // Add a "chain" function, which will delegate to the wrapper.
3947 _.chain = function(obj) {
3948 return _(obj).chain();
3949 };
3950
3951 // OOP
3952 // ---------------
3953 // If Underscore is called as a function, it returns a wrapped object that
3954 // can be used OO-style. This wrapper holds altered versions of all the
3955 // underscore functions. Wrapped objects may be chained.
3956
3957 // Helper function to continue chaining intermediate results.
3958 var result = function(obj) {
3959 return this._chain ? _(obj).chain() : obj;
3960 };
3961
3962 // Add all of the Underscore functions to the wrapper object.
3963 _.mixin(_);
3964
3965 // Add all mutator Array functions to the wrapper.
3966 each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
3967 var method = ArrayProto[name];
3968 _.prototype[name] = function() {
3969 var obj = this._wrapped;
3970 method.apply(obj, arguments);
3971 if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0];
3972 return result.call(this, obj);
3973 };
3974 });
3975
3976 // Add all accessor Array functions to the wrapper.
3977 each(['concat', 'join', 'slice'], function(name) {
3978 var method = ArrayProto[name];
3979 _.prototype[name] = function() {
3980 return result.call(this, method.apply(this._wrapped, arguments));
3981 };
3982 });
3983
3984 _.extend(_.prototype, {
3985
3986 // Start chaining a wrapped Underscore object.
3987 chain: function() {
3988 this._chain = true;
3989 return this;
3990 },
3991
3992 // Extracts the result from a wrapped and chained object.
3993 value: function() {
3994 return this._wrapped;
3995 }
3996
3997 });
3998
3999 // AMD registration happens at the end for compatibility with AMD loaders
4000 // that may not enforce next-turn semantics on modules. Even though general
4001 // practice for AMD registration is to be anonymous, underscore registers
4002 // as a named module because, like jQuery, it is a base library that is
4003 // popular enough to be bundled in a third party lib, but not be part of
4004 // an AMD load request. Those cases could generate an error when an
4005 // anonymous define() is called outside of a loader request.
4006 if (typeof define === 'function' && define.amd) {
4007 define('underscore', [], function() {
4008 return _;
4009 });
4010 }
4011}).call(this);
4012
4013(function(t,e){if(typeof define==="function"&&define.amd){define(["underscore","jquery","exports"],function(i,r,s){t.Backbone=e(t,s,i,r)})}else if(typeof exports!=="undefined"){var i=require("underscore");e(t,exports,i)}else{t.Backbone=e(t,{},t._,t.jQuery||t.Zepto||t.ender||t.$)}})(this,function(t,e,i,r){var s=t.Backbone;var n=[];var a=n.push;var o=n.slice;var h=n.splice;e.VERSION="1.1.2";e.$=r;e.noConflict=function(){t.Backbone=s;return this};e.emulateHTTP=false;e.emulateJSON=false;var u=e.Events={on:function(t,e,i){if(!c(this,"on",t,[e,i])||!e)return this;this._events||(this._events={});var r=this._events[t]||(this._events[t]=[]);r.push({callback:e,context:i,ctx:i||this});return this},once:function(t,e,r){if(!c(this,"once",t,[e,r])||!e)return this;var s=this;var n=i.once(function(){s.off(t,n);e.apply(this,arguments)});n._callback=e;return this.on(t,n,r)},off:function(t,e,r){var s,n,a,o,h,u,l,f;if(!this._events||!c(this,"off",t,[e,r]))return this;if(!t&&!e&&!r){this._events=void 0;return this}o=t?[t]:i.keys(this._events);for(h=0,u=o.length;h<u;h++){t=o[h];if(a=this._events[t]){this._events[t]=s=[];if(e||r){for(l=0,f=a.length;l<f;l++){n=a[l];if(e&&e!==n.callback&&e!==n.callback._callback||r&&r!==n.context){s.push(n)}}}if(!s.length)delete this._events[t]}}return this},trigger:function(t){if(!this._events)return this;var e=o.call(arguments,1);if(!c(this,"trigger",t,e))return this;var i=this._events[t];var r=this._events.all;if(i)f(i,e);if(r)f(r,arguments);return this},stopListening:function(t,e,r){var s=this._listeningTo;if(!s)return this;var n=!e&&!r;if(!r&&typeof e==="object")r=this;if(t)(s={})[t._listenId]=t;for(var a in s){t=s[a];t.off(e,r,this);if(n||i.isEmpty(t._events))delete this._listeningTo[a]}return this}};var l=/\s+/;var c=function(t,e,i,r){if(!i)return true;if(typeof i==="object"){for(var s in i){t[e].apply(t,[s,i[s]].concat(r))}return false}if(l.test(i)){var n=i.split(l);for(var a=0,o=n.length;a<o;a++){t[e].apply(t,[n[a]].concat(r))}return false}return true};var f=function(t,e){var i,r=-1,s=t.length,n=e[0],a=e[1],o=e[2];switch(e.length){case 0:while(++r<s)(i=t[r]).callback.call(i.ctx);return;case 1:while(++r<s)(i=t[r]).callback.call(i.ctx,n);return;case 2:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a);return;case 3:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a,o);return;default:while(++r<s)(i=t[r]).callback.apply(i.ctx,e);return}};var d={listenTo:"on",listenToOnce:"once"};i.each(d,function(t,e){u[e]=function(e,r,s){var n=this._listeningTo||(this._listeningTo={});var a=e._listenId||(e._listenId=i.uniqueId("l"));n[a]=e;if(!s&&typeof r==="object")s=this;e[t](r,s,this);return this}});u.bind=u.on;u.unbind=u.off;i.extend(e,u);var p=e.Model=function(t,e){var r=t||{};e||(e={});this.cid=i.uniqueId("c");this.attributes={};if(e.collection)this.collection=e.collection;if(e.parse)r=this.parse(r,e)||{};r=i.defaults({},r,i.result(this,"defaults"));this.set(r,e);this.changed={};this.initialize.apply(this,arguments)};i.extend(p.prototype,u,{changed:null,validationError:null,idAttribute:"id",initialize:function(){},toJSON:function(t){return i.clone(this.attributes)},sync:function(){return e.sync.apply(this,arguments)},get:function(t){return this.attributes[t]},escape:function(t){return i.escape(this.get(t))},has:function(t){return this.get(t)!=null},set:function(t,e,r){var s,n,a,o,h,u,l,c;if(t==null)return this;if(typeof t==="object"){n=t;r=e}else{(n={})[t]=e}r||(r={});if(!this._validate(n,r))return false;a=r.unset;h=r.silent;o=[];u=this._changing;this._changing=true;if(!u){this._previousAttributes=i.clone(this.attributes);this.changed={}}c=this.attributes,l=this._previousAttributes;if(this.idAttribute in n)this.id=n[this.idAttribute];for(s in n){e=n[s];if(!i.isEqual(c[s],e))o.push(s);if(!i.isEqual(l[s],e)){this.changed[s]=e}else{delete this.changed[s]}a?delete c[s]:c[s]=e}if(!h){if(o.length)this._pending=r;for(var f=0,d=o.length;f<d;f++){this.trigger("change:"+o[f],this,c[o[f]],r)}}if(u)return this;if(!h){while(this._pending){r=this._pending;this._pending=false;this.trigger("change",this,r)}}this._pending=false;this._changing=false;return this},unset:function(t,e){return this.set(t,void 0,i.extend({},e,{unset:true}))},clear:function(t){var e={};for(var r in this.attributes)e[r]=void 0;return this.set(e,i.extend({},t,{unset:true}))},hasChanged:function(t){if(t==null)return!i.isEmpty(this.changed);return i.has(this.changed,t)},changedAttributes:function(t){if(!t)return this.hasChanged()?i.clone(this.changed):false;var e,r=false;var s=this._changing?this._previousAttributes:this.attributes;for(var n in t){if(i.isEqual(s[n],e=t[n]))continue;(r||(r={}))[n]=e}return r},previous:function(t){if(t==null||!this._previousAttributes)return null;return this._previousAttributes[t]},previousAttributes:function(){return i.clone(this._previousAttributes)},fetch:function(t){t=t?i.clone(t):{};if(t.parse===void 0)t.parse=true;var e=this;var r=t.success;t.success=function(i){if(!e.set(e.parse(i,t),t))return false;if(r)r(e,i,t);e.trigger("sync",e,i,t)};q(this,t);return this.sync("read",this,t)},save:function(t,e,r){var s,n,a,o=this.attributes;if(t==null||typeof t==="object"){s=t;r=e}else{(s={})[t]=e}r=i.extend({validate:true},r);if(s&&!r.wait){if(!this.set(s,r))return false}else{if(!this._validate(s,r))return false}if(s&&r.wait){this.attributes=i.extend({},o,s)}if(r.parse===void 0)r.parse=true;var h=this;var u=r.success;r.success=function(t){h.attributes=o;var e=h.parse(t,r);if(r.wait)e=i.extend(s||{},e);if(i.isObject(e)&&!h.set(e,r)){return false}if(u)u(h,t,r);h.trigger("sync",h,t,r)};q(this,r);n=this.isNew()?"create":r.patch?"patch":"update";if(n==="patch")r.attrs=s;a=this.sync(n,this,r);if(s&&r.wait)this.attributes=o;return a},destroy:function(t){t=t?i.clone(t):{};var e=this;var r=t.success;var s=function(){e.trigger("destroy",e,e.collection,t)};t.success=function(i){if(t.wait||e.isNew())s();if(r)r(e,i,t);if(!e.isNew())e.trigger("sync",e,i,t)};if(this.isNew()){t.success();return false}q(this,t);var n=this.sync("delete",this,t);if(!t.wait)s();return n},url:function(){var t=i.result(this,"urlRoot")||i.result(this.collection,"url")||M();if(this.isNew())return t;return t.replace(/([^\/])$/,"$1/")+encodeURIComponent(this.id)},parse:function(t,e){return t},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return!this.has(this.idAttribute)},isValid:function(t){return this._validate({},i.extend(t||{},{validate:true}))},_validate:function(t,e){if(!e.validate||!this.validate)return true;t=i.extend({},this.attributes,t);var r=this.validationError=this.validate(t,e)||null;if(!r)return true;this.trigger("invalid",this,r,i.extend(e,{validationError:r}));return false}});var v=["keys","values","pairs","invert","pick","omit"];i.each(v,function(t){p.prototype[t]=function(){var e=o.call(arguments);e.unshift(this.attributes);return i[t].apply(i,e)}});var g=e.Collection=function(t,e){e||(e={});if(e.model)this.model=e.model;if(e.comparator!==void 0)this.comparator=e.comparator;this._reset();this.initialize.apply(this,arguments);if(t)this.reset(t,i.extend({silent:true},e))};var m={add:true,remove:true,merge:true};var y={add:true,remove:false};i.extend(g.prototype,u,{model:p,initialize:function(){},toJSON:function(t){return this.map(function(e){return e.toJSON(t)})},sync:function(){return e.sync.apply(this,arguments)},add:function(t,e){return this.set(t,i.extend({merge:false},e,y))},remove:function(t,e){var r=!i.isArray(t);t=r?[t]:i.clone(t);e||(e={});var s,n,a,o;for(s=0,n=t.length;s<n;s++){o=t[s]=this.get(t[s]);if(!o)continue;delete this._byId[o.id];delete this._byId[o.cid];a=this.indexOf(o);this.models.splice(a,1);this.length--;if(!e.silent){e.index=a;o.trigger("remove",o,this,e)}this._removeReference(o,e)}return r?t[0]:t},set:function(t,e){e=i.defaults({},e,m);if(e.parse)t=this.parse(t,e);var r=!i.isArray(t);t=r?t?[t]:[]:i.clone(t);var s,n,a,o,h,u,l;var c=e.at;var f=this.model;var d=this.comparator&&c==null&&e.sort!==false;var v=i.isString(this.comparator)?this.comparator:null;var g=[],y=[],_={};var b=e.add,w=e.merge,x=e.remove;var E=!d&&b&&x?[]:false;for(s=0,n=t.length;s<n;s++){h=t[s]||{};if(h instanceof p){a=o=h}else{a=h[f.prototype.idAttribute||"id"]}if(u=this.get(a)){if(x)_[u.cid]=true;if(w){h=h===o?o.attributes:h;if(e.parse)h=u.parse(h,e);u.set(h,e);if(d&&!l&&u.hasChanged(v))l=true}t[s]=u}else if(b){o=t[s]=this._prepareModel(h,e);if(!o)continue;g.push(o);this._addReference(o,e)}o=u||o;if(E&&(o.isNew()||!_[o.id]))E.push(o);_[o.id]=true}if(x){for(s=0,n=this.length;s<n;++s){if(!_[(o=this.models[s]).cid])y.push(o)}if(y.length)this.remove(y,e)}if(g.length||E&&E.length){if(d)l=true;this.length+=g.length;if(c!=null){for(s=0,n=g.length;s<n;s++){this.models.splice(c+s,0,g[s])}}else{if(E)this.models.length=0;var k=E||g;for(s=0,n=k.length;s<n;s++){this.models.push(k[s])}}}if(l)this.sort({silent:true});if(!e.silent){for(s=0,n=g.length;s<n;s++){(o=g[s]).trigger("add",o,this,e)}if(l||E&&E.length)this.trigger("sort",this,e)}return r?t[0]:t},reset:function(t,e){e||(e={});for(var r=0,s=this.models.length;r<s;r++){this._removeReference(this.models[r],e)}e.previousModels=this.models;this._reset();t=this.add(t,i.extend({silent:true},e));if(!e.silent)this.trigger("reset",this,e);return t},push:function(t,e){return this.add(t,i.extend({at:this.length},e))},pop:function(t){var e=this.at(this.length-1);this.remove(e,t);return e},unshift:function(t,e){return this.add(t,i.extend({at:0},e))},shift:function(t){var e=this.at(0);this.remove(e,t);return e},slice:function(){return o.apply(this.models,arguments)},get:function(t){if(t==null)return void 0;return this._byId[t]||this._byId[t.id]||this._byId[t.cid]},at:function(t){return this.models[t]},where:function(t,e){if(i.isEmpty(t))return e?void 0:[];return this[e?"find":"filter"](function(e){for(var i in t){if(t[i]!==e.get(i))return false}return true})},findWhere:function(t){return this.where(t,true)},sort:function(t){if(!this.comparator)throw new Error("Cannot sort a set without a comparator");t||(t={});if(i.isString(this.comparator)||this.comparator.length===1){this.models=this.sortBy(this.comparator,this)}else{this.models.sort(i.bind(this.comparator,this))}if(!t.silent)this.trigger("sort",this,t);return this},pluck:function(t){return i.invoke(this.models,"get",t)},fetch:function(t){t=t?i.clone(t):{};if(t.parse===void 0)t.parse=true;var e=t.success;var r=this;t.success=function(i){var s=t.reset?"reset":"set";r[s](i,t);if(e)e(r,i,t);r.trigger("sync",r,i,t)};q(this,t);return this.sync("read",this,t)},create:function(t,e){e=e?i.clone(e):{};if(!(t=this._prepareModel(t,e)))return false;if(!e.wait)this.add(t,e);var r=this;var s=e.success;e.success=function(t,i){if(e.wait)r.add(t,e);if(s)s(t,i,e)};t.save(null,e);return t},parse:function(t,e){return t},clone:function(){return new this.constructor(this.models)},_reset:function(){this.length=0;this.models=[];this._byId={}},_prepareModel:function(t,e){if(t instanceof p)return t;e=e?i.clone(e):{};e.collection=this;var r=new this.model(t,e);if(!r.validationError)return r;this.trigger("invalid",this,r.validationError,e);return false},_addReference:function(t,e){this._byId[t.cid]=t;if(t.id!=null)this._byId[t.id]=t;if(!t.collection)t.collection=this;t.on("all",this._onModelEvent,this)},_removeReference:function(t,e){if(this===t.collection)delete t.collection;t.off("all",this._onModelEvent,this)},_onModelEvent:function(t,e,i,r){if((t==="add"||t==="remove")&&i!==this)return;if(t==="destroy")this.remove(e,r);if(e&&t==="change:"+e.idAttribute){delete this._byId[e.previous(e.idAttribute)];if(e.id!=null)this._byId[e.id]=e}this.trigger.apply(this,arguments)}});var _=["forEach","each","map","collect","reduce","foldl","inject","reduceRight","foldr","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","toArray","size","first","head","take","initial","rest","tail","drop","last","without","difference","indexOf","shuffle","lastIndexOf","isEmpty","chain","sample"];i.each(_,function(t){g.prototype[t]=function(){var e=o.call(arguments);e.unshift(this.models);return i[t].apply(i,e)}});var b=["groupBy","countBy","sortBy","indexBy"];i.each(b,function(t){g.prototype[t]=function(e,r){var s=i.isFunction(e)?e:function(t){return t.get(e)};return i[t](this.models,s,r)}});var w=e.View=function(t){this.cid=i.uniqueId("view");t||(t={});i.extend(this,i.pick(t,E));this._ensureElement();this.initialize.apply(this,arguments);this.delegateEvents()};var x=/^(\S+)\s*(.*)$/;var E=["model","collection","el","id","attributes","className","tagName","events"];i.extend(w.prototype,u,{tagName:"div",$:function(t){return this.$el.find(t)},initialize:function(){},render:function(){return this},remove:function(){this.$el.remove();this.stopListening();return this},setElement:function(t,i){if(this.$el)this.undelegateEvents();this.$el=t instanceof e.$?t:e.$(t);this.el=this.$el[0];if(i!==false)this.delegateEvents();return this},delegateEvents:function(t){if(!(t||(t=i.result(this,"events"))))return this;this.undelegateEvents();for(var e in t){var r=t[e];if(!i.isFunction(r))r=this[t[e]];if(!r)continue;var s=e.match(x);var n=s[1],a=s[2];r=i.bind(r,this);n+=".delegateEvents"+this.cid;if(a===""){this.$el.on(n,r)}else{this.$el.on(n,a,r)}}return this},undelegateEvents:function(){this.$el.off(".delegateEvents"+this.cid);return this},_ensureElement:function(){if(!this.el){var t=i.extend({},i.result(this,"attributes"));if(this.id)t.id=i.result(this,"id");if(this.className)t["class"]=i.result(this,"className");var r=e.$("<"+i.result(this,"tagName")+">").attr(t);this.setElement(r,false)}else{this.setElement(i.result(this,"el"),false)}}});e.sync=function(t,r,s){var n=T[t];i.defaults(s||(s={}),{emulateHTTP:e.emulateHTTP,emulateJSON:e.emulateJSON});var a={type:n,dataType:"json"};if(!s.url){a.url=i.result(r,"url")||M()}if(s.data==null&&r&&(t==="create"||t==="update"||t==="patch")){a.contentType="application/json";a.data=JSON.stringify(s.attrs||r.toJSON(s))}if(s.emulateJSON){a.contentType="application/x-www-form-urlencoded";a.data=a.data?{model:a.data}:{}}if(s.emulateHTTP&&(n==="PUT"||n==="DELETE"||n==="PATCH")){a.type="POST";if(s.emulateJSON)a.data._method=n;var o=s.beforeSend;s.beforeSend=function(t){t.setRequestHeader("X-HTTP-Method-Override",n);if(o)return o.apply(this,arguments)}}if(a.type!=="GET"&&!s.emulateJSON){a.processData=false}if(a.type==="PATCH"&&k){a.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")}}var h=s.xhr=e.ajax(i.extend(a,s));r.trigger("request",r,h,s);return h};var k=typeof window!=="undefined"&&!!window.ActiveXObject&&!(window.XMLHttpRequest&&(new XMLHttpRequest).dispatchEvent);var T={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};e.ajax=function(){return e.$.ajax.apply(e.$,arguments)};var $=e.Router=function(t){t||(t={});if(t.routes)this.routes=t.routes;this._bindRoutes();this.initialize.apply(this,arguments)};var S=/\((.*?)\)/g;var H=/(\(\?)?:\w+/g;var A=/\*\w+/g;var I=/[\-{}\[\]+?.,\\\^$|#\s]/g;i.extend($.prototype,u,{initialize:function(){},route:function(t,r,s){if(!i.isRegExp(t))t=this._routeToRegExp(t);if(i.isFunction(r)){s=r;r=""}if(!s)s=this[r];var n=this;e.history.route(t,function(i){var a=n._extractParameters(t,i);n.execute(s,a);n.trigger.apply(n,["route:"+r].concat(a));n.trigger("route",r,a);e.history.trigger("route",n,r,a)});return this},execute:function(t,e){if(t)t.apply(this,e)},navigate:function(t,i){e.history.navigate(t,i);return this},_bindRoutes:function(){if(!this.routes)return;this.routes=i.result(this,"routes");var t,e=i.keys(this.routes);while((t=e.pop())!=null){this.route(t,this.routes[t])}},_routeToRegExp:function(t){t=t.replace(I,"\\$&").replace(S,"(?:$1)?").replace(H,function(t,e){return e?t:"([^/?]+)"}).replace(A,"([^?]*?)");return new RegExp("^"+t+"(?:\\?([\\s\\S]*))?$")},_extractParameters:function(t,e){var r=t.exec(e).slice(1);return i.map(r,function(t,e){if(e===r.length-1)return t||null;return t?decodeURIComponent(t):null})}});var N=e.History=function(){this.handlers=[];i.bindAll(this,"checkUrl");if(typeof window!=="undefined"){this.location=window.location;this.history=window.history}};var R=/^[#\/]|\s+$/g;var O=/^\/+|\/+$/g;var P=/msie [\w.]+/;var C=/\/$/;var j=/#.*$/;N.started=false;i.extend(N.prototype,u,{interval:50,atRoot:function(){return this.location.pathname.replace(/[^\/]$/,"$&/")===this.root},getHash:function(t){var e=(t||this).location.href.match(/#(.*)$/);return e?e[1]:""},getFragment:function(t,e){if(t==null){if(this._hasPushState||!this._wantsHashChange||e){t=decodeURI(this.location.pathname+this.location.search);var i=this.root.replace(C,"");if(!t.indexOf(i))t=t.slice(i.length)}else{t=this.getHash()}}return t.replace(R,"")},start:function(t){if(N.started)throw new Error("Backbone.history has already been started");N.started=true;this.options=i.extend({root:"/"},this.options,t);this.root=this.options.root;this._wantsHashChange=this.options.hashChange!==false;this._wantsPushState=!!this.options.pushState;this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);var r=this.getFragment();var s=document.documentMode;var n=P.exec(navigator.userAgent.toLowerCase())&&(!s||s<=7);this.root=("/"+this.root+"/").replace(O,"/");if(n&&this._wantsHashChange){var a=e.$('<iframe src="javascript:0" tabindex="-1">');this.iframe=a.hide().appendTo("body")[0].contentWindow;this.navigate(r)}if(this._hasPushState){e.$(window).on("popstate",this.checkUrl)}else if(this._wantsHashChange&&"onhashchange"in window&&!n){e.$(window).on("hashchange",this.checkUrl)}else if(this._wantsHashChange){this._checkUrlInterval=setInterval(this.checkUrl,this.interval)}this.fragment=r;var o=this.location;if(this._wantsHashChange&&this._wantsPushState){if(!this._hasPushState&&!this.atRoot()){this.fragment=this.getFragment(null,true);this.location.replace(this.root+"#"+this.fragment);return true}else if(this._hasPushState&&this.atRoot()&&o.hash){this.fragment=this.getHash().replace(R,"");this.history.replaceState({},document.title,this.root+this.fragment)}}if(!this.options.silent)return this.loadUrl()},stop:function(){e.$(window).off("popstate",this.checkUrl).off("hashchange",this.checkUrl);if(this._checkUrlInterval)clearInterval(this._checkUrlInterval);N.started=false},route:function(t,e){this.handlers.unshift({route:t,callback:e})},checkUrl:function(t){var e=this.getFragment();if(e===this.fragment&&this.iframe){e=this.getFragment(this.getHash(this.iframe))}if(e===this.fragment)return false;if(this.iframe)this.navigate(e);this.loadUrl()},loadUrl:function(t){t=this.fragment=this.getFragment(t);return i.any(this.handlers,function(e){if(e.route.test(t)){e.callback(t);return true}})},navigate:function(t,e){if(!N.started)return false;if(!e||e===true)e={trigger:!!e};var i=this.root+(t=this.getFragment(t||""));t=t.replace(j,"");if(this.fragment===t)return;this.fragment=t;if(t===""&&i!=="/")i=i.slice(0,-1);if(this._hasPushState){this.history[e.replace?"replaceState":"pushState"]({},document.title,i)}else if(this._wantsHashChange){this._updateHash(this.location,t,e.replace);if(this.iframe&&t!==this.getFragment(this.getHash(this.iframe))){if(!e.replace)this.iframe.document.open().close();this._updateHash(this.iframe.location,t,e.replace)}}else{return this.location.assign(i)}if(e.trigger)return this.loadUrl(t)},_updateHash:function(t,e,i){if(i){var r=t.href.replace(/(javascript:|#).*$/,"");t.replace(r+"#"+e)}else{t.hash="#"+e}}});e.history=new N;var U=function(t,e){var r=this;var s;if(t&&i.has(t,"constructor")){s=t.constructor}else{s=function(){return r.apply(this,arguments)}}i.extend(s,r,e);var n=function(){this.constructor=s};n.prototype=r.prototype;s.prototype=new n;if(t)i.extend(s.prototype,t);s.__super__=r.prototype;return s};p.extend=g.extend=$.extend=w.extend=N.extend=U;var M=function(){throw new Error('A "url" property or function must be specified')};var q=function(t,e){var i=e.error;e.error=function(r){if(i)i(t,r,e);t.trigger("error",t,r,e)}};return e});
4014//# sourceMappingURL=backbone-min.map
4015
4016/**
4017 * @author mrdoob / http://mrdoob.com/
4018 */
4019
4020var EventDispatcher = function () {}
4021
4022EventDispatcher.prototype = {
4023
4024 constructor: EventDispatcher,
4025
4026 apply: function ( object ) {
4027
4028 object.addEventListener = EventDispatcher.prototype.addEventListener;
4029 object.hasEventListener = EventDispatcher.prototype.hasEventListener;
4030 object.removeEventListener = EventDispatcher.prototype.removeEventListener;
4031 object.dispatchEvent = EventDispatcher.prototype.dispatchEvent;
4032
4033 },
4034
4035 addEventListener: function ( type, listener ) {
4036
4037 if ( this._listeners === undefined ) this._listeners = {};
4038
4039 var listeners = this._listeners;
4040
4041 if ( listeners[ type ] === undefined ) {
4042
4043 listeners[ type ] = [];
4044
4045 }
4046
4047 if ( listeners[ type ].indexOf( listener ) === - 1 ) {
4048
4049 //dispatch before pushing so that a listeneradded listener does not trigger itself
4050 this.dispatchEvent( { type: 'listeneradded', listenerType: type, listener: listener } );
4051
4052 listeners[ type ].push( listener );
4053
4054 }
4055
4056 },
4057
4058 hasEventListener: function ( type, listener ) {
4059
4060 if ( this._listeners === undefined ) return false;
4061
4062 var listeners = this._listeners;
4063
4064 if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
4065
4066 return true;
4067
4068 }
4069
4070 return false;
4071
4072 },
4073
4074 removeEventListener: function ( type, listener ) {
4075
4076 if ( this._listeners === undefined ) return;
4077
4078 var listeners = this._listeners;
4079 var listenerArray = listeners[ type ];
4080
4081 if ( listenerArray !== undefined ) {
4082
4083 var index = listenerArray.indexOf( listener );
4084
4085 if ( index !== - 1 ) {
4086
4087 listenerArray.splice( index, 1 );
4088
4089 this.dispatchEvent( { type: 'listenerremoved', listenerType: type, listener: listener } );
4090 //dispatch after splicing so that a listenerremoved listener does not trigger itself
4091 }
4092
4093 }
4094
4095 },
4096
4097 dispatchEvent: function ( event ) {
4098
4099 if ( this._listeners === undefined ) return;
4100
4101 var listeners = this._listeners;
4102 var listenerArray = listeners[ event.type ];
4103
4104 if ( listenerArray !== undefined ) {
4105
4106 event.target = this;
4107
4108 var array = [];
4109 var length = listenerArray.length;
4110
4111 for ( var i = 0; i < length; i ++ ) {
4112
4113 array[ i ] = listenerArray[ i ];
4114
4115 }
4116
4117 for ( var i = 0; i < length; i ++ ) {
4118
4119 array[ i ].call( this, event );
4120
4121 }
4122
4123 }
4124
4125 }
4126
4127};
4128
4129//
4130// Autogenerated by Thrift Compiler (0.9.3-GFODOR)
4131//
4132// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
4133//
4134
4135
4136SkeletonHandState = {
4137 'Unknown' : 0,
4138 'NotTracked' : 1,
4139 'Open' : 2,
4140 'Closed' : 3,
4141 'Lasso' : 4,
4142 'Pointing' : 5
4143};
4144GameEventType = {
4145 'Unknown' : 0,
4146 'Instantiation' : 1,
4147 'Serialization' : 2,
4148 'RPC' : 3,
4149 'Event' : 4,
4150 'Operation' : 5
4151};
4152VoiceCodec = {
4153 'Unknown' : 0,
4154 'Opus' : 1
4155};
4156Vector2Data = function(args) {
4157 this.x = 0;
4158 this.y = 0;
4159 if (args) {
4160 if (args.x !== undefined && args.x !== null) {
4161 this.x = args.x;
4162 }
4163 if (args.y !== undefined && args.y !== null) {
4164 this.y = args.y;
4165 }
4166 }
4167};
4168Vector2Data.prototype = {};
4169Vector2Data.prototype.read = function(input) {
4170 input.readStructBegin();
4171 while (true)
4172 {
4173 var ret = input.readFieldBegin();
4174 var fname = ret.fname;
4175 var ftype = ret.ftype;
4176 var fid = ret.fid;
4177 if (ftype == Thrift.Type.STOP) {
4178 break;
4179 }
4180 switch (fid)
4181 {
4182 case 1:
4183 if (ftype == Thrift.Type.DOUBLE) {
4184 this.x = input.readDouble().value;
4185 } else {
4186 input.skip(ftype);
4187 }
4188 break;
4189 case 2:
4190 if (ftype == Thrift.Type.DOUBLE) {
4191 this.y = input.readDouble().value;
4192 } else {
4193 input.skip(ftype);
4194 }
4195 break;
4196 default:
4197 input.skip(ftype);
4198 }
4199 input.readFieldEnd();
4200 }
4201 input.readStructEnd();
4202 return;
4203};
4204
4205Vector2Data.prototype.write = function(output) {
4206 output.writeStructBegin('Vector2Data');
4207 if (this.x !== null && this.x !== undefined) {
4208 output.writeFieldBegin('x', Thrift.Type.DOUBLE, 1);
4209 output.writeDouble(this.x);
4210 output.writeFieldEnd();
4211 }
4212 if (this.y !== null && this.y !== undefined) {
4213 output.writeFieldBegin('y', Thrift.Type.DOUBLE, 2);
4214 output.writeDouble(this.y);
4215 output.writeFieldEnd();
4216 }
4217 output.writeFieldStop();
4218 output.writeStructEnd();
4219 return;
4220};
4221
4222Vector3Data = function(args) {
4223 this.x = 0;
4224 this.y = 0;
4225 this.z = 0;
4226 if (args) {
4227 if (args.x !== undefined && args.x !== null) {
4228 this.x = args.x;
4229 }
4230 if (args.y !== undefined && args.y !== null) {
4231 this.y = args.y;
4232 }
4233 if (args.z !== undefined && args.z !== null) {
4234 this.z = args.z;
4235 }
4236 }
4237};
4238Vector3Data.prototype = {};
4239Vector3Data.prototype.read = function(input) {
4240 input.readStructBegin();
4241 while (true)
4242 {
4243 var ret = input.readFieldBegin();
4244 var fname = ret.fname;
4245 var ftype = ret.ftype;
4246 var fid = ret.fid;
4247 if (ftype == Thrift.Type.STOP) {
4248 break;
4249 }
4250 switch (fid)
4251 {
4252 case 1:
4253 if (ftype == Thrift.Type.DOUBLE) {
4254 this.x = input.readDouble().value;
4255 } else {
4256 input.skip(ftype);
4257 }
4258 break;
4259 case 2:
4260 if (ftype == Thrift.Type.DOUBLE) {
4261 this.y = input.readDouble().value;
4262 } else {
4263 input.skip(ftype);
4264 }
4265 break;
4266 case 3:
4267 if (ftype == Thrift.Type.DOUBLE) {
4268 this.z = input.readDouble().value;
4269 } else {
4270 input.skip(ftype);
4271 }
4272 break;
4273 default:
4274 input.skip(ftype);
4275 }
4276 input.readFieldEnd();
4277 }
4278 input.readStructEnd();
4279 return;
4280};
4281
4282Vector3Data.prototype.write = function(output) {
4283 output.writeStructBegin('Vector3Data');
4284 if (this.x !== null && this.x !== undefined) {
4285 output.writeFieldBegin('x', Thrift.Type.DOUBLE, 1);
4286 output.writeDouble(this.x);
4287 output.writeFieldEnd();
4288 }
4289 if (this.y !== null && this.y !== undefined) {
4290 output.writeFieldBegin('y', Thrift.Type.DOUBLE, 2);
4291 output.writeDouble(this.y);
4292 output.writeFieldEnd();
4293 }
4294 if (this.z !== null && this.z !== undefined) {
4295 output.writeFieldBegin('z', Thrift.Type.DOUBLE, 3);
4296 output.writeDouble(this.z);
4297 output.writeFieldEnd();
4298 }
4299 output.writeFieldStop();
4300 output.writeStructEnd();
4301 return;
4302};
4303
4304DimensionsData = function(args) {
4305 this.Width = 0;
4306 this.Height = 0;
4307 this.Depth = 0;
4308 if (args) {
4309 if (args.Width !== undefined && args.Width !== null) {
4310 this.Width = args.Width;
4311 }
4312 if (args.Height !== undefined && args.Height !== null) {
4313 this.Height = args.Height;
4314 }
4315 if (args.Depth !== undefined && args.Depth !== null) {
4316 this.Depth = args.Depth;
4317 }
4318 }
4319};
4320DimensionsData.prototype = {};
4321DimensionsData.prototype.read = function(input) {
4322 input.readStructBegin();
4323 while (true)
4324 {
4325 var ret = input.readFieldBegin();
4326 var fname = ret.fname;
4327 var ftype = ret.ftype;
4328 var fid = ret.fid;
4329 if (ftype == Thrift.Type.STOP) {
4330 break;
4331 }
4332 switch (fid)
4333 {
4334 case 1:
4335 if (ftype == Thrift.Type.DOUBLE) {
4336 this.Width = input.readDouble().value;
4337 } else {
4338 input.skip(ftype);
4339 }
4340 break;
4341 case 2:
4342 if (ftype == Thrift.Type.DOUBLE) {
4343 this.Height = input.readDouble().value;
4344 } else {
4345 input.skip(ftype);
4346 }
4347 break;
4348 case 3:
4349 if (ftype == Thrift.Type.DOUBLE) {
4350 this.Depth = input.readDouble().value;
4351 } else {
4352 input.skip(ftype);
4353 }
4354 break;
4355 default:
4356 input.skip(ftype);
4357 }
4358 input.readFieldEnd();
4359 }
4360 input.readStructEnd();
4361 return;
4362};
4363
4364DimensionsData.prototype.write = function(output) {
4365 output.writeStructBegin('DimensionsData');
4366 if (this.Width !== null && this.Width !== undefined) {
4367 output.writeFieldBegin('Width', Thrift.Type.DOUBLE, 1);
4368 output.writeDouble(this.Width);
4369 output.writeFieldEnd();
4370 }
4371 if (this.Height !== null && this.Height !== undefined) {
4372 output.writeFieldBegin('Height', Thrift.Type.DOUBLE, 2);
4373 output.writeDouble(this.Height);
4374 output.writeFieldEnd();
4375 }
4376 if (this.Depth !== null && this.Depth !== undefined) {
4377 output.writeFieldBegin('Depth', Thrift.Type.DOUBLE, 3);
4378 output.writeDouble(this.Depth);
4379 output.writeFieldEnd();
4380 }
4381 output.writeFieldStop();
4382 output.writeStructEnd();
4383 return;
4384};
4385
4386QuaternionData = function(args) {
4387 this.x = 0;
4388 this.y = 0;
4389 this.z = 0;
4390 this.w = 1;
4391 if (args) {
4392 if (args.x !== undefined && args.x !== null) {
4393 this.x = args.x;
4394 }
4395 if (args.y !== undefined && args.y !== null) {
4396 this.y = args.y;
4397 }
4398 if (args.z !== undefined && args.z !== null) {
4399 this.z = args.z;
4400 }
4401 if (args.w !== undefined && args.w !== null) {
4402 this.w = args.w;
4403 }
4404 }
4405};
4406QuaternionData.prototype = {};
4407QuaternionData.prototype.read = function(input) {
4408 input.readStructBegin();
4409 while (true)
4410 {
4411 var ret = input.readFieldBegin();
4412 var fname = ret.fname;
4413 var ftype = ret.ftype;
4414 var fid = ret.fid;
4415 if (ftype == Thrift.Type.STOP) {
4416 break;
4417 }
4418 switch (fid)
4419 {
4420 case 1:
4421 if (ftype == Thrift.Type.DOUBLE) {
4422 this.x = input.readDouble().value;
4423 } else {
4424 input.skip(ftype);
4425 }
4426 break;
4427 case 2:
4428 if (ftype == Thrift.Type.DOUBLE) {
4429 this.y = input.readDouble().value;
4430 } else {
4431 input.skip(ftype);
4432 }
4433 break;
4434 case 3:
4435 if (ftype == Thrift.Type.DOUBLE) {
4436 this.z = input.readDouble().value;
4437 } else {
4438 input.skip(ftype);
4439 }
4440 break;
4441 case 4:
4442 if (ftype == Thrift.Type.DOUBLE) {
4443 this.w = input.readDouble().value;
4444 } else {
4445 input.skip(ftype);
4446 }
4447 break;
4448 default:
4449 input.skip(ftype);
4450 }
4451 input.readFieldEnd();
4452 }
4453 input.readStructEnd();
4454 return;
4455};
4456
4457QuaternionData.prototype.write = function(output) {
4458 output.writeStructBegin('QuaternionData');
4459 if (this.x !== null && this.x !== undefined) {
4460 output.writeFieldBegin('x', Thrift.Type.DOUBLE, 1);
4461 output.writeDouble(this.x);
4462 output.writeFieldEnd();
4463 }
4464 if (this.y !== null && this.y !== undefined) {
4465 output.writeFieldBegin('y', Thrift.Type.DOUBLE, 2);
4466 output.writeDouble(this.y);
4467 output.writeFieldEnd();
4468 }
4469 if (this.z !== null && this.z !== undefined) {
4470 output.writeFieldBegin('z', Thrift.Type.DOUBLE, 3);
4471 output.writeDouble(this.z);
4472 output.writeFieldEnd();
4473 }
4474 if (this.w !== null && this.w !== undefined) {
4475 output.writeFieldBegin('w', Thrift.Type.DOUBLE, 4);
4476 output.writeDouble(this.w);
4477 output.writeFieldEnd();
4478 }
4479 output.writeFieldStop();
4480 output.writeStructEnd();
4481 return;
4482};
4483
4484ColorData = function(args) {
4485 this.r = null;
4486 this.g = null;
4487 this.b = null;
4488 this.a = null;
4489 if (args) {
4490 if (args.r !== undefined && args.r !== null) {
4491 this.r = args.r;
4492 }
4493 if (args.g !== undefined && args.g !== null) {
4494 this.g = args.g;
4495 }
4496 if (args.b !== undefined && args.b !== null) {
4497 this.b = args.b;
4498 }
4499 if (args.a !== undefined && args.a !== null) {
4500 this.a = args.a;
4501 }
4502 }
4503};
4504ColorData.prototype = {};
4505ColorData.prototype.read = function(input) {
4506 input.readStructBegin();
4507 while (true)
4508 {
4509 var ret = input.readFieldBegin();
4510 var fname = ret.fname;
4511 var ftype = ret.ftype;
4512 var fid = ret.fid;
4513 if (ftype == Thrift.Type.STOP) {
4514 break;
4515 }
4516 switch (fid)
4517 {
4518 case 1:
4519 if (ftype == Thrift.Type.DOUBLE) {
4520 this.r = input.readDouble().value;
4521 } else {
4522 input.skip(ftype);
4523 }
4524 break;
4525 case 2:
4526 if (ftype == Thrift.Type.DOUBLE) {
4527 this.g = input.readDouble().value;
4528 } else {
4529 input.skip(ftype);
4530 }
4531 break;
4532 case 3:
4533 if (ftype == Thrift.Type.DOUBLE) {
4534 this.b = input.readDouble().value;
4535 } else {
4536 input.skip(ftype);
4537 }
4538 break;
4539 case 4:
4540 if (ftype == Thrift.Type.DOUBLE) {
4541 this.a = input.readDouble().value;
4542 } else {
4543 input.skip(ftype);
4544 }
4545 break;
4546 default:
4547 input.skip(ftype);
4548 }
4549 input.readFieldEnd();
4550 }
4551 input.readStructEnd();
4552 return;
4553};
4554
4555ColorData.prototype.write = function(output) {
4556 output.writeStructBegin('ColorData');
4557 if (this.r !== null && this.r !== undefined) {
4558 output.writeFieldBegin('r', Thrift.Type.DOUBLE, 1);
4559 output.writeDouble(this.r);
4560 output.writeFieldEnd();
4561 }
4562 if (this.g !== null && this.g !== undefined) {
4563 output.writeFieldBegin('g', Thrift.Type.DOUBLE, 2);
4564 output.writeDouble(this.g);
4565 output.writeFieldEnd();
4566 }
4567 if (this.b !== null && this.b !== undefined) {
4568 output.writeFieldBegin('b', Thrift.Type.DOUBLE, 3);
4569 output.writeDouble(this.b);
4570 output.writeFieldEnd();
4571 }
4572 if (this.a !== null && this.a !== undefined) {
4573 output.writeFieldBegin('a', Thrift.Type.DOUBLE, 4);
4574 output.writeDouble(this.a);
4575 output.writeFieldEnd();
4576 }
4577 output.writeFieldStop();
4578 output.writeStructEnd();
4579 return;
4580};
4581
4582TransformData = function(args) {
4583 this.Position = null;
4584 this.Rotation = null;
4585 this.Scale = null;
4586 if (args) {
4587 if (args.Position !== undefined && args.Position !== null) {
4588 this.Position = new Vector3Data(args.Position);
4589 } else {
4590 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Position is unset!');
4591 }
4592 if (args.Rotation !== undefined && args.Rotation !== null) {
4593 this.Rotation = new QuaternionData(args.Rotation);
4594 } else {
4595 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Rotation is unset!');
4596 }
4597 if (args.Scale !== undefined && args.Scale !== null) {
4598 this.Scale = new Vector3Data(args.Scale);
4599 }
4600 }
4601};
4602TransformData.prototype = {};
4603TransformData.prototype.read = function(input) {
4604 input.readStructBegin();
4605 while (true)
4606 {
4607 var ret = input.readFieldBegin();
4608 var fname = ret.fname;
4609 var ftype = ret.ftype;
4610 var fid = ret.fid;
4611 if (ftype == Thrift.Type.STOP) {
4612 break;
4613 }
4614 switch (fid)
4615 {
4616 case 1:
4617 if (ftype == Thrift.Type.STRUCT) {
4618 this.Position = new Vector3Data();
4619 this.Position.read(input);
4620 } else {
4621 input.skip(ftype);
4622 }
4623 break;
4624 case 2:
4625 if (ftype == Thrift.Type.STRUCT) {
4626 this.Rotation = new QuaternionData();
4627 this.Rotation.read(input);
4628 } else {
4629 input.skip(ftype);
4630 }
4631 break;
4632 case 3:
4633 if (ftype == Thrift.Type.STRUCT) {
4634 this.Scale = new Vector3Data();
4635 this.Scale.read(input);
4636 } else {
4637 input.skip(ftype);
4638 }
4639 break;
4640 default:
4641 input.skip(ftype);
4642 }
4643 input.readFieldEnd();
4644 }
4645 input.readStructEnd();
4646 return;
4647};
4648
4649TransformData.prototype.write = function(output) {
4650 output.writeStructBegin('TransformData');
4651 if (this.Position !== null && this.Position !== undefined) {
4652 output.writeFieldBegin('Position', Thrift.Type.STRUCT, 1);
4653 this.Position.write(output);
4654 output.writeFieldEnd();
4655 }
4656 if (this.Rotation !== null && this.Rotation !== undefined) {
4657 output.writeFieldBegin('Rotation', Thrift.Type.STRUCT, 2);
4658 this.Rotation.write(output);
4659 output.writeFieldEnd();
4660 }
4661 if (this.Scale !== null && this.Scale !== undefined) {
4662 output.writeFieldBegin('Scale', Thrift.Type.STRUCT, 3);
4663 this.Scale.write(output);
4664 output.writeFieldEnd();
4665 }
4666 output.writeFieldStop();
4667 output.writeStructEnd();
4668 return;
4669};
4670
4671PlayerID = function(args) {
4672 this.UserId = null;
4673 if (args) {
4674 if (args.UserId !== undefined && args.UserId !== null) {
4675 this.UserId = args.UserId;
4676 }
4677 }
4678};
4679PlayerID.prototype = {};
4680PlayerID.prototype.read = function(input) {
4681 input.readStructBegin();
4682 while (true)
4683 {
4684 var ret = input.readFieldBegin();
4685 var fname = ret.fname;
4686 var ftype = ret.ftype;
4687 var fid = ret.fid;
4688 if (ftype == Thrift.Type.STOP) {
4689 break;
4690 }
4691 switch (fid)
4692 {
4693 case 1:
4694 if (ftype == Thrift.Type.I64) {
4695 this.UserId = input.readI64().value;
4696 } else {
4697 input.skip(ftype);
4698 }
4699 break;
4700 case 0:
4701 input.skip(ftype);
4702 break;
4703 default:
4704 input.skip(ftype);
4705 }
4706 input.readFieldEnd();
4707 }
4708 input.readStructEnd();
4709 return;
4710};
4711
4712PlayerID.prototype.write = function(output) {
4713 output.writeStructBegin('PlayerID');
4714 if (this.UserId !== null && this.UserId !== undefined) {
4715 output.writeFieldBegin('UserId', Thrift.Type.I64, 1);
4716 output.writeI64(this.UserId);
4717 output.writeFieldEnd();
4718 }
4719 output.writeFieldStop();
4720 output.writeStructEnd();
4721 return;
4722};
4723
4724GameServerTime = function(args) {
4725 this.GameServerTimeMilliseconds = null;
4726 if (args) {
4727 if (args.GameServerTimeMilliseconds !== undefined && args.GameServerTimeMilliseconds !== null) {
4728 this.GameServerTimeMilliseconds = args.GameServerTimeMilliseconds;
4729 }
4730 }
4731};
4732GameServerTime.prototype = {};
4733GameServerTime.prototype.read = function(input) {
4734 input.readStructBegin();
4735 while (true)
4736 {
4737 var ret = input.readFieldBegin();
4738 var fname = ret.fname;
4739 var ftype = ret.ftype;
4740 var fid = ret.fid;
4741 if (ftype == Thrift.Type.STOP) {
4742 break;
4743 }
4744 switch (fid)
4745 {
4746 case 1:
4747 if (ftype == Thrift.Type.I32) {
4748 this.GameServerTimeMilliseconds = input.readI32().value;
4749 } else {
4750 input.skip(ftype);
4751 }
4752 break;
4753 case 0:
4754 input.skip(ftype);
4755 break;
4756 default:
4757 input.skip(ftype);
4758 }
4759 input.readFieldEnd();
4760 }
4761 input.readStructEnd();
4762 return;
4763};
4764
4765GameServerTime.prototype.write = function(output) {
4766 output.writeStructBegin('GameServerTime');
4767 if (this.GameServerTimeMilliseconds !== null && this.GameServerTimeMilliseconds !== undefined) {
4768 output.writeFieldBegin('GameServerTimeMilliseconds', Thrift.Type.I32, 1);
4769 output.writeI32(this.GameServerTimeMilliseconds);
4770 output.writeFieldEnd();
4771 }
4772 output.writeFieldStop();
4773 output.writeStructEnd();
4774 return;
4775};
4776
4777GameViewID = function(args) {
4778 this.ViewId = null;
4779 this.LevelId = null;
4780 if (args) {
4781 if (args.ViewId !== undefined && args.ViewId !== null) {
4782 this.ViewId = args.ViewId;
4783 } else {
4784 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field ViewId is unset!');
4785 }
4786 if (args.LevelId !== undefined && args.LevelId !== null) {
4787 this.LevelId = args.LevelId;
4788 } else {
4789 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field LevelId is unset!');
4790 }
4791 }
4792};
4793GameViewID.prototype = {};
4794GameViewID.prototype.read = function(input) {
4795 input.readStructBegin();
4796 while (true)
4797 {
4798 var ret = input.readFieldBegin();
4799 var fname = ret.fname;
4800 var ftype = ret.ftype;
4801 var fid = ret.fid;
4802 if (ftype == Thrift.Type.STOP) {
4803 break;
4804 }
4805 switch (fid)
4806 {
4807 case 1:
4808 if (ftype == Thrift.Type.I32) {
4809 this.ViewId = input.readI32().value;
4810 } else {
4811 input.skip(ftype);
4812 }
4813 break;
4814 case 2:
4815 if (ftype == Thrift.Type.I32) {
4816 this.LevelId = input.readI32().value;
4817 } else {
4818 input.skip(ftype);
4819 }
4820 break;
4821 default:
4822 input.skip(ftype);
4823 }
4824 input.readFieldEnd();
4825 }
4826 input.readStructEnd();
4827 return;
4828};
4829
4830GameViewID.prototype.write = function(output) {
4831 output.writeStructBegin('GameViewID');
4832 if (this.ViewId !== null && this.ViewId !== undefined) {
4833 output.writeFieldBegin('ViewId', Thrift.Type.I32, 1);
4834 output.writeI32(this.ViewId);
4835 output.writeFieldEnd();
4836 }
4837 if (this.LevelId !== null && this.LevelId !== undefined) {
4838 output.writeFieldBegin('LevelId', Thrift.Type.I32, 2);
4839 output.writeI32(this.LevelId);
4840 output.writeFieldEnd();
4841 }
4842 output.writeFieldStop();
4843 output.writeStructEnd();
4844 return;
4845};
4846
4847PackedSkeletonJointData = function(args) {
4848 this.PackedSkeletonJointFormat = null;
4849 this.DirtyJoints = null;
4850 this.JointPositionData = null;
4851 this.JointRotationData = null;
4852 if (args) {
4853 if (args.PackedSkeletonJointFormat !== undefined && args.PackedSkeletonJointFormat !== null) {
4854 this.PackedSkeletonJointFormat = args.PackedSkeletonJointFormat;
4855 } else {
4856 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field PackedSkeletonJointFormat is unset!');
4857 }
4858 if (args.DirtyJoints !== undefined && args.DirtyJoints !== null) {
4859 this.DirtyJoints = args.DirtyJoints;
4860 } else {
4861 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field DirtyJoints is unset!');
4862 }
4863 if (args.JointPositionData !== undefined && args.JointPositionData !== null) {
4864 this.JointPositionData = Thrift.copyList(args.JointPositionData, [null]);
4865 } else {
4866 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field JointPositionData is unset!');
4867 }
4868 if (args.JointRotationData !== undefined && args.JointRotationData !== null) {
4869 this.JointRotationData = Thrift.copyList(args.JointRotationData, [null]);
4870 } else {
4871 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field JointRotationData is unset!');
4872 }
4873 }
4874};
4875PackedSkeletonJointData.prototype = {};
4876PackedSkeletonJointData.prototype.read = function(input) {
4877 input.readStructBegin();
4878 while (true)
4879 {
4880 var ret = input.readFieldBegin();
4881 var fname = ret.fname;
4882 var ftype = ret.ftype;
4883 var fid = ret.fid;
4884 if (ftype == Thrift.Type.STOP) {
4885 break;
4886 }
4887 switch (fid)
4888 {
4889 case 1:
4890 if (ftype == Thrift.Type.BYTE) {
4891 this.PackedSkeletonJointFormat = input.readByte().value;
4892 } else {
4893 input.skip(ftype);
4894 }
4895 break;
4896 case 2:
4897 if (ftype == Thrift.Type.I64) {
4898 this.DirtyJoints = input.readI64().value;
4899 } else {
4900 input.skip(ftype);
4901 }
4902 break;
4903 case 3:
4904 if (ftype == Thrift.Type.LIST) {
4905 var _size0 = 0;
4906 var _rtmp34;
4907 this.JointPositionData = [];
4908 var _etype3 = 0;
4909 _rtmp34 = input.readListBegin();
4910 _etype3 = _rtmp34.etype;
4911 _size0 = _rtmp34.size;
4912 for (var _i5 = 0; _i5 < _size0; ++_i5)
4913 {
4914 var elem6 = null;
4915 elem6 = input.readByte().value;
4916 this.JointPositionData.push(elem6);
4917 }
4918 input.readListEnd();
4919 } else {
4920 input.skip(ftype);
4921 }
4922 break;
4923 case 4:
4924 if (ftype == Thrift.Type.LIST) {
4925 var _size7 = 0;
4926 var _rtmp311;
4927 this.JointRotationData = [];
4928 var _etype10 = 0;
4929 _rtmp311 = input.readListBegin();
4930 _etype10 = _rtmp311.etype;
4931 _size7 = _rtmp311.size;
4932 for (var _i12 = 0; _i12 < _size7; ++_i12)
4933 {
4934 var elem13 = null;
4935 elem13 = input.readByte().value;
4936 this.JointRotationData.push(elem13);
4937 }
4938 input.readListEnd();
4939 } else {
4940 input.skip(ftype);
4941 }
4942 break;
4943 default:
4944 input.skip(ftype);
4945 }
4946 input.readFieldEnd();
4947 }
4948 input.readStructEnd();
4949 return;
4950};
4951
4952PackedSkeletonJointData.prototype.write = function(output) {
4953 output.writeStructBegin('PackedSkeletonJointData');
4954 if (this.PackedSkeletonJointFormat !== null && this.PackedSkeletonJointFormat !== undefined) {
4955 output.writeFieldBegin('PackedSkeletonJointFormat', Thrift.Type.BYTE, 1);
4956 output.writeByte(this.PackedSkeletonJointFormat);
4957 output.writeFieldEnd();
4958 }
4959 if (this.DirtyJoints !== null && this.DirtyJoints !== undefined) {
4960 output.writeFieldBegin('DirtyJoints', Thrift.Type.I64, 2);
4961 output.writeI64(this.DirtyJoints);
4962 output.writeFieldEnd();
4963 }
4964 if (this.JointPositionData !== null && this.JointPositionData !== undefined) {
4965 output.writeFieldBegin('JointPositionData', Thrift.Type.LIST, 3);
4966 output.writeListBegin(Thrift.Type.BYTE, this.JointPositionData.length);
4967 for (var iter14 in this.JointPositionData)
4968 {
4969 if (this.JointPositionData.hasOwnProperty(iter14))
4970 {
4971 iter14 = this.JointPositionData[iter14];
4972 output.writeByte(iter14);
4973 }
4974 }
4975 output.writeListEnd();
4976 output.writeFieldEnd();
4977 }
4978 if (this.JointRotationData !== null && this.JointRotationData !== undefined) {
4979 output.writeFieldBegin('JointRotationData', Thrift.Type.LIST, 4);
4980 output.writeListBegin(Thrift.Type.BYTE, this.JointRotationData.length);
4981 for (var iter15 in this.JointRotationData)
4982 {
4983 if (this.JointRotationData.hasOwnProperty(iter15))
4984 {
4985 iter15 = this.JointRotationData[iter15];
4986 output.writeByte(iter15);
4987 }
4988 }
4989 output.writeListEnd();
4990 output.writeFieldEnd();
4991 }
4992 output.writeFieldStop();
4993 output.writeStructEnd();
4994 return;
4995};
4996
4997SkeletonJointsData = function(args) {
4998 this.PackedSkeletonJoints = null;
4999 if (args) {
5000 if (args.PackedSkeletonJoints !== undefined && args.PackedSkeletonJoints !== null) {
5001 this.PackedSkeletonJoints = new PackedSkeletonJointData(args.PackedSkeletonJoints);
5002 }
5003 }
5004};
5005SkeletonJointsData.prototype = {};
5006SkeletonJointsData.prototype.read = function(input) {
5007 input.readStructBegin();
5008 while (true)
5009 {
5010 var ret = input.readFieldBegin();
5011 var fname = ret.fname;
5012 var ftype = ret.ftype;
5013 var fid = ret.fid;
5014 if (ftype == Thrift.Type.STOP) {
5015 break;
5016 }
5017 switch (fid)
5018 {
5019 case 1:
5020 if (ftype == Thrift.Type.STRUCT) {
5021 this.PackedSkeletonJoints = new PackedSkeletonJointData();
5022 this.PackedSkeletonJoints.read(input);
5023 } else {
5024 input.skip(ftype);
5025 }
5026 break;
5027 case 0:
5028 input.skip(ftype);
5029 break;
5030 default:
5031 input.skip(ftype);
5032 }
5033 input.readFieldEnd();
5034 }
5035 input.readStructEnd();
5036 return;
5037};
5038
5039SkeletonJointsData.prototype.write = function(output) {
5040 output.writeStructBegin('SkeletonJointsData');
5041 if (this.PackedSkeletonJoints !== null && this.PackedSkeletonJoints !== undefined) {
5042 output.writeFieldBegin('PackedSkeletonJoints', Thrift.Type.STRUCT, 1);
5043 this.PackedSkeletonJoints.write(output);
5044 output.writeFieldEnd();
5045 }
5046 output.writeFieldStop();
5047 output.writeStructEnd();
5048 return;
5049};
5050
5051SkeletonFrameData = function(args) {
5052 this.CenterEyeTransform = null;
5053 this.NeckTransform = null;
5054 this.LeftHandState = null;
5055 this.RightHandState = null;
5056 this.SkeletonJoints = null;
5057 if (args) {
5058 if (args.CenterEyeTransform !== undefined && args.CenterEyeTransform !== null) {
5059 this.CenterEyeTransform = new TransformData(args.CenterEyeTransform);
5060 }
5061 if (args.NeckTransform !== undefined && args.NeckTransform !== null) {
5062 this.NeckTransform = new TransformData(args.NeckTransform);
5063 }
5064 if (args.LeftHandState !== undefined && args.LeftHandState !== null) {
5065 this.LeftHandState = args.LeftHandState;
5066 }
5067 if (args.RightHandState !== undefined && args.RightHandState !== null) {
5068 this.RightHandState = args.RightHandState;
5069 }
5070 if (args.SkeletonJoints !== undefined && args.SkeletonJoints !== null) {
5071 this.SkeletonJoints = new SkeletonJointsData(args.SkeletonJoints);
5072 }
5073 }
5074};
5075SkeletonFrameData.prototype = {};
5076SkeletonFrameData.prototype.read = function(input) {
5077 input.readStructBegin();
5078 while (true)
5079 {
5080 var ret = input.readFieldBegin();
5081 var fname = ret.fname;
5082 var ftype = ret.ftype;
5083 var fid = ret.fid;
5084 if (ftype == Thrift.Type.STOP) {
5085 break;
5086 }
5087 switch (fid)
5088 {
5089 case 1:
5090 if (ftype == Thrift.Type.STRUCT) {
5091 this.CenterEyeTransform = new TransformData();
5092 this.CenterEyeTransform.read(input);
5093 } else {
5094 input.skip(ftype);
5095 }
5096 break;
5097 case 2:
5098 if (ftype == Thrift.Type.STRUCT) {
5099 this.NeckTransform = new TransformData();
5100 this.NeckTransform.read(input);
5101 } else {
5102 input.skip(ftype);
5103 }
5104 break;
5105 case 3:
5106 if (ftype == Thrift.Type.I32) {
5107 this.LeftHandState = input.readI32().value;
5108 } else {
5109 input.skip(ftype);
5110 }
5111 break;
5112 case 4:
5113 if (ftype == Thrift.Type.I32) {
5114 this.RightHandState = input.readI32().value;
5115 } else {
5116 input.skip(ftype);
5117 }
5118 break;
5119 case 5:
5120 if (ftype == Thrift.Type.STRUCT) {
5121 this.SkeletonJoints = new SkeletonJointsData();
5122 this.SkeletonJoints.read(input);
5123 } else {
5124 input.skip(ftype);
5125 }
5126 break;
5127 default:
5128 input.skip(ftype);
5129 }
5130 input.readFieldEnd();
5131 }
5132 input.readStructEnd();
5133 return;
5134};
5135
5136SkeletonFrameData.prototype.write = function(output) {
5137 output.writeStructBegin('SkeletonFrameData');
5138 if (this.CenterEyeTransform !== null && this.CenterEyeTransform !== undefined) {
5139 output.writeFieldBegin('CenterEyeTransform', Thrift.Type.STRUCT, 1);
5140 this.CenterEyeTransform.write(output);
5141 output.writeFieldEnd();
5142 }
5143 if (this.NeckTransform !== null && this.NeckTransform !== undefined) {
5144 output.writeFieldBegin('NeckTransform', Thrift.Type.STRUCT, 2);
5145 this.NeckTransform.write(output);
5146 output.writeFieldEnd();
5147 }
5148 if (this.LeftHandState !== null && this.LeftHandState !== undefined) {
5149 output.writeFieldBegin('LeftHandState', Thrift.Type.I32, 3);
5150 output.writeI32(this.LeftHandState);
5151 output.writeFieldEnd();
5152 }
5153 if (this.RightHandState !== null && this.RightHandState !== undefined) {
5154 output.writeFieldBegin('RightHandState', Thrift.Type.I32, 4);
5155 output.writeI32(this.RightHandState);
5156 output.writeFieldEnd();
5157 }
5158 if (this.SkeletonJoints !== null && this.SkeletonJoints !== undefined) {
5159 output.writeFieldBegin('SkeletonJoints', Thrift.Type.STRUCT, 5);
5160 this.SkeletonJoints.write(output);
5161 output.writeFieldEnd();
5162 }
5163 output.writeFieldStop();
5164 output.writeStructEnd();
5165 return;
5166};
5167
5168AvatarIndexFormFrameData = function(args) {
5169 this.AvatarIndex = null;
5170 if (args) {
5171 if (args.AvatarIndex !== undefined && args.AvatarIndex !== null) {
5172 this.AvatarIndex = args.AvatarIndex;
5173 }
5174 }
5175};
5176AvatarIndexFormFrameData.prototype = {};
5177AvatarIndexFormFrameData.prototype.read = function(input) {
5178 input.readStructBegin();
5179 while (true)
5180 {
5181 var ret = input.readFieldBegin();
5182 var fname = ret.fname;
5183 var ftype = ret.ftype;
5184 var fid = ret.fid;
5185 if (ftype == Thrift.Type.STOP) {
5186 break;
5187 }
5188 switch (fid)
5189 {
5190 case 1:
5191 if (ftype == Thrift.Type.I32) {
5192 this.AvatarIndex = input.readI32().value;
5193 } else {
5194 input.skip(ftype);
5195 }
5196 break;
5197 case 0:
5198 input.skip(ftype);
5199 break;
5200 default:
5201 input.skip(ftype);
5202 }
5203 input.readFieldEnd();
5204 }
5205 input.readStructEnd();
5206 return;
5207};
5208
5209AvatarIndexFormFrameData.prototype.write = function(output) {
5210 output.writeStructBegin('AvatarIndexFormFrameData');
5211 if (this.AvatarIndex !== null && this.AvatarIndex !== undefined) {
5212 output.writeFieldBegin('AvatarIndex', Thrift.Type.I32, 1);
5213 output.writeI32(this.AvatarIndex);
5214 output.writeFieldEnd();
5215 }
5216 output.writeFieldStop();
5217 output.writeStructEnd();
5218 return;
5219};
5220
5221FormFrame = function(args) {
5222 this.AvatarIndexFormFrame = null;
5223 if (args) {
5224 if (args.AvatarIndexFormFrame !== undefined && args.AvatarIndexFormFrame !== null) {
5225 this.AvatarIndexFormFrame = new AvatarIndexFormFrameData(args.AvatarIndexFormFrame);
5226 }
5227 }
5228};
5229FormFrame.prototype = {};
5230FormFrame.prototype.read = function(input) {
5231 input.readStructBegin();
5232 while (true)
5233 {
5234 var ret = input.readFieldBegin();
5235 var fname = ret.fname;
5236 var ftype = ret.ftype;
5237 var fid = ret.fid;
5238 if (ftype == Thrift.Type.STOP) {
5239 break;
5240 }
5241 switch (fid)
5242 {
5243 case 1:
5244 if (ftype == Thrift.Type.STRUCT) {
5245 this.AvatarIndexFormFrame = new AvatarIndexFormFrameData();
5246 this.AvatarIndexFormFrame.read(input);
5247 } else {
5248 input.skip(ftype);
5249 }
5250 break;
5251 case 0:
5252 input.skip(ftype);
5253 break;
5254 default:
5255 input.skip(ftype);
5256 }
5257 input.readFieldEnd();
5258 }
5259 input.readStructEnd();
5260 return;
5261};
5262
5263FormFrame.prototype.write = function(output) {
5264 output.writeStructBegin('FormFrame');
5265 if (this.AvatarIndexFormFrame !== null && this.AvatarIndexFormFrame !== undefined) {
5266 output.writeFieldBegin('AvatarIndexFormFrame', Thrift.Type.STRUCT, 1);
5267 this.AvatarIndexFormFrame.write(output);
5268 output.writeFieldEnd();
5269 }
5270 output.writeFieldStop();
5271 output.writeStructEnd();
5272 return;
5273};
5274
5275WandTransformFrameData = function(args) {
5276 this.LeftWandExists = null;
5277 this.RightWandExists = null;
5278 this.LeftWandTransform = null;
5279 this.RightWandTransform = null;
5280 if (args) {
5281 if (args.LeftWandExists !== undefined && args.LeftWandExists !== null) {
5282 this.LeftWandExists = args.LeftWandExists;
5283 } else {
5284 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field LeftWandExists is unset!');
5285 }
5286 if (args.RightWandExists !== undefined && args.RightWandExists !== null) {
5287 this.RightWandExists = args.RightWandExists;
5288 } else {
5289 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field RightWandExists is unset!');
5290 }
5291 if (args.LeftWandTransform !== undefined && args.LeftWandTransform !== null) {
5292 this.LeftWandTransform = new TransformData(args.LeftWandTransform);
5293 }
5294 if (args.RightWandTransform !== undefined && args.RightWandTransform !== null) {
5295 this.RightWandTransform = new TransformData(args.RightWandTransform);
5296 }
5297 }
5298};
5299WandTransformFrameData.prototype = {};
5300WandTransformFrameData.prototype.read = function(input) {
5301 input.readStructBegin();
5302 while (true)
5303 {
5304 var ret = input.readFieldBegin();
5305 var fname = ret.fname;
5306 var ftype = ret.ftype;
5307 var fid = ret.fid;
5308 if (ftype == Thrift.Type.STOP) {
5309 break;
5310 }
5311 switch (fid)
5312 {
5313 case 1:
5314 if (ftype == Thrift.Type.BOOL) {
5315 this.LeftWandExists = input.readBool().value;
5316 } else {
5317 input.skip(ftype);
5318 }
5319 break;
5320 case 2:
5321 if (ftype == Thrift.Type.BOOL) {
5322 this.RightWandExists = input.readBool().value;
5323 } else {
5324 input.skip(ftype);
5325 }
5326 break;
5327 case 3:
5328 if (ftype == Thrift.Type.STRUCT) {
5329 this.LeftWandTransform = new TransformData();
5330 this.LeftWandTransform.read(input);
5331 } else {
5332 input.skip(ftype);
5333 }
5334 break;
5335 case 4:
5336 if (ftype == Thrift.Type.STRUCT) {
5337 this.RightWandTransform = new TransformData();
5338 this.RightWandTransform.read(input);
5339 } else {
5340 input.skip(ftype);
5341 }
5342 break;
5343 default:
5344 input.skip(ftype);
5345 }
5346 input.readFieldEnd();
5347 }
5348 input.readStructEnd();
5349 return;
5350};
5351
5352WandTransformFrameData.prototype.write = function(output) {
5353 output.writeStructBegin('WandTransformFrameData');
5354 if (this.LeftWandExists !== null && this.LeftWandExists !== undefined) {
5355 output.writeFieldBegin('LeftWandExists', Thrift.Type.BOOL, 1);
5356 output.writeBool(this.LeftWandExists);
5357 output.writeFieldEnd();
5358 }
5359 if (this.RightWandExists !== null && this.RightWandExists !== undefined) {
5360 output.writeFieldBegin('RightWandExists', Thrift.Type.BOOL, 2);
5361 output.writeBool(this.RightWandExists);
5362 output.writeFieldEnd();
5363 }
5364 if (this.LeftWandTransform !== null && this.LeftWandTransform !== undefined) {
5365 output.writeFieldBegin('LeftWandTransform', Thrift.Type.STRUCT, 3);
5366 this.LeftWandTransform.write(output);
5367 output.writeFieldEnd();
5368 }
5369 if (this.RightWandTransform !== null && this.RightWandTransform !== undefined) {
5370 output.writeFieldBegin('RightWandTransform', Thrift.Type.STRUCT, 4);
5371 this.RightWandTransform.write(output);
5372 output.writeFieldEnd();
5373 }
5374 output.writeFieldStop();
5375 output.writeStructEnd();
5376 return;
5377};
5378
5379WandFrame = function(args) {
5380 this.WandTransformFrame = null;
5381 if (args) {
5382 if (args.WandTransformFrame !== undefined && args.WandTransformFrame !== null) {
5383 this.WandTransformFrame = new WandTransformFrameData(args.WandTransformFrame);
5384 }
5385 }
5386};
5387WandFrame.prototype = {};
5388WandFrame.prototype.read = function(input) {
5389 input.readStructBegin();
5390 while (true)
5391 {
5392 var ret = input.readFieldBegin();
5393 var fname = ret.fname;
5394 var ftype = ret.ftype;
5395 var fid = ret.fid;
5396 if (ftype == Thrift.Type.STOP) {
5397 break;
5398 }
5399 switch (fid)
5400 {
5401 case 1:
5402 if (ftype == Thrift.Type.STRUCT) {
5403 this.WandTransformFrame = new WandTransformFrameData();
5404 this.WandTransformFrame.read(input);
5405 } else {
5406 input.skip(ftype);
5407 }
5408 break;
5409 case 0:
5410 input.skip(ftype);
5411 break;
5412 default:
5413 input.skip(ftype);
5414 }
5415 input.readFieldEnd();
5416 }
5417 input.readStructEnd();
5418 return;
5419};
5420
5421WandFrame.prototype.write = function(output) {
5422 output.writeStructBegin('WandFrame');
5423 if (this.WandTransformFrame !== null && this.WandTransformFrame !== undefined) {
5424 output.writeFieldBegin('WandTransformFrame', Thrift.Type.STRUCT, 1);
5425 this.WandTransformFrame.write(output);
5426 output.writeFieldEnd();
5427 }
5428 output.writeFieldStop();
5429 output.writeStructEnd();
5430 return;
5431};
5432
5433AvatarFrameData = function(args) {
5434 this.SkeletonFrame = null;
5435 this.FormFrame = null;
5436 this.WandFrame = null;
5437 if (args) {
5438 if (args.SkeletonFrame !== undefined && args.SkeletonFrame !== null) {
5439 this.SkeletonFrame = new SkeletonFrameData(args.SkeletonFrame);
5440 } else {
5441 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field SkeletonFrame is unset!');
5442 }
5443 if (args.FormFrame !== undefined && args.FormFrame !== null) {
5444 this.FormFrame = new FormFrame(args.FormFrame);
5445 } else {
5446 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field FormFrame is unset!');
5447 }
5448 if (args.WandFrame !== undefined && args.WandFrame !== null) {
5449 this.WandFrame = new WandFrame(args.WandFrame);
5450 }
5451 }
5452};
5453AvatarFrameData.prototype = {};
5454AvatarFrameData.prototype.read = function(input) {
5455 input.readStructBegin();
5456 while (true)
5457 {
5458 var ret = input.readFieldBegin();
5459 var fname = ret.fname;
5460 var ftype = ret.ftype;
5461 var fid = ret.fid;
5462 if (ftype == Thrift.Type.STOP) {
5463 break;
5464 }
5465 switch (fid)
5466 {
5467 case 1:
5468 if (ftype == Thrift.Type.STRUCT) {
5469 this.SkeletonFrame = new SkeletonFrameData();
5470 this.SkeletonFrame.read(input);
5471 } else {
5472 input.skip(ftype);
5473 }
5474 break;
5475 case 2:
5476 if (ftype == Thrift.Type.STRUCT) {
5477 this.FormFrame = new FormFrame();
5478 this.FormFrame.read(input);
5479 } else {
5480 input.skip(ftype);
5481 }
5482 break;
5483 case 3:
5484 if (ftype == Thrift.Type.STRUCT) {
5485 this.WandFrame = new WandFrame();
5486 this.WandFrame.read(input);
5487 } else {
5488 input.skip(ftype);
5489 }
5490 break;
5491 default:
5492 input.skip(ftype);
5493 }
5494 input.readFieldEnd();
5495 }
5496 input.readStructEnd();
5497 return;
5498};
5499
5500AvatarFrameData.prototype.write = function(output) {
5501 output.writeStructBegin('AvatarFrameData');
5502 if (this.SkeletonFrame !== null && this.SkeletonFrame !== undefined) {
5503 output.writeFieldBegin('SkeletonFrame', Thrift.Type.STRUCT, 1);
5504 this.SkeletonFrame.write(output);
5505 output.writeFieldEnd();
5506 }
5507 if (this.FormFrame !== null && this.FormFrame !== undefined) {
5508 output.writeFieldBegin('FormFrame', Thrift.Type.STRUCT, 2);
5509 this.FormFrame.write(output);
5510 output.writeFieldEnd();
5511 }
5512 if (this.WandFrame !== null && this.WandFrame !== undefined) {
5513 output.writeFieldBegin('WandFrame', Thrift.Type.STRUCT, 3);
5514 this.WandFrame.write(output);
5515 output.writeFieldEnd();
5516 }
5517 output.writeFieldStop();
5518 output.writeStructEnd();
5519 return;
5520};
5521
5522TwoToneAvatarInfoFrameData = function(args) {
5523 this.AvatarSid = null;
5524 this.PrimaryColors = null;
5525 this.HighlightColors = null;
5526 if (args) {
5527 if (args.AvatarSid !== undefined && args.AvatarSid !== null) {
5528 this.AvatarSid = args.AvatarSid;
5529 } else {
5530 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field AvatarSid is unset!');
5531 }
5532 if (args.PrimaryColors !== undefined && args.PrimaryColors !== null) {
5533 this.PrimaryColors = Thrift.copyList(args.PrimaryColors, [null]);
5534 } else {
5535 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field PrimaryColors is unset!');
5536 }
5537 if (args.HighlightColors !== undefined && args.HighlightColors !== null) {
5538 this.HighlightColors = Thrift.copyList(args.HighlightColors, [null]);
5539 } else {
5540 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field HighlightColors is unset!');
5541 }
5542 }
5543};
5544TwoToneAvatarInfoFrameData.prototype = {};
5545TwoToneAvatarInfoFrameData.prototype.read = function(input) {
5546 input.readStructBegin();
5547 while (true)
5548 {
5549 var ret = input.readFieldBegin();
5550 var fname = ret.fname;
5551 var ftype = ret.ftype;
5552 var fid = ret.fid;
5553 if (ftype == Thrift.Type.STOP) {
5554 break;
5555 }
5556 switch (fid)
5557 {
5558 case 1:
5559 if (ftype == Thrift.Type.STRING) {
5560 this.AvatarSid = input.readString().value;
5561 } else {
5562 input.skip(ftype);
5563 }
5564 break;
5565 case 2:
5566 if (ftype == Thrift.Type.LIST) {
5567 var _size16 = 0;
5568 var _rtmp320;
5569 this.PrimaryColors = [];
5570 var _etype19 = 0;
5571 _rtmp320 = input.readListBegin();
5572 _etype19 = _rtmp320.etype;
5573 _size16 = _rtmp320.size;
5574 for (var _i21 = 0; _i21 < _size16; ++_i21)
5575 {
5576 var elem22 = null;
5577 elem22 = input.readDouble().value;
5578 this.PrimaryColors.push(elem22);
5579 }
5580 input.readListEnd();
5581 } else {
5582 input.skip(ftype);
5583 }
5584 break;
5585 case 3:
5586 if (ftype == Thrift.Type.LIST) {
5587 var _size23 = 0;
5588 var _rtmp327;
5589 this.HighlightColors = [];
5590 var _etype26 = 0;
5591 _rtmp327 = input.readListBegin();
5592 _etype26 = _rtmp327.etype;
5593 _size23 = _rtmp327.size;
5594 for (var _i28 = 0; _i28 < _size23; ++_i28)
5595 {
5596 var elem29 = null;
5597 elem29 = input.readDouble().value;
5598 this.HighlightColors.push(elem29);
5599 }
5600 input.readListEnd();
5601 } else {
5602 input.skip(ftype);
5603 }
5604 break;
5605 default:
5606 input.skip(ftype);
5607 }
5608 input.readFieldEnd();
5609 }
5610 input.readStructEnd();
5611 return;
5612};
5613
5614TwoToneAvatarInfoFrameData.prototype.write = function(output) {
5615 output.writeStructBegin('TwoToneAvatarInfoFrameData');
5616 if (this.AvatarSid !== null && this.AvatarSid !== undefined) {
5617 output.writeFieldBegin('AvatarSid', Thrift.Type.STRING, 1);
5618 output.writeString(this.AvatarSid);
5619 output.writeFieldEnd();
5620 }
5621 if (this.PrimaryColors !== null && this.PrimaryColors !== undefined) {
5622 output.writeFieldBegin('PrimaryColors', Thrift.Type.LIST, 2);
5623 output.writeListBegin(Thrift.Type.DOUBLE, this.PrimaryColors.length);
5624 for (var iter30 in this.PrimaryColors)
5625 {
5626 if (this.PrimaryColors.hasOwnProperty(iter30))
5627 {
5628 iter30 = this.PrimaryColors[iter30];
5629 output.writeDouble(iter30);
5630 }
5631 }
5632 output.writeListEnd();
5633 output.writeFieldEnd();
5634 }
5635 if (this.HighlightColors !== null && this.HighlightColors !== undefined) {
5636 output.writeFieldBegin('HighlightColors', Thrift.Type.LIST, 3);
5637 output.writeListBegin(Thrift.Type.DOUBLE, this.HighlightColors.length);
5638 for (var iter31 in this.HighlightColors)
5639 {
5640 if (this.HighlightColors.hasOwnProperty(iter31))
5641 {
5642 iter31 = this.HighlightColors[iter31];
5643 output.writeDouble(iter31);
5644 }
5645 }
5646 output.writeListEnd();
5647 output.writeFieldEnd();
5648 }
5649 output.writeFieldStop();
5650 output.writeStructEnd();
5651 return;
5652};
5653
5654NoCustomizationAvatarInfoFrameData = function(args) {
5655 this.AvatarSid = null;
5656 if (args) {
5657 if (args.AvatarSid !== undefined && args.AvatarSid !== null) {
5658 this.AvatarSid = args.AvatarSid;
5659 } else {
5660 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field AvatarSid is unset!');
5661 }
5662 }
5663};
5664NoCustomizationAvatarInfoFrameData.prototype = {};
5665NoCustomizationAvatarInfoFrameData.prototype.read = function(input) {
5666 input.readStructBegin();
5667 while (true)
5668 {
5669 var ret = input.readFieldBegin();
5670 var fname = ret.fname;
5671 var ftype = ret.ftype;
5672 var fid = ret.fid;
5673 if (ftype == Thrift.Type.STOP) {
5674 break;
5675 }
5676 switch (fid)
5677 {
5678 case 1:
5679 if (ftype == Thrift.Type.STRING) {
5680 this.AvatarSid = input.readString().value;
5681 } else {
5682 input.skip(ftype);
5683 }
5684 break;
5685 case 0:
5686 input.skip(ftype);
5687 break;
5688 default:
5689 input.skip(ftype);
5690 }
5691 input.readFieldEnd();
5692 }
5693 input.readStructEnd();
5694 return;
5695};
5696
5697NoCustomizationAvatarInfoFrameData.prototype.write = function(output) {
5698 output.writeStructBegin('NoCustomizationAvatarInfoFrameData');
5699 if (this.AvatarSid !== null && this.AvatarSid !== undefined) {
5700 output.writeFieldBegin('AvatarSid', Thrift.Type.STRING, 1);
5701 output.writeString(this.AvatarSid);
5702 output.writeFieldEnd();
5703 }
5704 output.writeFieldStop();
5705 output.writeStructEnd();
5706 return;
5707};
5708
5709ThreeTextureAvatarInfoFrameData = function(args) {
5710 this.AvatarSid = null;
5711 this.Texture1 = null;
5712 this.Texture2 = null;
5713 this.Texture3 = null;
5714 if (args) {
5715 if (args.AvatarSid !== undefined && args.AvatarSid !== null) {
5716 this.AvatarSid = args.AvatarSid;
5717 } else {
5718 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field AvatarSid is unset!');
5719 }
5720 if (args.Texture1 !== undefined && args.Texture1 !== null) {
5721 this.Texture1 = args.Texture1;
5722 } else {
5723 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Texture1 is unset!');
5724 }
5725 if (args.Texture2 !== undefined && args.Texture2 !== null) {
5726 this.Texture2 = args.Texture2;
5727 } else {
5728 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Texture2 is unset!');
5729 }
5730 if (args.Texture3 !== undefined && args.Texture3 !== null) {
5731 this.Texture3 = args.Texture3;
5732 } else {
5733 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Texture3 is unset!');
5734 }
5735 }
5736};
5737ThreeTextureAvatarInfoFrameData.prototype = {};
5738ThreeTextureAvatarInfoFrameData.prototype.read = function(input) {
5739 input.readStructBegin();
5740 while (true)
5741 {
5742 var ret = input.readFieldBegin();
5743 var fname = ret.fname;
5744 var ftype = ret.ftype;
5745 var fid = ret.fid;
5746 if (ftype == Thrift.Type.STOP) {
5747 break;
5748 }
5749 switch (fid)
5750 {
5751 case 1:
5752 if (ftype == Thrift.Type.STRING) {
5753 this.AvatarSid = input.readString().value;
5754 } else {
5755 input.skip(ftype);
5756 }
5757 break;
5758 case 2:
5759 if (ftype == Thrift.Type.STRING) {
5760 this.Texture1 = input.readString().value;
5761 } else {
5762 input.skip(ftype);
5763 }
5764 break;
5765 case 3:
5766 if (ftype == Thrift.Type.STRING) {
5767 this.Texture2 = input.readString().value;
5768 } else {
5769 input.skip(ftype);
5770 }
5771 break;
5772 case 4:
5773 if (ftype == Thrift.Type.STRING) {
5774 this.Texture3 = input.readString().value;
5775 } else {
5776 input.skip(ftype);
5777 }
5778 break;
5779 default:
5780 input.skip(ftype);
5781 }
5782 input.readFieldEnd();
5783 }
5784 input.readStructEnd();
5785 return;
5786};
5787
5788ThreeTextureAvatarInfoFrameData.prototype.write = function(output) {
5789 output.writeStructBegin('ThreeTextureAvatarInfoFrameData');
5790 if (this.AvatarSid !== null && this.AvatarSid !== undefined) {
5791 output.writeFieldBegin('AvatarSid', Thrift.Type.STRING, 1);
5792 output.writeString(this.AvatarSid);
5793 output.writeFieldEnd();
5794 }
5795 if (this.Texture1 !== null && this.Texture1 !== undefined) {
5796 output.writeFieldBegin('Texture1', Thrift.Type.STRING, 2);
5797 output.writeString(this.Texture1);
5798 output.writeFieldEnd();
5799 }
5800 if (this.Texture2 !== null && this.Texture2 !== undefined) {
5801 output.writeFieldBegin('Texture2', Thrift.Type.STRING, 3);
5802 output.writeString(this.Texture2);
5803 output.writeFieldEnd();
5804 }
5805 if (this.Texture3 !== null && this.Texture3 !== undefined) {
5806 output.writeFieldBegin('Texture3', Thrift.Type.STRING, 4);
5807 output.writeString(this.Texture3);
5808 output.writeFieldEnd();
5809 }
5810 output.writeFieldStop();
5811 output.writeStructEnd();
5812 return;
5813};
5814
5815PlayerAvatarInfoFrame = function(args) {
5816 this.TwoToneAvatarInfoFrame = null;
5817 this.NoCustomizationAvatarInfoFrame = null;
5818 this.ThreeTextureAvatarInfoFrame = null;
5819 if (args) {
5820 if (args.TwoToneAvatarInfoFrame !== undefined && args.TwoToneAvatarInfoFrame !== null) {
5821 this.TwoToneAvatarInfoFrame = new TwoToneAvatarInfoFrameData(args.TwoToneAvatarInfoFrame);
5822 }
5823 if (args.NoCustomizationAvatarInfoFrame !== undefined && args.NoCustomizationAvatarInfoFrame !== null) {
5824 this.NoCustomizationAvatarInfoFrame = new NoCustomizationAvatarInfoFrameData(args.NoCustomizationAvatarInfoFrame);
5825 }
5826 if (args.ThreeTextureAvatarInfoFrame !== undefined && args.ThreeTextureAvatarInfoFrame !== null) {
5827 this.ThreeTextureAvatarInfoFrame = new ThreeTextureAvatarInfoFrameData(args.ThreeTextureAvatarInfoFrame);
5828 }
5829 }
5830};
5831PlayerAvatarInfoFrame.prototype = {};
5832PlayerAvatarInfoFrame.prototype.read = function(input) {
5833 input.readStructBegin();
5834 while (true)
5835 {
5836 var ret = input.readFieldBegin();
5837 var fname = ret.fname;
5838 var ftype = ret.ftype;
5839 var fid = ret.fid;
5840 if (ftype == Thrift.Type.STOP) {
5841 break;
5842 }
5843 switch (fid)
5844 {
5845 case 1:
5846 if (ftype == Thrift.Type.STRUCT) {
5847 this.TwoToneAvatarInfoFrame = new TwoToneAvatarInfoFrameData();
5848 this.TwoToneAvatarInfoFrame.read(input);
5849 } else {
5850 input.skip(ftype);
5851 }
5852 break;
5853 case 2:
5854 if (ftype == Thrift.Type.STRUCT) {
5855 this.NoCustomizationAvatarInfoFrame = new NoCustomizationAvatarInfoFrameData();
5856 this.NoCustomizationAvatarInfoFrame.read(input);
5857 } else {
5858 input.skip(ftype);
5859 }
5860 break;
5861 case 3:
5862 if (ftype == Thrift.Type.STRUCT) {
5863 this.ThreeTextureAvatarInfoFrame = new ThreeTextureAvatarInfoFrameData();
5864 this.ThreeTextureAvatarInfoFrame.read(input);
5865 } else {
5866 input.skip(ftype);
5867 }
5868 break;
5869 default:
5870 input.skip(ftype);
5871 }
5872 input.readFieldEnd();
5873 }
5874 input.readStructEnd();
5875 return;
5876};
5877
5878PlayerAvatarInfoFrame.prototype.write = function(output) {
5879 output.writeStructBegin('PlayerAvatarInfoFrame');
5880 if (this.TwoToneAvatarInfoFrame !== null && this.TwoToneAvatarInfoFrame !== undefined) {
5881 output.writeFieldBegin('TwoToneAvatarInfoFrame', Thrift.Type.STRUCT, 1);
5882 this.TwoToneAvatarInfoFrame.write(output);
5883 output.writeFieldEnd();
5884 }
5885 if (this.NoCustomizationAvatarInfoFrame !== null && this.NoCustomizationAvatarInfoFrame !== undefined) {
5886 output.writeFieldBegin('NoCustomizationAvatarInfoFrame', Thrift.Type.STRUCT, 2);
5887 this.NoCustomizationAvatarInfoFrame.write(output);
5888 output.writeFieldEnd();
5889 }
5890 if (this.ThreeTextureAvatarInfoFrame !== null && this.ThreeTextureAvatarInfoFrame !== undefined) {
5891 output.writeFieldBegin('ThreeTextureAvatarInfoFrame', Thrift.Type.STRUCT, 3);
5892 this.ThreeTextureAvatarInfoFrame.write(output);
5893 output.writeFieldEnd();
5894 }
5895 output.writeFieldStop();
5896 output.writeStructEnd();
5897 return;
5898};
5899
5900PlayerInfoFrameData = function(args) {
5901 this.Name = null;
5902 this.IsAdmin = null;
5903 this.AvatarInfoFrame = null;
5904 if (args) {
5905 if (args.Name !== undefined && args.Name !== null) {
5906 this.Name = args.Name;
5907 }
5908 if (args.IsAdmin !== undefined && args.IsAdmin !== null) {
5909 this.IsAdmin = args.IsAdmin;
5910 }
5911 if (args.AvatarInfoFrame !== undefined && args.AvatarInfoFrame !== null) {
5912 this.AvatarInfoFrame = new PlayerAvatarInfoFrame(args.AvatarInfoFrame);
5913 }
5914 }
5915};
5916PlayerInfoFrameData.prototype = {};
5917PlayerInfoFrameData.prototype.read = function(input) {
5918 input.readStructBegin();
5919 while (true)
5920 {
5921 var ret = input.readFieldBegin();
5922 var fname = ret.fname;
5923 var ftype = ret.ftype;
5924 var fid = ret.fid;
5925 if (ftype == Thrift.Type.STOP) {
5926 break;
5927 }
5928 switch (fid)
5929 {
5930 case 1:
5931 if (ftype == Thrift.Type.STRING) {
5932 this.Name = input.readString().value;
5933 } else {
5934 input.skip(ftype);
5935 }
5936 break;
5937 case 2:
5938 if (ftype == Thrift.Type.BOOL) {
5939 this.IsAdmin = input.readBool().value;
5940 } else {
5941 input.skip(ftype);
5942 }
5943 break;
5944 case 3:
5945 if (ftype == Thrift.Type.STRUCT) {
5946 this.AvatarInfoFrame = new PlayerAvatarInfoFrame();
5947 this.AvatarInfoFrame.read(input);
5948 } else {
5949 input.skip(ftype);
5950 }
5951 break;
5952 default:
5953 input.skip(ftype);
5954 }
5955 input.readFieldEnd();
5956 }
5957 input.readStructEnd();
5958 return;
5959};
5960
5961PlayerInfoFrameData.prototype.write = function(output) {
5962 output.writeStructBegin('PlayerInfoFrameData');
5963 if (this.Name !== null && this.Name !== undefined) {
5964 output.writeFieldBegin('Name', Thrift.Type.STRING, 1);
5965 output.writeString(this.Name);
5966 output.writeFieldEnd();
5967 }
5968 if (this.IsAdmin !== null && this.IsAdmin !== undefined) {
5969 output.writeFieldBegin('IsAdmin', Thrift.Type.BOOL, 2);
5970 output.writeBool(this.IsAdmin);
5971 output.writeFieldEnd();
5972 }
5973 if (this.AvatarInfoFrame !== null && this.AvatarInfoFrame !== undefined) {
5974 output.writeFieldBegin('AvatarInfoFrame', Thrift.Type.STRUCT, 3);
5975 this.AvatarInfoFrame.write(output);
5976 output.writeFieldEnd();
5977 }
5978 output.writeFieldStop();
5979 output.writeStructEnd();
5980 return;
5981};
5982
5983VoiceFrameData = function(args) {
5984 this.VoiceCodec = null;
5985 this.Bitrate = null;
5986 this.PacketFormat = null;
5987 this.VoicePacketHeader = null;
5988 this.VoicePacketFrame = null;
5989 if (args) {
5990 if (args.VoiceCodec !== undefined && args.VoiceCodec !== null) {
5991 this.VoiceCodec = args.VoiceCodec;
5992 } else {
5993 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field VoiceCodec is unset!');
5994 }
5995 if (args.Bitrate !== undefined && args.Bitrate !== null) {
5996 this.Bitrate = args.Bitrate;
5997 } else {
5998 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Bitrate is unset!');
5999 }
6000 if (args.PacketFormat !== undefined && args.PacketFormat !== null) {
6001 this.PacketFormat = args.PacketFormat;
6002 } else {
6003 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field PacketFormat is unset!');
6004 }
6005 if (args.VoicePacketHeader !== undefined && args.VoicePacketHeader !== null) {
6006 this.VoicePacketHeader = Thrift.copyList(args.VoicePacketHeader, [null]);
6007 } else {
6008 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field VoicePacketHeader is unset!');
6009 }
6010 if (args.VoicePacketFrame !== undefined && args.VoicePacketFrame !== null) {
6011 this.VoicePacketFrame = Thrift.copyList(args.VoicePacketFrame, [null]);
6012 } else {
6013 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field VoicePacketFrame is unset!');
6014 }
6015 }
6016};
6017VoiceFrameData.prototype = {};
6018VoiceFrameData.prototype.read = function(input) {
6019 input.readStructBegin();
6020 while (true)
6021 {
6022 var ret = input.readFieldBegin();
6023 var fname = ret.fname;
6024 var ftype = ret.ftype;
6025 var fid = ret.fid;
6026 if (ftype == Thrift.Type.STOP) {
6027 break;
6028 }
6029 switch (fid)
6030 {
6031 case 1:
6032 if (ftype == Thrift.Type.I32) {
6033 this.VoiceCodec = input.readI32().value;
6034 } else {
6035 input.skip(ftype);
6036 }
6037 break;
6038 case 2:
6039 if (ftype == Thrift.Type.I32) {
6040 this.Bitrate = input.readI32().value;
6041 } else {
6042 input.skip(ftype);
6043 }
6044 break;
6045 case 3:
6046 if (ftype == Thrift.Type.BYTE) {
6047 this.PacketFormat = input.readByte().value;
6048 } else {
6049 input.skip(ftype);
6050 }
6051 break;
6052 case 4:
6053 if (ftype == Thrift.Type.LIST) {
6054 var _size32 = 0;
6055 var _rtmp336;
6056 this.VoicePacketHeader = [];
6057 var _etype35 = 0;
6058 _rtmp336 = input.readListBegin();
6059 _etype35 = _rtmp336.etype;
6060 _size32 = _rtmp336.size;
6061 for (var _i37 = 0; _i37 < _size32; ++_i37)
6062 {
6063 var elem38 = null;
6064 elem38 = input.readByte().value;
6065 this.VoicePacketHeader.push(elem38);
6066 }
6067 input.readListEnd();
6068 } else {
6069 input.skip(ftype);
6070 }
6071 break;
6072 case 5:
6073 if (ftype == Thrift.Type.LIST) {
6074 var _size39 = 0;
6075 var _rtmp343;
6076 this.VoicePacketFrame = [];
6077 var _etype42 = 0;
6078 _rtmp343 = input.readListBegin();
6079 _etype42 = _rtmp343.etype;
6080 _size39 = _rtmp343.size;
6081 for (var _i44 = 0; _i44 < _size39; ++_i44)
6082 {
6083 var elem45 = null;
6084 elem45 = input.readByte().value;
6085 this.VoicePacketFrame.push(elem45);
6086 }
6087 input.readListEnd();
6088 } else {
6089 input.skip(ftype);
6090 }
6091 break;
6092 default:
6093 input.skip(ftype);
6094 }
6095 input.readFieldEnd();
6096 }
6097 input.readStructEnd();
6098 return;
6099};
6100
6101VoiceFrameData.prototype.write = function(output) {
6102 output.writeStructBegin('VoiceFrameData');
6103 if (this.VoiceCodec !== null && this.VoiceCodec !== undefined) {
6104 output.writeFieldBegin('VoiceCodec', Thrift.Type.I32, 1);
6105 output.writeI32(this.VoiceCodec);
6106 output.writeFieldEnd();
6107 }
6108 if (this.Bitrate !== null && this.Bitrate !== undefined) {
6109 output.writeFieldBegin('Bitrate', Thrift.Type.I32, 2);
6110 output.writeI32(this.Bitrate);
6111 output.writeFieldEnd();
6112 }
6113 if (this.PacketFormat !== null && this.PacketFormat !== undefined) {
6114 output.writeFieldBegin('PacketFormat', Thrift.Type.BYTE, 3);
6115 output.writeByte(this.PacketFormat);
6116 output.writeFieldEnd();
6117 }
6118 if (this.VoicePacketHeader !== null && this.VoicePacketHeader !== undefined) {
6119 output.writeFieldBegin('VoicePacketHeader', Thrift.Type.LIST, 4);
6120 output.writeListBegin(Thrift.Type.BYTE, this.VoicePacketHeader.length);
6121 for (var iter46 in this.VoicePacketHeader)
6122 {
6123 if (this.VoicePacketHeader.hasOwnProperty(iter46))
6124 {
6125 iter46 = this.VoicePacketHeader[iter46];
6126 output.writeByte(iter46);
6127 }
6128 }
6129 output.writeListEnd();
6130 output.writeFieldEnd();
6131 }
6132 if (this.VoicePacketFrame !== null && this.VoicePacketFrame !== undefined) {
6133 output.writeFieldBegin('VoicePacketFrame', Thrift.Type.LIST, 5);
6134 output.writeListBegin(Thrift.Type.BYTE, this.VoicePacketFrame.length);
6135 for (var iter47 in this.VoicePacketFrame)
6136 {
6137 if (this.VoicePacketFrame.hasOwnProperty(iter47))
6138 {
6139 iter47 = this.VoicePacketFrame[iter47];
6140 output.writeByte(iter47);
6141 }
6142 }
6143 output.writeListEnd();
6144 output.writeFieldEnd();
6145 }
6146 output.writeFieldStop();
6147 output.writeStructEnd();
6148 return;
6149};
6150
6151PlayerGameEventUnit = function(args) {
6152 this.AvatarFrame = null;
6153 this.PlayerInfoFrame = null;
6154 this.VoiceFrame = null;
6155 if (args) {
6156 if (args.AvatarFrame !== undefined && args.AvatarFrame !== null) {
6157 this.AvatarFrame = new AvatarFrameData(args.AvatarFrame);
6158 }
6159 if (args.PlayerInfoFrame !== undefined && args.PlayerInfoFrame !== null) {
6160 this.PlayerInfoFrame = new PlayerInfoFrameData(args.PlayerInfoFrame);
6161 }
6162 if (args.VoiceFrame !== undefined && args.VoiceFrame !== null) {
6163 this.VoiceFrame = new VoiceFrameData(args.VoiceFrame);
6164 }
6165 }
6166};
6167PlayerGameEventUnit.prototype = {};
6168PlayerGameEventUnit.prototype.read = function(input) {
6169 input.readStructBegin();
6170 while (true)
6171 {
6172 var ret = input.readFieldBegin();
6173 var fname = ret.fname;
6174 var ftype = ret.ftype;
6175 var fid = ret.fid;
6176 if (ftype == Thrift.Type.STOP) {
6177 break;
6178 }
6179 switch (fid)
6180 {
6181 case 1:
6182 if (ftype == Thrift.Type.STRUCT) {
6183 this.AvatarFrame = new AvatarFrameData();
6184 this.AvatarFrame.read(input);
6185 } else {
6186 input.skip(ftype);
6187 }
6188 break;
6189 case 2:
6190 if (ftype == Thrift.Type.STRUCT) {
6191 this.PlayerInfoFrame = new PlayerInfoFrameData();
6192 this.PlayerInfoFrame.read(input);
6193 } else {
6194 input.skip(ftype);
6195 }
6196 break;
6197 case 3:
6198 if (ftype == Thrift.Type.STRUCT) {
6199 this.VoiceFrame = new VoiceFrameData();
6200 this.VoiceFrame.read(input);
6201 } else {
6202 input.skip(ftype);
6203 }
6204 break;
6205 default:
6206 input.skip(ftype);
6207 }
6208 input.readFieldEnd();
6209 }
6210 input.readStructEnd();
6211 return;
6212};
6213
6214PlayerGameEventUnit.prototype.write = function(output) {
6215 output.writeStructBegin('PlayerGameEventUnit');
6216 if (this.AvatarFrame !== null && this.AvatarFrame !== undefined) {
6217 output.writeFieldBegin('AvatarFrame', Thrift.Type.STRUCT, 1);
6218 this.AvatarFrame.write(output);
6219 output.writeFieldEnd();
6220 }
6221 if (this.PlayerInfoFrame !== null && this.PlayerInfoFrame !== undefined) {
6222 output.writeFieldBegin('PlayerInfoFrame', Thrift.Type.STRUCT, 2);
6223 this.PlayerInfoFrame.write(output);
6224 output.writeFieldEnd();
6225 }
6226 if (this.VoiceFrame !== null && this.VoiceFrame !== undefined) {
6227 output.writeFieldBegin('VoiceFrame', Thrift.Type.STRUCT, 3);
6228 this.VoiceFrame.write(output);
6229 output.writeFieldEnd();
6230 }
6231 output.writeFieldStop();
6232 output.writeStructEnd();
6233 return;
6234};
6235
6236PlayerGameEventData = function(args) {
6237 this.PlayerId = null;
6238 this.PlayerViewId = null;
6239 this.PlayerGameEventUnit = null;
6240 if (args) {
6241 if (args.PlayerId !== undefined && args.PlayerId !== null) {
6242 this.PlayerId = new PlayerID(args.PlayerId);
6243 } else {
6244 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field PlayerId is unset!');
6245 }
6246 if (args.PlayerViewId !== undefined && args.PlayerViewId !== null) {
6247 this.PlayerViewId = new GameViewID(args.PlayerViewId);
6248 } else {
6249 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field PlayerViewId is unset!');
6250 }
6251 if (args.PlayerGameEventUnit !== undefined && args.PlayerGameEventUnit !== null) {
6252 this.PlayerGameEventUnit = new PlayerGameEventUnit(args.PlayerGameEventUnit);
6253 } else {
6254 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field PlayerGameEventUnit is unset!');
6255 }
6256 }
6257};
6258PlayerGameEventData.prototype = {};
6259PlayerGameEventData.prototype.read = function(input) {
6260 input.readStructBegin();
6261 while (true)
6262 {
6263 var ret = input.readFieldBegin();
6264 var fname = ret.fname;
6265 var ftype = ret.ftype;
6266 var fid = ret.fid;
6267 if (ftype == Thrift.Type.STOP) {
6268 break;
6269 }
6270 switch (fid)
6271 {
6272 case 1:
6273 if (ftype == Thrift.Type.STRUCT) {
6274 this.PlayerId = new PlayerID();
6275 this.PlayerId.read(input);
6276 } else {
6277 input.skip(ftype);
6278 }
6279 break;
6280 case 2:
6281 if (ftype == Thrift.Type.STRUCT) {
6282 this.PlayerViewId = new GameViewID();
6283 this.PlayerViewId.read(input);
6284 } else {
6285 input.skip(ftype);
6286 }
6287 break;
6288 case 3:
6289 if (ftype == Thrift.Type.STRUCT) {
6290 this.PlayerGameEventUnit = new PlayerGameEventUnit();
6291 this.PlayerGameEventUnit.read(input);
6292 } else {
6293 input.skip(ftype);
6294 }
6295 break;
6296 default:
6297 input.skip(ftype);
6298 }
6299 input.readFieldEnd();
6300 }
6301 input.readStructEnd();
6302 return;
6303};
6304
6305PlayerGameEventData.prototype.write = function(output) {
6306 output.writeStructBegin('PlayerGameEventData');
6307 if (this.PlayerId !== null && this.PlayerId !== undefined) {
6308 output.writeFieldBegin('PlayerId', Thrift.Type.STRUCT, 1);
6309 this.PlayerId.write(output);
6310 output.writeFieldEnd();
6311 }
6312 if (this.PlayerViewId !== null && this.PlayerViewId !== undefined) {
6313 output.writeFieldBegin('PlayerViewId', Thrift.Type.STRUCT, 2);
6314 this.PlayerViewId.write(output);
6315 output.writeFieldEnd();
6316 }
6317 if (this.PlayerGameEventUnit !== null && this.PlayerGameEventUnit !== undefined) {
6318 output.writeFieldBegin('PlayerGameEventUnit', Thrift.Type.STRUCT, 3);
6319 this.PlayerGameEventUnit.write(output);
6320 output.writeFieldEnd();
6321 }
6322 output.writeFieldStop();
6323 output.writeStructEnd();
6324 return;
6325};
6326
6327WebMediaContentFrameData = function(args) {
6328 this.Url = null;
6329 this.MediaPlayerInfoJson = null;
6330 this.ScrollPoint = null;
6331 if (args) {
6332 if (args.Url !== undefined && args.Url !== null) {
6333 this.Url = args.Url;
6334 } else {
6335 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Url is unset!');
6336 }
6337 if (args.MediaPlayerInfoJson !== undefined && args.MediaPlayerInfoJson !== null) {
6338 this.MediaPlayerInfoJson = args.MediaPlayerInfoJson;
6339 }
6340 if (args.ScrollPoint !== undefined && args.ScrollPoint !== null) {
6341 this.ScrollPoint = new Vector2Data(args.ScrollPoint);
6342 } else {
6343 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field ScrollPoint is unset!');
6344 }
6345 }
6346};
6347WebMediaContentFrameData.prototype = {};
6348WebMediaContentFrameData.prototype.read = function(input) {
6349 input.readStructBegin();
6350 while (true)
6351 {
6352 var ret = input.readFieldBegin();
6353 var fname = ret.fname;
6354 var ftype = ret.ftype;
6355 var fid = ret.fid;
6356 if (ftype == Thrift.Type.STOP) {
6357 break;
6358 }
6359 switch (fid)
6360 {
6361 case 1:
6362 if (ftype == Thrift.Type.STRING) {
6363 this.Url = input.readString().value;
6364 } else {
6365 input.skip(ftype);
6366 }
6367 break;
6368 case 2:
6369 if (ftype == Thrift.Type.STRING) {
6370 this.MediaPlayerInfoJson = input.readString().value;
6371 } else {
6372 input.skip(ftype);
6373 }
6374 break;
6375 case 3:
6376 if (ftype == Thrift.Type.STRUCT) {
6377 this.ScrollPoint = new Vector2Data();
6378 this.ScrollPoint.read(input);
6379 } else {
6380 input.skip(ftype);
6381 }
6382 break;
6383 default:
6384 input.skip(ftype);
6385 }
6386 input.readFieldEnd();
6387 }
6388 input.readStructEnd();
6389 return;
6390};
6391
6392WebMediaContentFrameData.prototype.write = function(output) {
6393 output.writeStructBegin('WebMediaContentFrameData');
6394 if (this.Url !== null && this.Url !== undefined) {
6395 output.writeFieldBegin('Url', Thrift.Type.STRING, 1);
6396 output.writeString(this.Url);
6397 output.writeFieldEnd();
6398 }
6399 if (this.MediaPlayerInfoJson !== null && this.MediaPlayerInfoJson !== undefined) {
6400 output.writeFieldBegin('MediaPlayerInfoJson', Thrift.Type.STRING, 2);
6401 output.writeString(this.MediaPlayerInfoJson);
6402 output.writeFieldEnd();
6403 }
6404 if (this.ScrollPoint !== null && this.ScrollPoint !== undefined) {
6405 output.writeFieldBegin('ScrollPoint', Thrift.Type.STRUCT, 3);
6406 this.ScrollPoint.write(output);
6407 output.writeFieldEnd();
6408 }
6409 output.writeFieldStop();
6410 output.writeStructEnd();
6411 return;
6412};
6413
6414ContentFrameUnit = function(args) {
6415 this.WebMediaContentFrame = null;
6416 if (args) {
6417 if (args.WebMediaContentFrame !== undefined && args.WebMediaContentFrame !== null) {
6418 this.WebMediaContentFrame = new WebMediaContentFrameData(args.WebMediaContentFrame);
6419 }
6420 }
6421};
6422ContentFrameUnit.prototype = {};
6423ContentFrameUnit.prototype.read = function(input) {
6424 input.readStructBegin();
6425 while (true)
6426 {
6427 var ret = input.readFieldBegin();
6428 var fname = ret.fname;
6429 var ftype = ret.ftype;
6430 var fid = ret.fid;
6431 if (ftype == Thrift.Type.STOP) {
6432 break;
6433 }
6434 switch (fid)
6435 {
6436 case 1:
6437 if (ftype == Thrift.Type.STRUCT) {
6438 this.WebMediaContentFrame = new WebMediaContentFrameData();
6439 this.WebMediaContentFrame.read(input);
6440 } else {
6441 input.skip(ftype);
6442 }
6443 break;
6444 case 0:
6445 input.skip(ftype);
6446 break;
6447 default:
6448 input.skip(ftype);
6449 }
6450 input.readFieldEnd();
6451 }
6452 input.readStructEnd();
6453 return;
6454};
6455
6456ContentFrameUnit.prototype.write = function(output) {
6457 output.writeStructBegin('ContentFrameUnit');
6458 if (this.WebMediaContentFrame !== null && this.WebMediaContentFrame !== undefined) {
6459 output.writeFieldBegin('WebMediaContentFrame', Thrift.Type.STRUCT, 1);
6460 this.WebMediaContentFrame.write(output);
6461 output.writeFieldEnd();
6462 }
6463 output.writeFieldStop();
6464 output.writeStructEnd();
6465 return;
6466};
6467
6468CompositionFrameData = function(args) {
6469 this.CompositionTransform = null;
6470 this.ContentFrameUnit = null;
6471 this.ParentEnclosureID = null;
6472 if (args) {
6473 if (args.CompositionTransform !== undefined && args.CompositionTransform !== null) {
6474 this.CompositionTransform = new TransformData(args.CompositionTransform);
6475 } else {
6476 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field CompositionTransform is unset!');
6477 }
6478 if (args.ContentFrameUnit !== undefined && args.ContentFrameUnit !== null) {
6479 this.ContentFrameUnit = new ContentFrameUnit(args.ContentFrameUnit);
6480 } else {
6481 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field ContentFrameUnit is unset!');
6482 }
6483 if (args.ParentEnclosureID !== undefined && args.ParentEnclosureID !== null) {
6484 this.ParentEnclosureID = new GameViewID(args.ParentEnclosureID);
6485 } else {
6486 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field ParentEnclosureID is unset!');
6487 }
6488 }
6489};
6490CompositionFrameData.prototype = {};
6491CompositionFrameData.prototype.read = function(input) {
6492 input.readStructBegin();
6493 while (true)
6494 {
6495 var ret = input.readFieldBegin();
6496 var fname = ret.fname;
6497 var ftype = ret.ftype;
6498 var fid = ret.fid;
6499 if (ftype == Thrift.Type.STOP) {
6500 break;
6501 }
6502 switch (fid)
6503 {
6504 case 1:
6505 if (ftype == Thrift.Type.STRUCT) {
6506 this.CompositionTransform = new TransformData();
6507 this.CompositionTransform.read(input);
6508 } else {
6509 input.skip(ftype);
6510 }
6511 break;
6512 case 2:
6513 if (ftype == Thrift.Type.STRUCT) {
6514 this.ContentFrameUnit = new ContentFrameUnit();
6515 this.ContentFrameUnit.read(input);
6516 } else {
6517 input.skip(ftype);
6518 }
6519 break;
6520 case 3:
6521 if (ftype == Thrift.Type.STRUCT) {
6522 this.ParentEnclosureID = new GameViewID();
6523 this.ParentEnclosureID.read(input);
6524 } else {
6525 input.skip(ftype);
6526 }
6527 break;
6528 default:
6529 input.skip(ftype);
6530 }
6531 input.readFieldEnd();
6532 }
6533 input.readStructEnd();
6534 return;
6535};
6536
6537CompositionFrameData.prototype.write = function(output) {
6538 output.writeStructBegin('CompositionFrameData');
6539 if (this.CompositionTransform !== null && this.CompositionTransform !== undefined) {
6540 output.writeFieldBegin('CompositionTransform', Thrift.Type.STRUCT, 1);
6541 this.CompositionTransform.write(output);
6542 output.writeFieldEnd();
6543 }
6544 if (this.ContentFrameUnit !== null && this.ContentFrameUnit !== undefined) {
6545 output.writeFieldBegin('ContentFrameUnit', Thrift.Type.STRUCT, 2);
6546 this.ContentFrameUnit.write(output);
6547 output.writeFieldEnd();
6548 }
6549 if (this.ParentEnclosureID !== null && this.ParentEnclosureID !== undefined) {
6550 output.writeFieldBegin('ParentEnclosureID', Thrift.Type.STRUCT, 3);
6551 this.ParentEnclosureID.write(output);
6552 output.writeFieldEnd();
6553 }
6554 output.writeFieldStop();
6555 output.writeStructEnd();
6556 return;
6557};
6558
6559CompositionGameEventUnit = function(args) {
6560 this.CompositionFrame = null;
6561 if (args) {
6562 if (args.CompositionFrame !== undefined && args.CompositionFrame !== null) {
6563 this.CompositionFrame = new CompositionFrameData(args.CompositionFrame);
6564 }
6565 }
6566};
6567CompositionGameEventUnit.prototype = {};
6568CompositionGameEventUnit.prototype.read = function(input) {
6569 input.readStructBegin();
6570 while (true)
6571 {
6572 var ret = input.readFieldBegin();
6573 var fname = ret.fname;
6574 var ftype = ret.ftype;
6575 var fid = ret.fid;
6576 if (ftype == Thrift.Type.STOP) {
6577 break;
6578 }
6579 switch (fid)
6580 {
6581 case 1:
6582 if (ftype == Thrift.Type.STRUCT) {
6583 this.CompositionFrame = new CompositionFrameData();
6584 this.CompositionFrame.read(input);
6585 } else {
6586 input.skip(ftype);
6587 }
6588 break;
6589 case 0:
6590 input.skip(ftype);
6591 break;
6592 default:
6593 input.skip(ftype);
6594 }
6595 input.readFieldEnd();
6596 }
6597 input.readStructEnd();
6598 return;
6599};
6600
6601CompositionGameEventUnit.prototype.write = function(output) {
6602 output.writeStructBegin('CompositionGameEventUnit');
6603 if (this.CompositionFrame !== null && this.CompositionFrame !== undefined) {
6604 output.writeFieldBegin('CompositionFrame', Thrift.Type.STRUCT, 1);
6605 this.CompositionFrame.write(output);
6606 output.writeFieldEnd();
6607 }
6608 output.writeFieldStop();
6609 output.writeStructEnd();
6610 return;
6611};
6612
6613CompositionGameEventData = function(args) {
6614 this.CompositionViewId = null;
6615 this.CompositionGameEventUnit = null;
6616 this.OwnerId = null;
6617 if (args) {
6618 if (args.CompositionViewId !== undefined && args.CompositionViewId !== null) {
6619 this.CompositionViewId = new GameViewID(args.CompositionViewId);
6620 } else {
6621 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field CompositionViewId is unset!');
6622 }
6623 if (args.CompositionGameEventUnit !== undefined && args.CompositionGameEventUnit !== null) {
6624 this.CompositionGameEventUnit = new CompositionGameEventUnit(args.CompositionGameEventUnit);
6625 } else {
6626 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field CompositionGameEventUnit is unset!');
6627 }
6628 if (args.OwnerId !== undefined && args.OwnerId !== null) {
6629 this.OwnerId = new PlayerID(args.OwnerId);
6630 }
6631 }
6632};
6633CompositionGameEventData.prototype = {};
6634CompositionGameEventData.prototype.read = function(input) {
6635 input.readStructBegin();
6636 while (true)
6637 {
6638 var ret = input.readFieldBegin();
6639 var fname = ret.fname;
6640 var ftype = ret.ftype;
6641 var fid = ret.fid;
6642 if (ftype == Thrift.Type.STOP) {
6643 break;
6644 }
6645 switch (fid)
6646 {
6647 case 1:
6648 if (ftype == Thrift.Type.STRUCT) {
6649 this.CompositionViewId = new GameViewID();
6650 this.CompositionViewId.read(input);
6651 } else {
6652 input.skip(ftype);
6653 }
6654 break;
6655 case 2:
6656 if (ftype == Thrift.Type.STRUCT) {
6657 this.CompositionGameEventUnit = new CompositionGameEventUnit();
6658 this.CompositionGameEventUnit.read(input);
6659 } else {
6660 input.skip(ftype);
6661 }
6662 break;
6663 case 3:
6664 if (ftype == Thrift.Type.STRUCT) {
6665 this.OwnerId = new PlayerID();
6666 this.OwnerId.read(input);
6667 } else {
6668 input.skip(ftype);
6669 }
6670 break;
6671 default:
6672 input.skip(ftype);
6673 }
6674 input.readFieldEnd();
6675 }
6676 input.readStructEnd();
6677 return;
6678};
6679
6680CompositionGameEventData.prototype.write = function(output) {
6681 output.writeStructBegin('CompositionGameEventData');
6682 if (this.CompositionViewId !== null && this.CompositionViewId !== undefined) {
6683 output.writeFieldBegin('CompositionViewId', Thrift.Type.STRUCT, 1);
6684 this.CompositionViewId.write(output);
6685 output.writeFieldEnd();
6686 }
6687 if (this.CompositionGameEventUnit !== null && this.CompositionGameEventUnit !== undefined) {
6688 output.writeFieldBegin('CompositionGameEventUnit', Thrift.Type.STRUCT, 2);
6689 this.CompositionGameEventUnit.write(output);
6690 output.writeFieldEnd();
6691 }
6692 if (this.OwnerId !== null && this.OwnerId !== undefined) {
6693 output.writeFieldBegin('OwnerId', Thrift.Type.STRUCT, 3);
6694 this.OwnerId.write(output);
6695 output.writeFieldEnd();
6696 }
6697 output.writeFieldStop();
6698 output.writeStructEnd();
6699 return;
6700};
6701
6702EnclosurePermissionsData = function(args) {
6703 this.IsAdminLocked = null;
6704 if (args) {
6705 if (args.IsAdminLocked !== undefined && args.IsAdminLocked !== null) {
6706 this.IsAdminLocked = args.IsAdminLocked;
6707 } else {
6708 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field IsAdminLocked is unset!');
6709 }
6710 }
6711};
6712EnclosurePermissionsData.prototype = {};
6713EnclosurePermissionsData.prototype.read = function(input) {
6714 input.readStructBegin();
6715 while (true)
6716 {
6717 var ret = input.readFieldBegin();
6718 var fname = ret.fname;
6719 var ftype = ret.ftype;
6720 var fid = ret.fid;
6721 if (ftype == Thrift.Type.STOP) {
6722 break;
6723 }
6724 switch (fid)
6725 {
6726 case 1:
6727 if (ftype == Thrift.Type.BOOL) {
6728 this.IsAdminLocked = input.readBool().value;
6729 } else {
6730 input.skip(ftype);
6731 }
6732 break;
6733 case 0:
6734 input.skip(ftype);
6735 break;
6736 default:
6737 input.skip(ftype);
6738 }
6739 input.readFieldEnd();
6740 }
6741 input.readStructEnd();
6742 return;
6743};
6744
6745EnclosurePermissionsData.prototype.write = function(output) {
6746 output.writeStructBegin('EnclosurePermissionsData');
6747 if (this.IsAdminLocked !== null && this.IsAdminLocked !== undefined) {
6748 output.writeFieldBegin('IsAdminLocked', Thrift.Type.BOOL, 1);
6749 output.writeBool(this.IsAdminLocked);
6750 output.writeFieldEnd();
6751 }
6752 output.writeFieldStop();
6753 output.writeStructEnd();
6754 return;
6755};
6756
6757EnclosurePermissionsUnit = function(args) {
6758 this.EnclosurePermissions = null;
6759 if (args) {
6760 if (args.EnclosurePermissions !== undefined && args.EnclosurePermissions !== null) {
6761 this.EnclosurePermissions = new EnclosurePermissionsData(args.EnclosurePermissions);
6762 }
6763 }
6764};
6765EnclosurePermissionsUnit.prototype = {};
6766EnclosurePermissionsUnit.prototype.read = function(input) {
6767 input.readStructBegin();
6768 while (true)
6769 {
6770 var ret = input.readFieldBegin();
6771 var fname = ret.fname;
6772 var ftype = ret.ftype;
6773 var fid = ret.fid;
6774 if (ftype == Thrift.Type.STOP) {
6775 break;
6776 }
6777 switch (fid)
6778 {
6779 case 1:
6780 if (ftype == Thrift.Type.STRUCT) {
6781 this.EnclosurePermissions = new EnclosurePermissionsData();
6782 this.EnclosurePermissions.read(input);
6783 } else {
6784 input.skip(ftype);
6785 }
6786 break;
6787 case 0:
6788 input.skip(ftype);
6789 break;
6790 default:
6791 input.skip(ftype);
6792 }
6793 input.readFieldEnd();
6794 }
6795 input.readStructEnd();
6796 return;
6797};
6798
6799EnclosurePermissionsUnit.prototype.write = function(output) {
6800 output.writeStructBegin('EnclosurePermissionsUnit');
6801 if (this.EnclosurePermissions !== null && this.EnclosurePermissions !== undefined) {
6802 output.writeFieldBegin('EnclosurePermissions', Thrift.Type.STRUCT, 1);
6803 this.EnclosurePermissions.write(output);
6804 output.writeFieldEnd();
6805 }
6806 output.writeFieldStop();
6807 output.writeStructEnd();
6808 return;
6809};
6810
6811EnclosureFrameData = function(args) {
6812 this.EnclosureTransform = null;
6813 this.EnclosureDimensions = null;
6814 this.EnclosurePermissions = null;
6815 if (args) {
6816 if (args.EnclosureTransform !== undefined && args.EnclosureTransform !== null) {
6817 this.EnclosureTransform = new TransformData(args.EnclosureTransform);
6818 }
6819 if (args.EnclosureDimensions !== undefined && args.EnclosureDimensions !== null) {
6820 this.EnclosureDimensions = new DimensionsData(args.EnclosureDimensions);
6821 }
6822 if (args.EnclosurePermissions !== undefined && args.EnclosurePermissions !== null) {
6823 this.EnclosurePermissions = new EnclosurePermissionsUnit(args.EnclosurePermissions);
6824 }
6825 }
6826};
6827EnclosureFrameData.prototype = {};
6828EnclosureFrameData.prototype.read = function(input) {
6829 input.readStructBegin();
6830 while (true)
6831 {
6832 var ret = input.readFieldBegin();
6833 var fname = ret.fname;
6834 var ftype = ret.ftype;
6835 var fid = ret.fid;
6836 if (ftype == Thrift.Type.STOP) {
6837 break;
6838 }
6839 switch (fid)
6840 {
6841 case 1:
6842 if (ftype == Thrift.Type.STRUCT) {
6843 this.EnclosureTransform = new TransformData();
6844 this.EnclosureTransform.read(input);
6845 } else {
6846 input.skip(ftype);
6847 }
6848 break;
6849 case 2:
6850 if (ftype == Thrift.Type.STRUCT) {
6851 this.EnclosureDimensions = new DimensionsData();
6852 this.EnclosureDimensions.read(input);
6853 } else {
6854 input.skip(ftype);
6855 }
6856 break;
6857 case 3:
6858 if (ftype == Thrift.Type.STRUCT) {
6859 this.EnclosurePermissions = new EnclosurePermissionsUnit();
6860 this.EnclosurePermissions.read(input);
6861 } else {
6862 input.skip(ftype);
6863 }
6864 break;
6865 default:
6866 input.skip(ftype);
6867 }
6868 input.readFieldEnd();
6869 }
6870 input.readStructEnd();
6871 return;
6872};
6873
6874EnclosureFrameData.prototype.write = function(output) {
6875 output.writeStructBegin('EnclosureFrameData');
6876 if (this.EnclosureTransform !== null && this.EnclosureTransform !== undefined) {
6877 output.writeFieldBegin('EnclosureTransform', Thrift.Type.STRUCT, 1);
6878 this.EnclosureTransform.write(output);
6879 output.writeFieldEnd();
6880 }
6881 if (this.EnclosureDimensions !== null && this.EnclosureDimensions !== undefined) {
6882 output.writeFieldBegin('EnclosureDimensions', Thrift.Type.STRUCT, 2);
6883 this.EnclosureDimensions.write(output);
6884 output.writeFieldEnd();
6885 }
6886 if (this.EnclosurePermissions !== null && this.EnclosurePermissions !== undefined) {
6887 output.writeFieldBegin('EnclosurePermissions', Thrift.Type.STRUCT, 3);
6888 this.EnclosurePermissions.write(output);
6889 output.writeFieldEnd();
6890 }
6891 output.writeFieldStop();
6892 output.writeStructEnd();
6893 return;
6894};
6895
6896EnclosureGameEventUnit = function(args) {
6897 this.EnclosureFrame = null;
6898 if (args) {
6899 if (args.EnclosureFrame !== undefined && args.EnclosureFrame !== null) {
6900 this.EnclosureFrame = new EnclosureFrameData(args.EnclosureFrame);
6901 }
6902 }
6903};
6904EnclosureGameEventUnit.prototype = {};
6905EnclosureGameEventUnit.prototype.read = function(input) {
6906 input.readStructBegin();
6907 while (true)
6908 {
6909 var ret = input.readFieldBegin();
6910 var fname = ret.fname;
6911 var ftype = ret.ftype;
6912 var fid = ret.fid;
6913 if (ftype == Thrift.Type.STOP) {
6914 break;
6915 }
6916 switch (fid)
6917 {
6918 case 1:
6919 if (ftype == Thrift.Type.STRUCT) {
6920 this.EnclosureFrame = new EnclosureFrameData();
6921 this.EnclosureFrame.read(input);
6922 } else {
6923 input.skip(ftype);
6924 }
6925 break;
6926 case 0:
6927 input.skip(ftype);
6928 break;
6929 default:
6930 input.skip(ftype);
6931 }
6932 input.readFieldEnd();
6933 }
6934 input.readStructEnd();
6935 return;
6936};
6937
6938EnclosureGameEventUnit.prototype.write = function(output) {
6939 output.writeStructBegin('EnclosureGameEventUnit');
6940 if (this.EnclosureFrame !== null && this.EnclosureFrame !== undefined) {
6941 output.writeFieldBegin('EnclosureFrame', Thrift.Type.STRUCT, 1);
6942 this.EnclosureFrame.write(output);
6943 output.writeFieldEnd();
6944 }
6945 output.writeFieldStop();
6946 output.writeStructEnd();
6947 return;
6948};
6949
6950EnclosureGameEventData = function(args) {
6951 this.EnclosureViewId = null;
6952 this.EnclosureGameEventUnit = null;
6953 if (args) {
6954 if (args.EnclosureViewId !== undefined && args.EnclosureViewId !== null) {
6955 this.EnclosureViewId = new GameViewID(args.EnclosureViewId);
6956 } else {
6957 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field EnclosureViewId is unset!');
6958 }
6959 if (args.EnclosureGameEventUnit !== undefined && args.EnclosureGameEventUnit !== null) {
6960 this.EnclosureGameEventUnit = new EnclosureGameEventUnit(args.EnclosureGameEventUnit);
6961 } else {
6962 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field EnclosureGameEventUnit is unset!');
6963 }
6964 }
6965};
6966EnclosureGameEventData.prototype = {};
6967EnclosureGameEventData.prototype.read = function(input) {
6968 input.readStructBegin();
6969 while (true)
6970 {
6971 var ret = input.readFieldBegin();
6972 var fname = ret.fname;
6973 var ftype = ret.ftype;
6974 var fid = ret.fid;
6975 if (ftype == Thrift.Type.STOP) {
6976 break;
6977 }
6978 switch (fid)
6979 {
6980 case 1:
6981 if (ftype == Thrift.Type.STRUCT) {
6982 this.EnclosureViewId = new GameViewID();
6983 this.EnclosureViewId.read(input);
6984 } else {
6985 input.skip(ftype);
6986 }
6987 break;
6988 case 2:
6989 if (ftype == Thrift.Type.STRUCT) {
6990 this.EnclosureGameEventUnit = new EnclosureGameEventUnit();
6991 this.EnclosureGameEventUnit.read(input);
6992 } else {
6993 input.skip(ftype);
6994 }
6995 break;
6996 default:
6997 input.skip(ftype);
6998 }
6999 input.readFieldEnd();
7000 }
7001 input.readStructEnd();
7002 return;
7003};
7004
7005EnclosureGameEventData.prototype.write = function(output) {
7006 output.writeStructBegin('EnclosureGameEventData');
7007 if (this.EnclosureViewId !== null && this.EnclosureViewId !== undefined) {
7008 output.writeFieldBegin('EnclosureViewId', Thrift.Type.STRUCT, 1);
7009 this.EnclosureViewId.write(output);
7010 output.writeFieldEnd();
7011 }
7012 if (this.EnclosureGameEventUnit !== null && this.EnclosureGameEventUnit !== undefined) {
7013 output.writeFieldBegin('EnclosureGameEventUnit', Thrift.Type.STRUCT, 2);
7014 this.EnclosureGameEventUnit.write(output);
7015 output.writeFieldEnd();
7016 }
7017 output.writeFieldStop();
7018 output.writeStructEnd();
7019 return;
7020};
7021
7022GameEventUnit = function(args) {
7023 this.PlayerGameEvent = null;
7024 this.CompositionGameEvent = null;
7025 this.EnclosureGameEvent = null;
7026 if (args) {
7027 if (args.PlayerGameEvent !== undefined && args.PlayerGameEvent !== null) {
7028 this.PlayerGameEvent = new PlayerGameEventData(args.PlayerGameEvent);
7029 }
7030 if (args.CompositionGameEvent !== undefined && args.CompositionGameEvent !== null) {
7031 this.CompositionGameEvent = new CompositionGameEventData(args.CompositionGameEvent);
7032 }
7033 if (args.EnclosureGameEvent !== undefined && args.EnclosureGameEvent !== null) {
7034 this.EnclosureGameEvent = new EnclosureGameEventData(args.EnclosureGameEvent);
7035 }
7036 }
7037};
7038GameEventUnit.prototype = {};
7039GameEventUnit.prototype.read = function(input) {
7040 input.readStructBegin();
7041 while (true)
7042 {
7043 var ret = input.readFieldBegin();
7044 var fname = ret.fname;
7045 var ftype = ret.ftype;
7046 var fid = ret.fid;
7047 if (ftype == Thrift.Type.STOP) {
7048 break;
7049 }
7050 switch (fid)
7051 {
7052 case 1:
7053 if (ftype == Thrift.Type.STRUCT) {
7054 this.PlayerGameEvent = new PlayerGameEventData();
7055 this.PlayerGameEvent.read(input);
7056 } else {
7057 input.skip(ftype);
7058 }
7059 break;
7060 case 2:
7061 if (ftype == Thrift.Type.STRUCT) {
7062 this.CompositionGameEvent = new CompositionGameEventData();
7063 this.CompositionGameEvent.read(input);
7064 } else {
7065 input.skip(ftype);
7066 }
7067 break;
7068 case 3:
7069 if (ftype == Thrift.Type.STRUCT) {
7070 this.EnclosureGameEvent = new EnclosureGameEventData();
7071 this.EnclosureGameEvent.read(input);
7072 } else {
7073 input.skip(ftype);
7074 }
7075 break;
7076 default:
7077 input.skip(ftype);
7078 }
7079 input.readFieldEnd();
7080 }
7081 input.readStructEnd();
7082 return;
7083};
7084
7085GameEventUnit.prototype.write = function(output) {
7086 output.writeStructBegin('GameEventUnit');
7087 if (this.PlayerGameEvent !== null && this.PlayerGameEvent !== undefined) {
7088 output.writeFieldBegin('PlayerGameEvent', Thrift.Type.STRUCT, 1);
7089 this.PlayerGameEvent.write(output);
7090 output.writeFieldEnd();
7091 }
7092 if (this.CompositionGameEvent !== null && this.CompositionGameEvent !== undefined) {
7093 output.writeFieldBegin('CompositionGameEvent', Thrift.Type.STRUCT, 2);
7094 this.CompositionGameEvent.write(output);
7095 output.writeFieldEnd();
7096 }
7097 if (this.EnclosureGameEvent !== null && this.EnclosureGameEvent !== undefined) {
7098 output.writeFieldBegin('EnclosureGameEvent', Thrift.Type.STRUCT, 3);
7099 this.EnclosureGameEvent.write(output);
7100 output.writeFieldEnd();
7101 }
7102 output.writeFieldStop();
7103 output.writeStructEnd();
7104 return;
7105};
7106
7107GameEventData = function(args) {
7108 this.GameServerTime = null;
7109 this.GameEventType = null;
7110 this.GameEventUnit = null;
7111 if (args) {
7112 if (args.GameServerTime !== undefined && args.GameServerTime !== null) {
7113 this.GameServerTime = new GameServerTime(args.GameServerTime);
7114 } else {
7115 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field GameServerTime is unset!');
7116 }
7117 if (args.GameEventType !== undefined && args.GameEventType !== null) {
7118 this.GameEventType = args.GameEventType;
7119 } else {
7120 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field GameEventType is unset!');
7121 }
7122 if (args.GameEventUnit !== undefined && args.GameEventUnit !== null) {
7123 this.GameEventUnit = new GameEventUnit(args.GameEventUnit);
7124 } else {
7125 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field GameEventUnit is unset!');
7126 }
7127 }
7128};
7129GameEventData.prototype = {};
7130GameEventData.prototype.read = function(input) {
7131 input.readStructBegin();
7132 while (true)
7133 {
7134 var ret = input.readFieldBegin();
7135 var fname = ret.fname;
7136 var ftype = ret.ftype;
7137 var fid = ret.fid;
7138 if (ftype == Thrift.Type.STOP) {
7139 break;
7140 }
7141 switch (fid)
7142 {
7143 case 1:
7144 if (ftype == Thrift.Type.STRUCT) {
7145 this.GameServerTime = new GameServerTime();
7146 this.GameServerTime.read(input);
7147 } else {
7148 input.skip(ftype);
7149 }
7150 break;
7151 case 2:
7152 if (ftype == Thrift.Type.I32) {
7153 this.GameEventType = input.readI32().value;
7154 } else {
7155 input.skip(ftype);
7156 }
7157 break;
7158 case 3:
7159 if (ftype == Thrift.Type.STRUCT) {
7160 this.GameEventUnit = new GameEventUnit();
7161 this.GameEventUnit.read(input);
7162 } else {
7163 input.skip(ftype);
7164 }
7165 break;
7166 default:
7167 input.skip(ftype);
7168 }
7169 input.readFieldEnd();
7170 }
7171 input.readStructEnd();
7172 return;
7173};
7174
7175GameEventData.prototype.write = function(output) {
7176 output.writeStructBegin('GameEventData');
7177 if (this.GameServerTime !== null && this.GameServerTime !== undefined) {
7178 output.writeFieldBegin('GameServerTime', Thrift.Type.STRUCT, 1);
7179 this.GameServerTime.write(output);
7180 output.writeFieldEnd();
7181 }
7182 if (this.GameEventType !== null && this.GameEventType !== undefined) {
7183 output.writeFieldBegin('GameEventType', Thrift.Type.I32, 2);
7184 output.writeI32(this.GameEventType);
7185 output.writeFieldEnd();
7186 }
7187 if (this.GameEventUnit !== null && this.GameEventUnit !== undefined) {
7188 output.writeFieldBegin('GameEventUnit', Thrift.Type.STRUCT, 3);
7189 this.GameEventUnit.write(output);
7190 output.writeFieldEnd();
7191 }
7192 output.writeFieldStop();
7193 output.writeStructEnd();
7194 return;
7195};
7196
7197RecordingStartEventData = function(args) {
7198 this.RecordedByPlayerId = null;
7199 this.RecordedInSpaceId = null;
7200 this.RecordingFormat = null;
7201 if (args) {
7202 if (args.RecordedByPlayerId !== undefined && args.RecordedByPlayerId !== null) {
7203 this.RecordedByPlayerId = new PlayerID(args.RecordedByPlayerId);
7204 } else {
7205 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field RecordedByPlayerId is unset!');
7206 }
7207 if (args.RecordedInSpaceId !== undefined && args.RecordedInSpaceId !== null) {
7208 this.RecordedInSpaceId = args.RecordedInSpaceId;
7209 } else {
7210 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field RecordedInSpaceId is unset!');
7211 }
7212 if (args.RecordingFormat !== undefined && args.RecordingFormat !== null) {
7213 this.RecordingFormat = args.RecordingFormat;
7214 } else {
7215 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field RecordingFormat is unset!');
7216 }
7217 }
7218};
7219RecordingStartEventData.prototype = {};
7220RecordingStartEventData.prototype.read = function(input) {
7221 input.readStructBegin();
7222 while (true)
7223 {
7224 var ret = input.readFieldBegin();
7225 var fname = ret.fname;
7226 var ftype = ret.ftype;
7227 var fid = ret.fid;
7228 if (ftype == Thrift.Type.STOP) {
7229 break;
7230 }
7231 switch (fid)
7232 {
7233 case 1:
7234 if (ftype == Thrift.Type.STRUCT) {
7235 this.RecordedByPlayerId = new PlayerID();
7236 this.RecordedByPlayerId.read(input);
7237 } else {
7238 input.skip(ftype);
7239 }
7240 break;
7241 case 2:
7242 if (ftype == Thrift.Type.I64) {
7243 this.RecordedInSpaceId = input.readI64().value;
7244 } else {
7245 input.skip(ftype);
7246 }
7247 break;
7248 case 3:
7249 if (ftype == Thrift.Type.BYTE) {
7250 this.RecordingFormat = input.readByte().value;
7251 } else {
7252 input.skip(ftype);
7253 }
7254 break;
7255 default:
7256 input.skip(ftype);
7257 }
7258 input.readFieldEnd();
7259 }
7260 input.readStructEnd();
7261 return;
7262};
7263
7264RecordingStartEventData.prototype.write = function(output) {
7265 output.writeStructBegin('RecordingStartEventData');
7266 if (this.RecordedByPlayerId !== null && this.RecordedByPlayerId !== undefined) {
7267 output.writeFieldBegin('RecordedByPlayerId', Thrift.Type.STRUCT, 1);
7268 this.RecordedByPlayerId.write(output);
7269 output.writeFieldEnd();
7270 }
7271 if (this.RecordedInSpaceId !== null && this.RecordedInSpaceId !== undefined) {
7272 output.writeFieldBegin('RecordedInSpaceId', Thrift.Type.I64, 2);
7273 output.writeI64(this.RecordedInSpaceId);
7274 output.writeFieldEnd();
7275 }
7276 if (this.RecordingFormat !== null && this.RecordingFormat !== undefined) {
7277 output.writeFieldBegin('RecordingFormat', Thrift.Type.BYTE, 3);
7278 output.writeByte(this.RecordingFormat);
7279 output.writeFieldEnd();
7280 }
7281 output.writeFieldStop();
7282 output.writeStructEnd();
7283 return;
7284};
7285
7286RecordingEventUnit = function(args) {
7287 this.RecordingStart = null;
7288 if (args) {
7289 if (args.RecordingStart !== undefined && args.RecordingStart !== null) {
7290 this.RecordingStart = new RecordingStartEventData(args.RecordingStart);
7291 }
7292 }
7293};
7294RecordingEventUnit.prototype = {};
7295RecordingEventUnit.prototype.read = function(input) {
7296 input.readStructBegin();
7297 while (true)
7298 {
7299 var ret = input.readFieldBegin();
7300 var fname = ret.fname;
7301 var ftype = ret.ftype;
7302 var fid = ret.fid;
7303 if (ftype == Thrift.Type.STOP) {
7304 break;
7305 }
7306 switch (fid)
7307 {
7308 case 1:
7309 if (ftype == Thrift.Type.STRUCT) {
7310 this.RecordingStart = new RecordingStartEventData();
7311 this.RecordingStart.read(input);
7312 } else {
7313 input.skip(ftype);
7314 }
7315 break;
7316 case 0:
7317 input.skip(ftype);
7318 break;
7319 default:
7320 input.skip(ftype);
7321 }
7322 input.readFieldEnd();
7323 }
7324 input.readStructEnd();
7325 return;
7326};
7327
7328RecordingEventUnit.prototype.write = function(output) {
7329 output.writeStructBegin('RecordingEventUnit');
7330 if (this.RecordingStart !== null && this.RecordingStart !== undefined) {
7331 output.writeFieldBegin('RecordingStart', Thrift.Type.STRUCT, 1);
7332 this.RecordingStart.write(output);
7333 output.writeFieldEnd();
7334 }
7335 output.writeFieldStop();
7336 output.writeStructEnd();
7337 return;
7338};
7339
7340RecordingEventData = function(args) {
7341 this.Timestamp = null;
7342 this.RecordingEventUnit = null;
7343 if (args) {
7344 if (args.Timestamp !== undefined && args.Timestamp !== null) {
7345 this.Timestamp = args.Timestamp;
7346 } else {
7347 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Timestamp is unset!');
7348 }
7349 if (args.RecordingEventUnit !== undefined && args.RecordingEventUnit !== null) {
7350 this.RecordingEventUnit = new RecordingEventUnit(args.RecordingEventUnit);
7351 } else {
7352 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field RecordingEventUnit is unset!');
7353 }
7354 }
7355};
7356RecordingEventData.prototype = {};
7357RecordingEventData.prototype.read = function(input) {
7358 input.readStructBegin();
7359 while (true)
7360 {
7361 var ret = input.readFieldBegin();
7362 var fname = ret.fname;
7363 var ftype = ret.ftype;
7364 var fid = ret.fid;
7365 if (ftype == Thrift.Type.STOP) {
7366 break;
7367 }
7368 switch (fid)
7369 {
7370 case 1:
7371 if (ftype == Thrift.Type.I64) {
7372 this.Timestamp = input.readI64().value;
7373 } else {
7374 input.skip(ftype);
7375 }
7376 break;
7377 case 2:
7378 if (ftype == Thrift.Type.STRUCT) {
7379 this.RecordingEventUnit = new RecordingEventUnit();
7380 this.RecordingEventUnit.read(input);
7381 } else {
7382 input.skip(ftype);
7383 }
7384 break;
7385 default:
7386 input.skip(ftype);
7387 }
7388 input.readFieldEnd();
7389 }
7390 input.readStructEnd();
7391 return;
7392};
7393
7394RecordingEventData.prototype.write = function(output) {
7395 output.writeStructBegin('RecordingEventData');
7396 if (this.Timestamp !== null && this.Timestamp !== undefined) {
7397 output.writeFieldBegin('Timestamp', Thrift.Type.I64, 1);
7398 output.writeI64(this.Timestamp);
7399 output.writeFieldEnd();
7400 }
7401 if (this.RecordingEventUnit !== null && this.RecordingEventUnit !== undefined) {
7402 output.writeFieldBegin('RecordingEventUnit', Thrift.Type.STRUCT, 2);
7403 this.RecordingEventUnit.write(output);
7404 output.writeFieldEnd();
7405 }
7406 output.writeFieldStop();
7407 output.writeStructEnd();
7408 return;
7409};
7410
7411EventUnit = function(args) {
7412 this.GameEvent = null;
7413 this.RecordingEvent = null;
7414 if (args) {
7415 if (args.GameEvent !== undefined && args.GameEvent !== null) {
7416 this.GameEvent = new GameEventData(args.GameEvent);
7417 }
7418 if (args.RecordingEvent !== undefined && args.RecordingEvent !== null) {
7419 this.RecordingEvent = new RecordingEventData(args.RecordingEvent);
7420 }
7421 }
7422};
7423EventUnit.prototype = {};
7424EventUnit.prototype.read = function(input) {
7425 input.readStructBegin();
7426 while (true)
7427 {
7428 var ret = input.readFieldBegin();
7429 var fname = ret.fname;
7430 var ftype = ret.ftype;
7431 var fid = ret.fid;
7432 if (ftype == Thrift.Type.STOP) {
7433 break;
7434 }
7435 switch (fid)
7436 {
7437 case 1:
7438 if (ftype == Thrift.Type.STRUCT) {
7439 this.GameEvent = new GameEventData();
7440 this.GameEvent.read(input);
7441 } else {
7442 input.skip(ftype);
7443 }
7444 break;
7445 case 2:
7446 if (ftype == Thrift.Type.STRUCT) {
7447 this.RecordingEvent = new RecordingEventData();
7448 this.RecordingEvent.read(input);
7449 } else {
7450 input.skip(ftype);
7451 }
7452 break;
7453 default:
7454 input.skip(ftype);
7455 }
7456 input.readFieldEnd();
7457 }
7458 input.readStructEnd();
7459 return;
7460};
7461
7462EventUnit.prototype.write = function(output) {
7463 output.writeStructBegin('EventUnit');
7464 if (this.GameEvent !== null && this.GameEvent !== undefined) {
7465 output.writeFieldBegin('GameEvent', Thrift.Type.STRUCT, 1);
7466 this.GameEvent.write(output);
7467 output.writeFieldEnd();
7468 }
7469 if (this.RecordingEvent !== null && this.RecordingEvent !== undefined) {
7470 output.writeFieldBegin('RecordingEvent', Thrift.Type.STRUCT, 2);
7471 this.RecordingEvent.write(output);
7472 output.writeFieldEnd();
7473 }
7474 output.writeFieldStop();
7475 output.writeStructEnd();
7476 return;
7477};
7478
7479Pedigree = function(args) {
7480 this.RecordedAtTicks = null;
7481 if (args) {
7482 if (args.RecordedAtTicks !== undefined && args.RecordedAtTicks !== null) {
7483 this.RecordedAtTicks = args.RecordedAtTicks;
7484 } else {
7485 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field RecordedAtTicks is unset!');
7486 }
7487 }
7488};
7489Pedigree.prototype = {};
7490Pedigree.prototype.read = function(input) {
7491 input.readStructBegin();
7492 while (true)
7493 {
7494 var ret = input.readFieldBegin();
7495 var fname = ret.fname;
7496 var ftype = ret.ftype;
7497 var fid = ret.fid;
7498 if (ftype == Thrift.Type.STOP) {
7499 break;
7500 }
7501 switch (fid)
7502 {
7503 case 1:
7504 if (ftype == Thrift.Type.I64) {
7505 this.RecordedAtTicks = input.readI64().value;
7506 } else {
7507 input.skip(ftype);
7508 }
7509 break;
7510 case 0:
7511 input.skip(ftype);
7512 break;
7513 default:
7514 input.skip(ftype);
7515 }
7516 input.readFieldEnd();
7517 }
7518 input.readStructEnd();
7519 return;
7520};
7521
7522Pedigree.prototype.write = function(output) {
7523 output.writeStructBegin('Pedigree');
7524 if (this.RecordedAtTicks !== null && this.RecordedAtTicks !== undefined) {
7525 output.writeFieldBegin('RecordedAtTicks', Thrift.Type.I64, 1);
7526 output.writeI64(this.RecordedAtTicks);
7527 output.writeFieldEnd();
7528 }
7529 output.writeFieldStop();
7530 output.writeStructEnd();
7531 return;
7532};
7533
7534EventData = function(args) {
7535 this.Unit = null;
7536 this.Pedigree = null;
7537 if (args) {
7538 if (args.Unit !== undefined && args.Unit !== null) {
7539 this.Unit = new EventUnit(args.Unit);
7540 } else {
7541 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Unit is unset!');
7542 }
7543 if (args.Pedigree !== undefined && args.Pedigree !== null) {
7544 this.Pedigree = new Pedigree(args.Pedigree);
7545 }
7546 }
7547};
7548EventData.prototype = {};
7549EventData.prototype.read = function(input) {
7550 input.readStructBegin();
7551 while (true)
7552 {
7553 var ret = input.readFieldBegin();
7554 var fname = ret.fname;
7555 var ftype = ret.ftype;
7556 var fid = ret.fid;
7557 if (ftype == Thrift.Type.STOP) {
7558 break;
7559 }
7560 switch (fid)
7561 {
7562 case 1:
7563 if (ftype == Thrift.Type.STRUCT) {
7564 this.Unit = new EventUnit();
7565 this.Unit.read(input);
7566 } else {
7567 input.skip(ftype);
7568 }
7569 break;
7570 case 2:
7571 if (ftype == Thrift.Type.STRUCT) {
7572 this.Pedigree = new Pedigree();
7573 this.Pedigree.read(input);
7574 } else {
7575 input.skip(ftype);
7576 }
7577 break;
7578 default:
7579 input.skip(ftype);
7580 }
7581 input.readFieldEnd();
7582 }
7583 input.readStructEnd();
7584 return;
7585};
7586
7587EventData.prototype.write = function(output) {
7588 output.writeStructBegin('EventData');
7589 if (this.Unit !== null && this.Unit !== undefined) {
7590 output.writeFieldBegin('Unit', Thrift.Type.STRUCT, 1);
7591 this.Unit.write(output);
7592 output.writeFieldEnd();
7593 }
7594 if (this.Pedigree !== null && this.Pedigree !== undefined) {
7595 output.writeFieldBegin('Pedigree', Thrift.Type.STRUCT, 2);
7596 this.Pedigree.write(output);
7597 output.writeFieldEnd();
7598 }
7599 output.writeFieldStop();
7600 output.writeStructEnd();
7601 return;
7602};
7603
7604ThreeJSSceneObject = function(args) {
7605 this.MeshId = null;
7606 this.PositionX = null;
7607 this.PositionY = null;
7608 this.PositionZ = null;
7609 this.RotationX = null;
7610 this.RotationY = null;
7611 this.RotationZ = null;
7612 this.RotationW = null;
7613 this.ScaleX = null;
7614 this.ScaleY = null;
7615 this.ScaleZ = null;
7616 this.IsVisible = null;
7617 if (args) {
7618 if (args.MeshId !== undefined && args.MeshId !== null) {
7619 this.MeshId = args.MeshId;
7620 } else {
7621 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field MeshId is unset!');
7622 }
7623 if (args.PositionX !== undefined && args.PositionX !== null) {
7624 this.PositionX = args.PositionX;
7625 } else {
7626 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field PositionX is unset!');
7627 }
7628 if (args.PositionY !== undefined && args.PositionY !== null) {
7629 this.PositionY = args.PositionY;
7630 } else {
7631 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field PositionY is unset!');
7632 }
7633 if (args.PositionZ !== undefined && args.PositionZ !== null) {
7634 this.PositionZ = args.PositionZ;
7635 } else {
7636 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field PositionZ is unset!');
7637 }
7638 if (args.RotationX !== undefined && args.RotationX !== null) {
7639 this.RotationX = args.RotationX;
7640 } else {
7641 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field RotationX is unset!');
7642 }
7643 if (args.RotationY !== undefined && args.RotationY !== null) {
7644 this.RotationY = args.RotationY;
7645 } else {
7646 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field RotationY is unset!');
7647 }
7648 if (args.RotationZ !== undefined && args.RotationZ !== null) {
7649 this.RotationZ = args.RotationZ;
7650 } else {
7651 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field RotationZ is unset!');
7652 }
7653 if (args.RotationW !== undefined && args.RotationW !== null) {
7654 this.RotationW = args.RotationW;
7655 } else {
7656 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field RotationW is unset!');
7657 }
7658 if (args.ScaleX !== undefined && args.ScaleX !== null) {
7659 this.ScaleX = args.ScaleX;
7660 } else {
7661 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field ScaleX is unset!');
7662 }
7663 if (args.ScaleY !== undefined && args.ScaleY !== null) {
7664 this.ScaleY = args.ScaleY;
7665 } else {
7666 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field ScaleY is unset!');
7667 }
7668 if (args.ScaleZ !== undefined && args.ScaleZ !== null) {
7669 this.ScaleZ = args.ScaleZ;
7670 } else {
7671 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field ScaleZ is unset!');
7672 }
7673 if (args.IsVisible !== undefined && args.IsVisible !== null) {
7674 this.IsVisible = args.IsVisible;
7675 } else {
7676 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field IsVisible is unset!');
7677 }
7678 }
7679};
7680ThreeJSSceneObject.prototype = {};
7681ThreeJSSceneObject.prototype.read = function(input) {
7682 input.readStructBegin();
7683 while (true)
7684 {
7685 var ret = input.readFieldBegin();
7686 var fname = ret.fname;
7687 var ftype = ret.ftype;
7688 var fid = ret.fid;
7689 if (ftype == Thrift.Type.STOP) {
7690 break;
7691 }
7692 switch (fid)
7693 {
7694 case 1:
7695 if (ftype == Thrift.Type.I32) {
7696 this.MeshId = input.readI32().value;
7697 } else {
7698 input.skip(ftype);
7699 }
7700 break;
7701 case 2:
7702 if (ftype == Thrift.Type.DOUBLE) {
7703 this.PositionX = input.readDouble().value;
7704 } else {
7705 input.skip(ftype);
7706 }
7707 break;
7708 case 3:
7709 if (ftype == Thrift.Type.DOUBLE) {
7710 this.PositionY = input.readDouble().value;
7711 } else {
7712 input.skip(ftype);
7713 }
7714 break;
7715 case 4:
7716 if (ftype == Thrift.Type.DOUBLE) {
7717 this.PositionZ = input.readDouble().value;
7718 } else {
7719 input.skip(ftype);
7720 }
7721 break;
7722 case 5:
7723 if (ftype == Thrift.Type.DOUBLE) {
7724 this.RotationX = input.readDouble().value;
7725 } else {
7726 input.skip(ftype);
7727 }
7728 break;
7729 case 6:
7730 if (ftype == Thrift.Type.DOUBLE) {
7731 this.RotationY = input.readDouble().value;
7732 } else {
7733 input.skip(ftype);
7734 }
7735 break;
7736 case 7:
7737 if (ftype == Thrift.Type.DOUBLE) {
7738 this.RotationZ = input.readDouble().value;
7739 } else {
7740 input.skip(ftype);
7741 }
7742 break;
7743 case 8:
7744 if (ftype == Thrift.Type.DOUBLE) {
7745 this.RotationW = input.readDouble().value;
7746 } else {
7747 input.skip(ftype);
7748 }
7749 break;
7750 case 9:
7751 if (ftype == Thrift.Type.DOUBLE) {
7752 this.ScaleX = input.readDouble().value;
7753 } else {
7754 input.skip(ftype);
7755 }
7756 break;
7757 case 10:
7758 if (ftype == Thrift.Type.DOUBLE) {
7759 this.ScaleY = input.readDouble().value;
7760 } else {
7761 input.skip(ftype);
7762 }
7763 break;
7764 case 11:
7765 if (ftype == Thrift.Type.DOUBLE) {
7766 this.ScaleZ = input.readDouble().value;
7767 } else {
7768 input.skip(ftype);
7769 }
7770 break;
7771 case 12:
7772 if (ftype == Thrift.Type.BOOL) {
7773 this.IsVisible = input.readBool().value;
7774 } else {
7775 input.skip(ftype);
7776 }
7777 break;
7778 default:
7779 input.skip(ftype);
7780 }
7781 input.readFieldEnd();
7782 }
7783 input.readStructEnd();
7784 return;
7785};
7786
7787ThreeJSSceneObject.prototype.write = function(output) {
7788 output.writeStructBegin('ThreeJSSceneObject');
7789 if (this.MeshId !== null && this.MeshId !== undefined) {
7790 output.writeFieldBegin('MeshId', Thrift.Type.I32, 1);
7791 output.writeI32(this.MeshId);
7792 output.writeFieldEnd();
7793 }
7794 if (this.PositionX !== null && this.PositionX !== undefined) {
7795 output.writeFieldBegin('PositionX', Thrift.Type.DOUBLE, 2);
7796 output.writeDouble(this.PositionX);
7797 output.writeFieldEnd();
7798 }
7799 if (this.PositionY !== null && this.PositionY !== undefined) {
7800 output.writeFieldBegin('PositionY', Thrift.Type.DOUBLE, 3);
7801 output.writeDouble(this.PositionY);
7802 output.writeFieldEnd();
7803 }
7804 if (this.PositionZ !== null && this.PositionZ !== undefined) {
7805 output.writeFieldBegin('PositionZ', Thrift.Type.DOUBLE, 4);
7806 output.writeDouble(this.PositionZ);
7807 output.writeFieldEnd();
7808 }
7809 if (this.RotationX !== null && this.RotationX !== undefined) {
7810 output.writeFieldBegin('RotationX', Thrift.Type.DOUBLE, 5);
7811 output.writeDouble(this.RotationX);
7812 output.writeFieldEnd();
7813 }
7814 if (this.RotationY !== null && this.RotationY !== undefined) {
7815 output.writeFieldBegin('RotationY', Thrift.Type.DOUBLE, 6);
7816 output.writeDouble(this.RotationY);
7817 output.writeFieldEnd();
7818 }
7819 if (this.RotationZ !== null && this.RotationZ !== undefined) {
7820 output.writeFieldBegin('RotationZ', Thrift.Type.DOUBLE, 7);
7821 output.writeDouble(this.RotationZ);
7822 output.writeFieldEnd();
7823 }
7824 if (this.RotationW !== null && this.RotationW !== undefined) {
7825 output.writeFieldBegin('RotationW', Thrift.Type.DOUBLE, 8);
7826 output.writeDouble(this.RotationW);
7827 output.writeFieldEnd();
7828 }
7829 if (this.ScaleX !== null && this.ScaleX !== undefined) {
7830 output.writeFieldBegin('ScaleX', Thrift.Type.DOUBLE, 9);
7831 output.writeDouble(this.ScaleX);
7832 output.writeFieldEnd();
7833 }
7834 if (this.ScaleY !== null && this.ScaleY !== undefined) {
7835 output.writeFieldBegin('ScaleY', Thrift.Type.DOUBLE, 10);
7836 output.writeDouble(this.ScaleY);
7837 output.writeFieldEnd();
7838 }
7839 if (this.ScaleZ !== null && this.ScaleZ !== undefined) {
7840 output.writeFieldBegin('ScaleZ', Thrift.Type.DOUBLE, 11);
7841 output.writeDouble(this.ScaleZ);
7842 output.writeFieldEnd();
7843 }
7844 if (this.IsVisible !== null && this.IsVisible !== undefined) {
7845 output.writeFieldBegin('IsVisible', Thrift.Type.BOOL, 12);
7846 output.writeBool(this.IsVisible);
7847 output.writeFieldEnd();
7848 }
7849 output.writeFieldStop();
7850 output.writeStructEnd();
7851 return;
7852};
7853
7854ThreeJSGeometryData = function(args) {
7855 this.Vertices = null;
7856 this.Faces = null;
7857 this.Uvs = null;
7858 this.IsBufferedGeometry = null;
7859 if (args) {
7860 if (args.Vertices !== undefined && args.Vertices !== null) {
7861 this.Vertices = Thrift.copyList(args.Vertices, [null]);
7862 } else {
7863 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Vertices is unset!');
7864 }
7865 if (args.Faces !== undefined && args.Faces !== null) {
7866 this.Faces = Thrift.copyList(args.Faces, [null]);
7867 } else {
7868 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Faces is unset!');
7869 }
7870 if (args.Uvs !== undefined && args.Uvs !== null) {
7871 this.Uvs = Thrift.copyList(args.Uvs, [null]);
7872 }
7873 if (args.IsBufferedGeometry !== undefined && args.IsBufferedGeometry !== null) {
7874 this.IsBufferedGeometry = args.IsBufferedGeometry;
7875 } else {
7876 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field IsBufferedGeometry is unset!');
7877 }
7878 }
7879};
7880ThreeJSGeometryData.prototype = {};
7881ThreeJSGeometryData.prototype.read = function(input) {
7882 input.readStructBegin();
7883 while (true)
7884 {
7885 var ret = input.readFieldBegin();
7886 var fname = ret.fname;
7887 var ftype = ret.ftype;
7888 var fid = ret.fid;
7889 if (ftype == Thrift.Type.STOP) {
7890 break;
7891 }
7892 switch (fid)
7893 {
7894 case 1:
7895 if (ftype == Thrift.Type.LIST) {
7896 var _size48 = 0;
7897 var _rtmp352;
7898 this.Vertices = [];
7899 var _etype51 = 0;
7900 _rtmp352 = input.readListBegin();
7901 _etype51 = _rtmp352.etype;
7902 _size48 = _rtmp352.size;
7903 for (var _i53 = 0; _i53 < _size48; ++_i53)
7904 {
7905 var elem54 = null;
7906 elem54 = input.readDouble().value;
7907 this.Vertices.push(elem54);
7908 }
7909 input.readListEnd();
7910 } else {
7911 input.skip(ftype);
7912 }
7913 break;
7914 case 2:
7915 if (ftype == Thrift.Type.LIST) {
7916 var _size55 = 0;
7917 var _rtmp359;
7918 this.Faces = [];
7919 var _etype58 = 0;
7920 _rtmp359 = input.readListBegin();
7921 _etype58 = _rtmp359.etype;
7922 _size55 = _rtmp359.size;
7923 for (var _i60 = 0; _i60 < _size55; ++_i60)
7924 {
7925 var elem61 = null;
7926 elem61 = input.readI32().value;
7927 this.Faces.push(elem61);
7928 }
7929 input.readListEnd();
7930 } else {
7931 input.skip(ftype);
7932 }
7933 break;
7934 case 3:
7935 if (ftype == Thrift.Type.LIST) {
7936 var _size62 = 0;
7937 var _rtmp366;
7938 this.Uvs = [];
7939 var _etype65 = 0;
7940 _rtmp366 = input.readListBegin();
7941 _etype65 = _rtmp366.etype;
7942 _size62 = _rtmp366.size;
7943 for (var _i67 = 0; _i67 < _size62; ++_i67)
7944 {
7945 var elem68 = null;
7946 elem68 = input.readDouble().value;
7947 this.Uvs.push(elem68);
7948 }
7949 input.readListEnd();
7950 } else {
7951 input.skip(ftype);
7952 }
7953 break;
7954 case 4:
7955 if (ftype == Thrift.Type.BOOL) {
7956 this.IsBufferedGeometry = input.readBool().value;
7957 } else {
7958 input.skip(ftype);
7959 }
7960 break;
7961 default:
7962 input.skip(ftype);
7963 }
7964 input.readFieldEnd();
7965 }
7966 input.readStructEnd();
7967 return;
7968};
7969
7970ThreeJSGeometryData.prototype.write = function(output) {
7971 output.writeStructBegin('ThreeJSGeometryData');
7972 if (this.Vertices !== null && this.Vertices !== undefined) {
7973 output.writeFieldBegin('Vertices', Thrift.Type.LIST, 1);
7974 output.writeListBegin(Thrift.Type.DOUBLE, this.Vertices.length);
7975 for (var iter69 in this.Vertices)
7976 {
7977 if (this.Vertices.hasOwnProperty(iter69))
7978 {
7979 iter69 = this.Vertices[iter69];
7980 output.writeDouble(iter69);
7981 }
7982 }
7983 output.writeListEnd();
7984 output.writeFieldEnd();
7985 }
7986 if (this.Faces !== null && this.Faces !== undefined) {
7987 output.writeFieldBegin('Faces', Thrift.Type.LIST, 2);
7988 output.writeListBegin(Thrift.Type.I32, this.Faces.length);
7989 for (var iter70 in this.Faces)
7990 {
7991 if (this.Faces.hasOwnProperty(iter70))
7992 {
7993 iter70 = this.Faces[iter70];
7994 output.writeI32(iter70);
7995 }
7996 }
7997 output.writeListEnd();
7998 output.writeFieldEnd();
7999 }
8000 if (this.Uvs !== null && this.Uvs !== undefined) {
8001 output.writeFieldBegin('Uvs', Thrift.Type.LIST, 3);
8002 output.writeListBegin(Thrift.Type.DOUBLE, this.Uvs.length);
8003 for (var iter71 in this.Uvs)
8004 {
8005 if (this.Uvs.hasOwnProperty(iter71))
8006 {
8007 iter71 = this.Uvs[iter71];
8008 output.writeDouble(iter71);
8009 }
8010 }
8011 output.writeListEnd();
8012 output.writeFieldEnd();
8013 }
8014 if (this.IsBufferedGeometry !== null && this.IsBufferedGeometry !== undefined) {
8015 output.writeFieldBegin('IsBufferedGeometry', Thrift.Type.BOOL, 4);
8016 output.writeBool(this.IsBufferedGeometry);
8017 output.writeFieldEnd();
8018 }
8019 output.writeFieldStop();
8020 output.writeStructEnd();
8021 return;
8022};
8023
8024ThreeJSGeometry = function(args) {
8025 this.Uuid = null;
8026 this.Data = null;
8027 if (args) {
8028 if (args.Uuid !== undefined && args.Uuid !== null) {
8029 this.Uuid = args.Uuid;
8030 } else {
8031 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Uuid is unset!');
8032 }
8033 if (args.Data !== undefined && args.Data !== null) {
8034 this.Data = new ThreeJSGeometryData(args.Data);
8035 } else {
8036 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Data is unset!');
8037 }
8038 }
8039};
8040ThreeJSGeometry.prototype = {};
8041ThreeJSGeometry.prototype.read = function(input) {
8042 input.readStructBegin();
8043 while (true)
8044 {
8045 var ret = input.readFieldBegin();
8046 var fname = ret.fname;
8047 var ftype = ret.ftype;
8048 var fid = ret.fid;
8049 if (ftype == Thrift.Type.STOP) {
8050 break;
8051 }
8052 switch (fid)
8053 {
8054 case 1:
8055 if (ftype == Thrift.Type.STRING) {
8056 this.Uuid = input.readString().value;
8057 } else {
8058 input.skip(ftype);
8059 }
8060 break;
8061 case 2:
8062 if (ftype == Thrift.Type.STRUCT) {
8063 this.Data = new ThreeJSGeometryData();
8064 this.Data.read(input);
8065 } else {
8066 input.skip(ftype);
8067 }
8068 break;
8069 default:
8070 input.skip(ftype);
8071 }
8072 input.readFieldEnd();
8073 }
8074 input.readStructEnd();
8075 return;
8076};
8077
8078ThreeJSGeometry.prototype.write = function(output) {
8079 output.writeStructBegin('ThreeJSGeometry');
8080 if (this.Uuid !== null && this.Uuid !== undefined) {
8081 output.writeFieldBegin('Uuid', Thrift.Type.STRING, 1);
8082 output.writeString(this.Uuid);
8083 output.writeFieldEnd();
8084 }
8085 if (this.Data !== null && this.Data !== undefined) {
8086 output.writeFieldBegin('Data', Thrift.Type.STRUCT, 2);
8087 this.Data.write(output);
8088 output.writeFieldEnd();
8089 }
8090 output.writeFieldStop();
8091 output.writeStructEnd();
8092 return;
8093};
8094
8095ThreeJSMaterial = function(args) {
8096 this.Uuid = null;
8097 this.Visible = null;
8098 this.SourceHash = null;
8099 this.Color = null;
8100 this.TextureDataUri = null;
8101 this.Src = null;
8102 this.Side = null;
8103 this.Transparent = null;
8104 this.Opacity = null;
8105 this.MapOffsetX = null;
8106 this.MapOffsetY = null;
8107 this.MapRepeatX = null;
8108 this.MapRepeatY = null;
8109 this.MapWrapS = null;
8110 if (args) {
8111 if (args.Uuid !== undefined && args.Uuid !== null) {
8112 this.Uuid = args.Uuid;
8113 } else {
8114 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Uuid is unset!');
8115 }
8116 if (args.Visible !== undefined && args.Visible !== null) {
8117 this.Visible = args.Visible;
8118 } else {
8119 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Visible is unset!');
8120 }
8121 if (args.SourceHash !== undefined && args.SourceHash !== null) {
8122 this.SourceHash = args.SourceHash;
8123 } else {
8124 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field SourceHash is unset!');
8125 }
8126 if (args.Color !== undefined && args.Color !== null) {
8127 this.Color = args.Color;
8128 } else {
8129 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Color is unset!');
8130 }
8131 if (args.TextureDataUri !== undefined && args.TextureDataUri !== null) {
8132 this.TextureDataUri = args.TextureDataUri;
8133 } else {
8134 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field TextureDataUri is unset!');
8135 }
8136 if (args.Src !== undefined && args.Src !== null) {
8137 this.Src = args.Src;
8138 } else {
8139 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Src is unset!');
8140 }
8141 if (args.Side !== undefined && args.Side !== null) {
8142 this.Side = args.Side;
8143 } else {
8144 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Side is unset!');
8145 }
8146 if (args.Transparent !== undefined && args.Transparent !== null) {
8147 this.Transparent = args.Transparent;
8148 } else {
8149 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Transparent is unset!');
8150 }
8151 if (args.Opacity !== undefined && args.Opacity !== null) {
8152 this.Opacity = args.Opacity;
8153 } else {
8154 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Opacity is unset!');
8155 }
8156 if (args.MapOffsetX !== undefined && args.MapOffsetX !== null) {
8157 this.MapOffsetX = args.MapOffsetX;
8158 } else {
8159 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field MapOffsetX is unset!');
8160 }
8161 if (args.MapOffsetY !== undefined && args.MapOffsetY !== null) {
8162 this.MapOffsetY = args.MapOffsetY;
8163 } else {
8164 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field MapOffsetY is unset!');
8165 }
8166 if (args.MapRepeatX !== undefined && args.MapRepeatX !== null) {
8167 this.MapRepeatX = args.MapRepeatX;
8168 } else {
8169 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field MapRepeatX is unset!');
8170 }
8171 if (args.MapRepeatY !== undefined && args.MapRepeatY !== null) {
8172 this.MapRepeatY = args.MapRepeatY;
8173 } else {
8174 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field MapRepeatY is unset!');
8175 }
8176 if (args.MapWrapS !== undefined && args.MapWrapS !== null) {
8177 this.MapWrapS = args.MapWrapS;
8178 } else {
8179 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field MapWrapS is unset!');
8180 }
8181 }
8182};
8183ThreeJSMaterial.prototype = {};
8184ThreeJSMaterial.prototype.read = function(input) {
8185 input.readStructBegin();
8186 while (true)
8187 {
8188 var ret = input.readFieldBegin();
8189 var fname = ret.fname;
8190 var ftype = ret.ftype;
8191 var fid = ret.fid;
8192 if (ftype == Thrift.Type.STOP) {
8193 break;
8194 }
8195 switch (fid)
8196 {
8197 case 1:
8198 if (ftype == Thrift.Type.STRING) {
8199 this.Uuid = input.readString().value;
8200 } else {
8201 input.skip(ftype);
8202 }
8203 break;
8204 case 2:
8205 if (ftype == Thrift.Type.BOOL) {
8206 this.Visible = input.readBool().value;
8207 } else {
8208 input.skip(ftype);
8209 }
8210 break;
8211 case 3:
8212 if (ftype == Thrift.Type.DOUBLE) {
8213 this.SourceHash = input.readDouble().value;
8214 } else {
8215 input.skip(ftype);
8216 }
8217 break;
8218 case 4:
8219 if (ftype == Thrift.Type.I32) {
8220 this.Color = input.readI32().value;
8221 } else {
8222 input.skip(ftype);
8223 }
8224 break;
8225 case 5:
8226 if (ftype == Thrift.Type.STRING) {
8227 this.TextureDataUri = input.readBinary().value;
8228 } else {
8229 input.skip(ftype);
8230 }
8231 break;
8232 case 6:
8233 if (ftype == Thrift.Type.STRING) {
8234 this.Src = input.readString().value;
8235 } else {
8236 input.skip(ftype);
8237 }
8238 break;
8239 case 7:
8240 if (ftype == Thrift.Type.BYTE) {
8241 this.Side = input.readByte().value;
8242 } else {
8243 input.skip(ftype);
8244 }
8245 break;
8246 case 8:
8247 if (ftype == Thrift.Type.BOOL) {
8248 this.Transparent = input.readBool().value;
8249 } else {
8250 input.skip(ftype);
8251 }
8252 break;
8253 case 9:
8254 if (ftype == Thrift.Type.DOUBLE) {
8255 this.Opacity = input.readDouble().value;
8256 } else {
8257 input.skip(ftype);
8258 }
8259 break;
8260 case 10:
8261 if (ftype == Thrift.Type.DOUBLE) {
8262 this.MapOffsetX = input.readDouble().value;
8263 } else {
8264 input.skip(ftype);
8265 }
8266 break;
8267 case 11:
8268 if (ftype == Thrift.Type.DOUBLE) {
8269 this.MapOffsetY = input.readDouble().value;
8270 } else {
8271 input.skip(ftype);
8272 }
8273 break;
8274 case 12:
8275 if (ftype == Thrift.Type.DOUBLE) {
8276 this.MapRepeatX = input.readDouble().value;
8277 } else {
8278 input.skip(ftype);
8279 }
8280 break;
8281 case 13:
8282 if (ftype == Thrift.Type.DOUBLE) {
8283 this.MapRepeatY = input.readDouble().value;
8284 } else {
8285 input.skip(ftype);
8286 }
8287 break;
8288 case 14:
8289 if (ftype == Thrift.Type.I16) {
8290 this.MapWrapS = input.readI16().value;
8291 } else {
8292 input.skip(ftype);
8293 }
8294 break;
8295 default:
8296 input.skip(ftype);
8297 }
8298 input.readFieldEnd();
8299 }
8300 input.readStructEnd();
8301 return;
8302};
8303
8304ThreeJSMaterial.prototype.write = function(output) {
8305 output.writeStructBegin('ThreeJSMaterial');
8306 if (this.Uuid !== null && this.Uuid !== undefined) {
8307 output.writeFieldBegin('Uuid', Thrift.Type.STRING, 1);
8308 output.writeString(this.Uuid);
8309 output.writeFieldEnd();
8310 }
8311 if (this.Visible !== null && this.Visible !== undefined) {
8312 output.writeFieldBegin('Visible', Thrift.Type.BOOL, 2);
8313 output.writeBool(this.Visible);
8314 output.writeFieldEnd();
8315 }
8316 if (this.SourceHash !== null && this.SourceHash !== undefined) {
8317 output.writeFieldBegin('SourceHash', Thrift.Type.DOUBLE, 3);
8318 output.writeDouble(this.SourceHash);
8319 output.writeFieldEnd();
8320 }
8321 if (this.Color !== null && this.Color !== undefined) {
8322 output.writeFieldBegin('Color', Thrift.Type.I32, 4);
8323 output.writeI32(this.Color);
8324 output.writeFieldEnd();
8325 }
8326 if (this.TextureDataUri !== null && this.TextureDataUri !== undefined) {
8327 output.writeFieldBegin('TextureDataUri', Thrift.Type.STRING, 5);
8328 output.writeBinary(this.TextureDataUri);
8329 output.writeFieldEnd();
8330 }
8331 if (this.Src !== null && this.Src !== undefined) {
8332 output.writeFieldBegin('Src', Thrift.Type.STRING, 6);
8333 output.writeString(this.Src);
8334 output.writeFieldEnd();
8335 }
8336 if (this.Side !== null && this.Side !== undefined) {
8337 output.writeFieldBegin('Side', Thrift.Type.BYTE, 7);
8338 output.writeByte(this.Side);
8339 output.writeFieldEnd();
8340 }
8341 if (this.Transparent !== null && this.Transparent !== undefined) {
8342 output.writeFieldBegin('Transparent', Thrift.Type.BOOL, 8);
8343 output.writeBool(this.Transparent);
8344 output.writeFieldEnd();
8345 }
8346 if (this.Opacity !== null && this.Opacity !== undefined) {
8347 output.writeFieldBegin('Opacity', Thrift.Type.DOUBLE, 9);
8348 output.writeDouble(this.Opacity);
8349 output.writeFieldEnd();
8350 }
8351 if (this.MapOffsetX !== null && this.MapOffsetX !== undefined) {
8352 output.writeFieldBegin('MapOffsetX', Thrift.Type.DOUBLE, 10);
8353 output.writeDouble(this.MapOffsetX);
8354 output.writeFieldEnd();
8355 }
8356 if (this.MapOffsetY !== null && this.MapOffsetY !== undefined) {
8357 output.writeFieldBegin('MapOffsetY', Thrift.Type.DOUBLE, 11);
8358 output.writeDouble(this.MapOffsetY);
8359 output.writeFieldEnd();
8360 }
8361 if (this.MapRepeatX !== null && this.MapRepeatX !== undefined) {
8362 output.writeFieldBegin('MapRepeatX', Thrift.Type.DOUBLE, 12);
8363 output.writeDouble(this.MapRepeatX);
8364 output.writeFieldEnd();
8365 }
8366 if (this.MapRepeatY !== null && this.MapRepeatY !== undefined) {
8367 output.writeFieldBegin('MapRepeatY', Thrift.Type.DOUBLE, 13);
8368 output.writeDouble(this.MapRepeatY);
8369 output.writeFieldEnd();
8370 }
8371 if (this.MapWrapS !== null && this.MapWrapS !== undefined) {
8372 output.writeFieldBegin('MapWrapS', Thrift.Type.I16, 14);
8373 output.writeI16(this.MapWrapS);
8374 output.writeFieldEnd();
8375 }
8376 output.writeFieldStop();
8377 output.writeStructEnd();
8378 return;
8379};
8380
8381ThreeJSMesh = function(args) {
8382 this.MeshId = null;
8383 this.Geometry = null;
8384 this.Material = null;
8385 if (args) {
8386 if (args.MeshId !== undefined && args.MeshId !== null) {
8387 this.MeshId = args.MeshId;
8388 } else {
8389 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field MeshId is unset!');
8390 }
8391 if (args.Geometry !== undefined && args.Geometry !== null) {
8392 this.Geometry = args.Geometry;
8393 } else {
8394 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Geometry is unset!');
8395 }
8396 if (args.Material !== undefined && args.Material !== null) {
8397 this.Material = args.Material;
8398 } else {
8399 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Material is unset!');
8400 }
8401 }
8402};
8403ThreeJSMesh.prototype = {};
8404ThreeJSMesh.prototype.read = function(input) {
8405 input.readStructBegin();
8406 while (true)
8407 {
8408 var ret = input.readFieldBegin();
8409 var fname = ret.fname;
8410 var ftype = ret.ftype;
8411 var fid = ret.fid;
8412 if (ftype == Thrift.Type.STOP) {
8413 break;
8414 }
8415 switch (fid)
8416 {
8417 case 1:
8418 if (ftype == Thrift.Type.I32) {
8419 this.MeshId = input.readI32().value;
8420 } else {
8421 input.skip(ftype);
8422 }
8423 break;
8424 case 2:
8425 if (ftype == Thrift.Type.STRING) {
8426 this.Geometry = input.readString().value;
8427 } else {
8428 input.skip(ftype);
8429 }
8430 break;
8431 case 3:
8432 if (ftype == Thrift.Type.STRING) {
8433 this.Material = input.readString().value;
8434 } else {
8435 input.skip(ftype);
8436 }
8437 break;
8438 default:
8439 input.skip(ftype);
8440 }
8441 input.readFieldEnd();
8442 }
8443 input.readStructEnd();
8444 return;
8445};
8446
8447ThreeJSMesh.prototype.write = function(output) {
8448 output.writeStructBegin('ThreeJSMesh');
8449 if (this.MeshId !== null && this.MeshId !== undefined) {
8450 output.writeFieldBegin('MeshId', Thrift.Type.I32, 1);
8451 output.writeI32(this.MeshId);
8452 output.writeFieldEnd();
8453 }
8454 if (this.Geometry !== null && this.Geometry !== undefined) {
8455 output.writeFieldBegin('Geometry', Thrift.Type.STRING, 2);
8456 output.writeString(this.Geometry);
8457 output.writeFieldEnd();
8458 }
8459 if (this.Material !== null && this.Material !== undefined) {
8460 output.writeFieldBegin('Material', Thrift.Type.STRING, 3);
8461 output.writeString(this.Material);
8462 output.writeFieldEnd();
8463 }
8464 output.writeFieldStop();
8465 output.writeStructEnd();
8466 return;
8467};
8468
8469ThreeJSScene = function(args) {
8470 this.Geometries = null;
8471 this.Materials = null;
8472 this.Meshes = null;
8473 if (args) {
8474 if (args.Geometries !== undefined && args.Geometries !== null) {
8475 this.Geometries = Thrift.copyList(args.Geometries, [ThreeJSGeometry]);
8476 } else {
8477 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Geometries is unset!');
8478 }
8479 if (args.Materials !== undefined && args.Materials !== null) {
8480 this.Materials = Thrift.copyList(args.Materials, [ThreeJSMaterial]);
8481 } else {
8482 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Materials is unset!');
8483 }
8484 if (args.Meshes !== undefined && args.Meshes !== null) {
8485 this.Meshes = Thrift.copyList(args.Meshes, [ThreeJSMesh]);
8486 } else {
8487 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Meshes is unset!');
8488 }
8489 }
8490};
8491ThreeJSScene.prototype = {};
8492ThreeJSScene.prototype.read = function(input) {
8493 input.readStructBegin();
8494 while (true)
8495 {
8496 var ret = input.readFieldBegin();
8497 var fname = ret.fname;
8498 var ftype = ret.ftype;
8499 var fid = ret.fid;
8500 if (ftype == Thrift.Type.STOP) {
8501 break;
8502 }
8503 switch (fid)
8504 {
8505 case 1:
8506 if (ftype == Thrift.Type.LIST) {
8507 var _size72 = 0;
8508 var _rtmp376;
8509 this.Geometries = [];
8510 var _etype75 = 0;
8511 _rtmp376 = input.readListBegin();
8512 _etype75 = _rtmp376.etype;
8513 _size72 = _rtmp376.size;
8514 for (var _i77 = 0; _i77 < _size72; ++_i77)
8515 {
8516 var elem78 = null;
8517 elem78 = new ThreeJSGeometry();
8518 elem78.read(input);
8519 this.Geometries.push(elem78);
8520 }
8521 input.readListEnd();
8522 } else {
8523 input.skip(ftype);
8524 }
8525 break;
8526 case 2:
8527 if (ftype == Thrift.Type.LIST) {
8528 var _size79 = 0;
8529 var _rtmp383;
8530 this.Materials = [];
8531 var _etype82 = 0;
8532 _rtmp383 = input.readListBegin();
8533 _etype82 = _rtmp383.etype;
8534 _size79 = _rtmp383.size;
8535 for (var _i84 = 0; _i84 < _size79; ++_i84)
8536 {
8537 var elem85 = null;
8538 elem85 = new ThreeJSMaterial();
8539 elem85.read(input);
8540 this.Materials.push(elem85);
8541 }
8542 input.readListEnd();
8543 } else {
8544 input.skip(ftype);
8545 }
8546 break;
8547 case 3:
8548 if (ftype == Thrift.Type.LIST) {
8549 var _size86 = 0;
8550 var _rtmp390;
8551 this.Meshes = [];
8552 var _etype89 = 0;
8553 _rtmp390 = input.readListBegin();
8554 _etype89 = _rtmp390.etype;
8555 _size86 = _rtmp390.size;
8556 for (var _i91 = 0; _i91 < _size86; ++_i91)
8557 {
8558 var elem92 = null;
8559 elem92 = new ThreeJSMesh();
8560 elem92.read(input);
8561 this.Meshes.push(elem92);
8562 }
8563 input.readListEnd();
8564 } else {
8565 input.skip(ftype);
8566 }
8567 break;
8568 default:
8569 input.skip(ftype);
8570 }
8571 input.readFieldEnd();
8572 }
8573 input.readStructEnd();
8574 return;
8575};
8576
8577ThreeJSScene.prototype.write = function(output) {
8578 output.writeStructBegin('ThreeJSScene');
8579 if (this.Geometries !== null && this.Geometries !== undefined) {
8580 output.writeFieldBegin('Geometries', Thrift.Type.LIST, 1);
8581 output.writeListBegin(Thrift.Type.STRUCT, this.Geometries.length);
8582 for (var iter93 in this.Geometries)
8583 {
8584 if (this.Geometries.hasOwnProperty(iter93))
8585 {
8586 iter93 = this.Geometries[iter93];
8587 iter93.write(output);
8588 }
8589 }
8590 output.writeListEnd();
8591 output.writeFieldEnd();
8592 }
8593 if (this.Materials !== null && this.Materials !== undefined) {
8594 output.writeFieldBegin('Materials', Thrift.Type.LIST, 2);
8595 output.writeListBegin(Thrift.Type.STRUCT, this.Materials.length);
8596 for (var iter94 in this.Materials)
8597 {
8598 if (this.Materials.hasOwnProperty(iter94))
8599 {
8600 iter94 = this.Materials[iter94];
8601 iter94.write(output);
8602 }
8603 }
8604 output.writeListEnd();
8605 output.writeFieldEnd();
8606 }
8607 if (this.Meshes !== null && this.Meshes !== undefined) {
8608 output.writeFieldBegin('Meshes', Thrift.Type.LIST, 3);
8609 output.writeListBegin(Thrift.Type.STRUCT, this.Meshes.length);
8610 for (var iter95 in this.Meshes)
8611 {
8612 if (this.Meshes.hasOwnProperty(iter95))
8613 {
8614 iter95 = this.Meshes[iter95];
8615 iter95.write(output);
8616 }
8617 }
8618 output.writeListEnd();
8619 output.writeFieldEnd();
8620 }
8621 output.writeFieldStop();
8622 output.writeStructEnd();
8623 return;
8624};
8625
8626ThreeJSUpdate = function(args) {
8627 this.SceneObjectUpdates = null;
8628 this.SceneObjectsToRemove = null;
8629 this.Index = null;
8630 if (args) {
8631 if (args.SceneObjectUpdates !== undefined && args.SceneObjectUpdates !== null) {
8632 this.SceneObjectUpdates = Thrift.copyList(args.SceneObjectUpdates, [ThreeJSSceneObject]);
8633 }
8634 if (args.SceneObjectsToRemove !== undefined && args.SceneObjectsToRemove !== null) {
8635 this.SceneObjectsToRemove = Thrift.copyList(args.SceneObjectsToRemove, [null]);
8636 }
8637 if (args.Index !== undefined && args.Index !== null) {
8638 this.Index = args.Index;
8639 } else {
8640 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field Index is unset!');
8641 }
8642 }
8643};
8644ThreeJSUpdate.prototype = {};
8645ThreeJSUpdate.prototype.read = function(input) {
8646 input.readStructBegin();
8647 while (true)
8648 {
8649 var ret = input.readFieldBegin();
8650 var fname = ret.fname;
8651 var ftype = ret.ftype;
8652 var fid = ret.fid;
8653 if (ftype == Thrift.Type.STOP) {
8654 break;
8655 }
8656 switch (fid)
8657 {
8658 case 1:
8659 if (ftype == Thrift.Type.LIST) {
8660 var _size96 = 0;
8661 var _rtmp3100;
8662 this.SceneObjectUpdates = [];
8663 var _etype99 = 0;
8664 _rtmp3100 = input.readListBegin();
8665 _etype99 = _rtmp3100.etype;
8666 _size96 = _rtmp3100.size;
8667 for (var _i101 = 0; _i101 < _size96; ++_i101)
8668 {
8669 var elem102 = null;
8670 elem102 = new ThreeJSSceneObject();
8671 elem102.read(input);
8672 this.SceneObjectUpdates.push(elem102);
8673 }
8674 input.readListEnd();
8675 } else {
8676 input.skip(ftype);
8677 }
8678 break;
8679 case 2:
8680 if (ftype == Thrift.Type.LIST) {
8681 var _size103 = 0;
8682 var _rtmp3107;
8683 this.SceneObjectsToRemove = [];
8684 var _etype106 = 0;
8685 _rtmp3107 = input.readListBegin();
8686 _etype106 = _rtmp3107.etype;
8687 _size103 = _rtmp3107.size;
8688 for (var _i108 = 0; _i108 < _size103; ++_i108)
8689 {
8690 var elem109 = null;
8691 elem109 = input.readI32().value;
8692 this.SceneObjectsToRemove.push(elem109);
8693 }
8694 input.readListEnd();
8695 } else {
8696 input.skip(ftype);
8697 }
8698 break;
8699 case 3:
8700 if (ftype == Thrift.Type.I32) {
8701 this.Index = input.readI32().value;
8702 } else {
8703 input.skip(ftype);
8704 }
8705 break;
8706 default:
8707 input.skip(ftype);
8708 }
8709 input.readFieldEnd();
8710 }
8711 input.readStructEnd();
8712 return;
8713};
8714
8715ThreeJSUpdate.prototype.write = function(output) {
8716 output.writeStructBegin('ThreeJSUpdate');
8717 if (this.SceneObjectUpdates !== null && this.SceneObjectUpdates !== undefined) {
8718 output.writeFieldBegin('SceneObjectUpdates', Thrift.Type.LIST, 1);
8719 output.writeListBegin(Thrift.Type.STRUCT, this.SceneObjectUpdates.length);
8720 for (var iter110 in this.SceneObjectUpdates)
8721 {
8722 if (this.SceneObjectUpdates.hasOwnProperty(iter110))
8723 {
8724 iter110 = this.SceneObjectUpdates[iter110];
8725 iter110.write(output);
8726 }
8727 }
8728 output.writeListEnd();
8729 output.writeFieldEnd();
8730 }
8731 if (this.SceneObjectsToRemove !== null && this.SceneObjectsToRemove !== undefined) {
8732 output.writeFieldBegin('SceneObjectsToRemove', Thrift.Type.LIST, 2);
8733 output.writeListBegin(Thrift.Type.I32, this.SceneObjectsToRemove.length);
8734 for (var iter111 in this.SceneObjectsToRemove)
8735 {
8736 if (this.SceneObjectsToRemove.hasOwnProperty(iter111))
8737 {
8738 iter111 = this.SceneObjectsToRemove[iter111];
8739 output.writeI32(iter111);
8740 }
8741 }
8742 output.writeListEnd();
8743 output.writeFieldEnd();
8744 }
8745 if (this.Index !== null && this.Index !== undefined) {
8746 output.writeFieldBegin('Index', Thrift.Type.I32, 3);
8747 output.writeI32(this.Index);
8748 output.writeFieldEnd();
8749 }
8750 output.writeFieldStop();
8751 output.writeStructEnd();
8752 return;
8753};
8754
8755BindCallMessage = function(args) {
8756 this.BindingName = null;
8757 this.RequestID = null;
8758 this.ThreeJSUpdate = null;
8759 this.ThreeJSScene = null;
8760 this.ArgumentObjectType = null;
8761 this.ArgumentObjectArg0Name = null;
8762 this.ArgumentObjectArg0StringValue = null;
8763 this.ArgumentObjectArg0NumericValue = null;
8764 this.ArgumentObjectArg1Name = null;
8765 this.ArgumentObjectArg1StringValue = null;
8766 this.ArgumentObjectArg1NumericValue = null;
8767 this.ArgumentObjectArg2Name = null;
8768 this.ArgumentObjectArg2StringValue = null;
8769 this.ArgumentObjectArg2NumericValue = null;
8770 this.ArgumentObjectArg3Name = null;
8771 this.ArgumentObjectArg3StringValue = null;
8772 this.ArgumentObjectArg3NumericValue = null;
8773 this.ArgumentObjectArg4Name = null;
8774 this.ArgumentObjectArg4StringValue = null;
8775 this.ArgumentObjectArg4NumericValue = null;
8776 this.ArgumentObjectArg5Name = null;
8777 this.ArgumentObjectArg5StringValue = null;
8778 this.ArgumentObjectArg5NumericValue = null;
8779 this.ArgumentObjectArg6Name = null;
8780 this.ArgumentObjectArg6StringValue = null;
8781 this.ArgumentObjectArg6NumericValue = null;
8782 this.ArgumentObjectArg7Name = null;
8783 this.ArgumentObjectArg7StringValue = null;
8784 this.ArgumentObjectArg7NumericValue = null;
8785 this.ArgumentObjectArg8Name = null;
8786 this.ArgumentObjectArg8StringValue = null;
8787 this.ArgumentObjectArg8NumericValue = null;
8788 this.ArgumentObjectArg9Name = null;
8789 this.ArgumentObjectArg9StringValue = null;
8790 this.ArgumentObjectArg9NumericValue = null;
8791 if (args) {
8792 if (args.BindingName !== undefined && args.BindingName !== null) {
8793 this.BindingName = args.BindingName;
8794 } else {
8795 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field BindingName is unset!');
8796 }
8797 if (args.RequestID !== undefined && args.RequestID !== null) {
8798 this.RequestID = args.RequestID;
8799 } else {
8800 throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field RequestID is unset!');
8801 }
8802 if (args.ThreeJSUpdate !== undefined && args.ThreeJSUpdate !== null) {
8803 this.ThreeJSUpdate = new ThreeJSUpdate(args.ThreeJSUpdate);
8804 }
8805 if (args.ThreeJSScene !== undefined && args.ThreeJSScene !== null) {
8806 this.ThreeJSScene = new ThreeJSScene(args.ThreeJSScene);
8807 }
8808 if (args.ArgumentObjectType !== undefined && args.ArgumentObjectType !== null) {
8809 this.ArgumentObjectType = args.ArgumentObjectType;
8810 }
8811 if (args.ArgumentObjectArg0Name !== undefined && args.ArgumentObjectArg0Name !== null) {
8812 this.ArgumentObjectArg0Name = args.ArgumentObjectArg0Name;
8813 }
8814 if (args.ArgumentObjectArg0StringValue !== undefined && args.ArgumentObjectArg0StringValue !== null) {
8815 this.ArgumentObjectArg0StringValue = args.ArgumentObjectArg0StringValue;
8816 }
8817 if (args.ArgumentObjectArg0NumericValue !== undefined && args.ArgumentObjectArg0NumericValue !== null) {
8818 this.ArgumentObjectArg0NumericValue = args.ArgumentObjectArg0NumericValue;
8819 }
8820 if (args.ArgumentObjectArg1Name !== undefined && args.ArgumentObjectArg1Name !== null) {
8821 this.ArgumentObjectArg1Name = args.ArgumentObjectArg1Name;
8822 }
8823 if (args.ArgumentObjectArg1StringValue !== undefined && args.ArgumentObjectArg1StringValue !== null) {
8824 this.ArgumentObjectArg1StringValue = args.ArgumentObjectArg1StringValue;
8825 }
8826 if (args.ArgumentObjectArg1NumericValue !== undefined && args.ArgumentObjectArg1NumericValue !== null) {
8827 this.ArgumentObjectArg1NumericValue = args.ArgumentObjectArg1NumericValue;
8828 }
8829 if (args.ArgumentObjectArg2Name !== undefined && args.ArgumentObjectArg2Name !== null) {
8830 this.ArgumentObjectArg2Name = args.ArgumentObjectArg2Name;
8831 }
8832 if (args.ArgumentObjectArg2StringValue !== undefined && args.ArgumentObjectArg2StringValue !== null) {
8833 this.ArgumentObjectArg2StringValue = args.ArgumentObjectArg2StringValue;
8834 }
8835 if (args.ArgumentObjectArg2NumericValue !== undefined && args.ArgumentObjectArg2NumericValue !== null) {
8836 this.ArgumentObjectArg2NumericValue = args.ArgumentObjectArg2NumericValue;
8837 }
8838 if (args.ArgumentObjectArg3Name !== undefined && args.ArgumentObjectArg3Name !== null) {
8839 this.ArgumentObjectArg3Name = args.ArgumentObjectArg3Name;
8840 }
8841 if (args.ArgumentObjectArg3StringValue !== undefined && args.ArgumentObjectArg3StringValue !== null) {
8842 this.ArgumentObjectArg3StringValue = args.ArgumentObjectArg3StringValue;
8843 }
8844 if (args.ArgumentObjectArg3NumericValue !== undefined && args.ArgumentObjectArg3NumericValue !== null) {
8845 this.ArgumentObjectArg3NumericValue = args.ArgumentObjectArg3NumericValue;
8846 }
8847 if (args.ArgumentObjectArg4Name !== undefined && args.ArgumentObjectArg4Name !== null) {
8848 this.ArgumentObjectArg4Name = args.ArgumentObjectArg4Name;
8849 }
8850 if (args.ArgumentObjectArg4StringValue !== undefined && args.ArgumentObjectArg4StringValue !== null) {
8851 this.ArgumentObjectArg4StringValue = args.ArgumentObjectArg4StringValue;
8852 }
8853 if (args.ArgumentObjectArg4NumericValue !== undefined && args.ArgumentObjectArg4NumericValue !== null) {
8854 this.ArgumentObjectArg4NumericValue = args.ArgumentObjectArg4NumericValue;
8855 }
8856 if (args.ArgumentObjectArg5Name !== undefined && args.ArgumentObjectArg5Name !== null) {
8857 this.ArgumentObjectArg5Name = args.ArgumentObjectArg5Name;
8858 }
8859 if (args.ArgumentObjectArg5StringValue !== undefined && args.ArgumentObjectArg5StringValue !== null) {
8860 this.ArgumentObjectArg5StringValue = args.ArgumentObjectArg5StringValue;
8861 }
8862 if (args.ArgumentObjectArg5NumericValue !== undefined && args.ArgumentObjectArg5NumericValue !== null) {
8863 this.ArgumentObjectArg5NumericValue = args.ArgumentObjectArg5NumericValue;
8864 }
8865 if (args.ArgumentObjectArg6Name !== undefined && args.ArgumentObjectArg6Name !== null) {
8866 this.ArgumentObjectArg6Name = args.ArgumentObjectArg6Name;
8867 }
8868 if (args.ArgumentObjectArg6StringValue !== undefined && args.ArgumentObjectArg6StringValue !== null) {
8869 this.ArgumentObjectArg6StringValue = args.ArgumentObjectArg6StringValue;
8870 }
8871 if (args.ArgumentObjectArg6NumericValue !== undefined && args.ArgumentObjectArg6NumericValue !== null) {
8872 this.ArgumentObjectArg6NumericValue = args.ArgumentObjectArg6NumericValue;
8873 }
8874 if (args.ArgumentObjectArg7Name !== undefined && args.ArgumentObjectArg7Name !== null) {
8875 this.ArgumentObjectArg7Name = args.ArgumentObjectArg7Name;
8876 }
8877 if (args.ArgumentObjectArg7StringValue !== undefined && args.ArgumentObjectArg7StringValue !== null) {
8878 this.ArgumentObjectArg7StringValue = args.ArgumentObjectArg7StringValue;
8879 }
8880 if (args.ArgumentObjectArg7NumericValue !== undefined && args.ArgumentObjectArg7NumericValue !== null) {
8881 this.ArgumentObjectArg7NumericValue = args.ArgumentObjectArg7NumericValue;
8882 }
8883 if (args.ArgumentObjectArg8Name !== undefined && args.ArgumentObjectArg8Name !== null) {
8884 this.ArgumentObjectArg8Name = args.ArgumentObjectArg8Name;
8885 }
8886 if (args.ArgumentObjectArg8StringValue !== undefined && args.ArgumentObjectArg8StringValue !== null) {
8887 this.ArgumentObjectArg8StringValue = args.ArgumentObjectArg8StringValue;
8888 }
8889 if (args.ArgumentObjectArg8NumericValue !== undefined && args.ArgumentObjectArg8NumericValue !== null) {
8890 this.ArgumentObjectArg8NumericValue = args.ArgumentObjectArg8NumericValue;
8891 }
8892 if (args.ArgumentObjectArg9Name !== undefined && args.ArgumentObjectArg9Name !== null) {
8893 this.ArgumentObjectArg9Name = args.ArgumentObjectArg9Name;
8894 }
8895 if (args.ArgumentObjectArg9StringValue !== undefined && args.ArgumentObjectArg9StringValue !== null) {
8896 this.ArgumentObjectArg9StringValue = args.ArgumentObjectArg9StringValue;
8897 }
8898 if (args.ArgumentObjectArg9NumericValue !== undefined && args.ArgumentObjectArg9NumericValue !== null) {
8899 this.ArgumentObjectArg9NumericValue = args.ArgumentObjectArg9NumericValue;
8900 }
8901 }
8902};
8903BindCallMessage.prototype = {};
8904BindCallMessage.prototype.read = function(input) {
8905 input.readStructBegin();
8906 while (true)
8907 {
8908 var ret = input.readFieldBegin();
8909 var fname = ret.fname;
8910 var ftype = ret.ftype;
8911 var fid = ret.fid;
8912 if (ftype == Thrift.Type.STOP) {
8913 break;
8914 }
8915 switch (fid)
8916 {
8917 case 1:
8918 if (ftype == Thrift.Type.STRING) {
8919 this.BindingName = input.readString().value;
8920 } else {
8921 input.skip(ftype);
8922 }
8923 break;
8924 case 2:
8925 if (ftype == Thrift.Type.I32) {
8926 this.RequestID = input.readI32().value;
8927 } else {
8928 input.skip(ftype);
8929 }
8930 break;
8931 case 3:
8932 if (ftype == Thrift.Type.STRUCT) {
8933 this.ThreeJSUpdate = new ThreeJSUpdate();
8934 this.ThreeJSUpdate.read(input);
8935 } else {
8936 input.skip(ftype);
8937 }
8938 break;
8939 case 4:
8940 if (ftype == Thrift.Type.STRUCT) {
8941 this.ThreeJSScene = new ThreeJSScene();
8942 this.ThreeJSScene.read(input);
8943 } else {
8944 input.skip(ftype);
8945 }
8946 break;
8947 case 5:
8948 if (ftype == Thrift.Type.STRING) {
8949 this.ArgumentObjectType = input.readString().value;
8950 } else {
8951 input.skip(ftype);
8952 }
8953 break;
8954 case 6:
8955 if (ftype == Thrift.Type.STRING) {
8956 this.ArgumentObjectArg0Name = input.readString().value;
8957 } else {
8958 input.skip(ftype);
8959 }
8960 break;
8961 case 7:
8962 if (ftype == Thrift.Type.STRING) {
8963 this.ArgumentObjectArg0StringValue = input.readString().value;
8964 } else {
8965 input.skip(ftype);
8966 }
8967 break;
8968 case 8:
8969 if (ftype == Thrift.Type.DOUBLE) {
8970 this.ArgumentObjectArg0NumericValue = input.readDouble().value;
8971 } else {
8972 input.skip(ftype);
8973 }
8974 break;
8975 case 9:
8976 if (ftype == Thrift.Type.STRING) {
8977 this.ArgumentObjectArg1Name = input.readString().value;
8978 } else {
8979 input.skip(ftype);
8980 }
8981 break;
8982 case 10:
8983 if (ftype == Thrift.Type.STRING) {
8984 this.ArgumentObjectArg1StringValue = input.readString().value;
8985 } else {
8986 input.skip(ftype);
8987 }
8988 break;
8989 case 11:
8990 if (ftype == Thrift.Type.DOUBLE) {
8991 this.ArgumentObjectArg1NumericValue = input.readDouble().value;
8992 } else {
8993 input.skip(ftype);
8994 }
8995 break;
8996 case 12:
8997 if (ftype == Thrift.Type.STRING) {
8998 this.ArgumentObjectArg2Name = input.readString().value;
8999 } else {
9000 input.skip(ftype);
9001 }
9002 break;
9003 case 13:
9004 if (ftype == Thrift.Type.STRING) {
9005 this.ArgumentObjectArg2StringValue = input.readString().value;
9006 } else {
9007 input.skip(ftype);
9008 }
9009 break;
9010 case 14:
9011 if (ftype == Thrift.Type.DOUBLE) {
9012 this.ArgumentObjectArg2NumericValue = input.readDouble().value;
9013 } else {
9014 input.skip(ftype);
9015 }
9016 break;
9017 case 15:
9018 if (ftype == Thrift.Type.STRING) {
9019 this.ArgumentObjectArg3Name = input.readString().value;
9020 } else {
9021 input.skip(ftype);
9022 }
9023 break;
9024 case 16:
9025 if (ftype == Thrift.Type.STRING) {
9026 this.ArgumentObjectArg3StringValue = input.readString().value;
9027 } else {
9028 input.skip(ftype);
9029 }
9030 break;
9031 case 17:
9032 if (ftype == Thrift.Type.DOUBLE) {
9033 this.ArgumentObjectArg3NumericValue = input.readDouble().value;
9034 } else {
9035 input.skip(ftype);
9036 }
9037 break;
9038 case 18:
9039 if (ftype == Thrift.Type.STRING) {
9040 this.ArgumentObjectArg4Name = input.readString().value;
9041 } else {
9042 input.skip(ftype);
9043 }
9044 break;
9045 case 19:
9046 if (ftype == Thrift.Type.STRING) {
9047 this.ArgumentObjectArg4StringValue = input.readString().value;
9048 } else {
9049 input.skip(ftype);
9050 }
9051 break;
9052 case 20:
9053 if (ftype == Thrift.Type.DOUBLE) {
9054 this.ArgumentObjectArg4NumericValue = input.readDouble().value;
9055 } else {
9056 input.skip(ftype);
9057 }
9058 break;
9059 case 21:
9060 if (ftype == Thrift.Type.STRING) {
9061 this.ArgumentObjectArg5Name = input.readString().value;
9062 } else {
9063 input.skip(ftype);
9064 }
9065 break;
9066 case 22:
9067 if (ftype == Thrift.Type.STRING) {
9068 this.ArgumentObjectArg5StringValue = input.readString().value;
9069 } else {
9070 input.skip(ftype);
9071 }
9072 break;
9073 case 23:
9074 if (ftype == Thrift.Type.DOUBLE) {
9075 this.ArgumentObjectArg5NumericValue = input.readDouble().value;
9076 } else {
9077 input.skip(ftype);
9078 }
9079 break;
9080 case 24:
9081 if (ftype == Thrift.Type.STRING) {
9082 this.ArgumentObjectArg6Name = input.readString().value;
9083 } else {
9084 input.skip(ftype);
9085 }
9086 break;
9087 case 25:
9088 if (ftype == Thrift.Type.STRING) {
9089 this.ArgumentObjectArg6StringValue = input.readString().value;
9090 } else {
9091 input.skip(ftype);
9092 }
9093 break;
9094 case 26:
9095 if (ftype == Thrift.Type.DOUBLE) {
9096 this.ArgumentObjectArg6NumericValue = input.readDouble().value;
9097 } else {
9098 input.skip(ftype);
9099 }
9100 break;
9101 case 27:
9102 if (ftype == Thrift.Type.STRING) {
9103 this.ArgumentObjectArg7Name = input.readString().value;
9104 } else {
9105 input.skip(ftype);
9106 }
9107 break;
9108 case 28:
9109 if (ftype == Thrift.Type.STRING) {
9110 this.ArgumentObjectArg7StringValue = input.readString().value;
9111 } else {
9112 input.skip(ftype);
9113 }
9114 break;
9115 case 29:
9116 if (ftype == Thrift.Type.DOUBLE) {
9117 this.ArgumentObjectArg7NumericValue = input.readDouble().value;
9118 } else {
9119 input.skip(ftype);
9120 }
9121 break;
9122 case 30:
9123 if (ftype == Thrift.Type.STRING) {
9124 this.ArgumentObjectArg8Name = input.readString().value;
9125 } else {
9126 input.skip(ftype);
9127 }
9128 break;
9129 case 31:
9130 if (ftype == Thrift.Type.STRING) {
9131 this.ArgumentObjectArg8StringValue = input.readString().value;
9132 } else {
9133 input.skip(ftype);
9134 }
9135 break;
9136 case 32:
9137 if (ftype == Thrift.Type.DOUBLE) {
9138 this.ArgumentObjectArg8NumericValue = input.readDouble().value;
9139 } else {
9140 input.skip(ftype);
9141 }
9142 break;
9143 case 33:
9144 if (ftype == Thrift.Type.STRING) {
9145 this.ArgumentObjectArg9Name = input.readString().value;
9146 } else {
9147 input.skip(ftype);
9148 }
9149 break;
9150 case 34:
9151 if (ftype == Thrift.Type.STRING) {
9152 this.ArgumentObjectArg9StringValue = input.readString().value;
9153 } else {
9154 input.skip(ftype);
9155 }
9156 break;
9157 case 35:
9158 if (ftype == Thrift.Type.DOUBLE) {
9159 this.ArgumentObjectArg9NumericValue = input.readDouble().value;
9160 } else {
9161 input.skip(ftype);
9162 }
9163 break;
9164 default:
9165 input.skip(ftype);
9166 }
9167 input.readFieldEnd();
9168 }
9169 input.readStructEnd();
9170 return;
9171};
9172
9173BindCallMessage.prototype.write = function(output) {
9174 output.writeStructBegin('BindCallMessage');
9175 if (this.BindingName !== null && this.BindingName !== undefined) {
9176 output.writeFieldBegin('BindingName', Thrift.Type.STRING, 1);
9177 output.writeString(this.BindingName);
9178 output.writeFieldEnd();
9179 }
9180 if (this.RequestID !== null && this.RequestID !== undefined) {
9181 output.writeFieldBegin('RequestID', Thrift.Type.I32, 2);
9182 output.writeI32(this.RequestID);
9183 output.writeFieldEnd();
9184 }
9185 if (this.ThreeJSUpdate !== null && this.ThreeJSUpdate !== undefined) {
9186 output.writeFieldBegin('ThreeJSUpdate', Thrift.Type.STRUCT, 3);
9187 this.ThreeJSUpdate.write(output);
9188 output.writeFieldEnd();
9189 }
9190 if (this.ThreeJSScene !== null && this.ThreeJSScene !== undefined) {
9191 output.writeFieldBegin('ThreeJSScene', Thrift.Type.STRUCT, 4);
9192 this.ThreeJSScene.write(output);
9193 output.writeFieldEnd();
9194 }
9195 if (this.ArgumentObjectType !== null && this.ArgumentObjectType !== undefined) {
9196 output.writeFieldBegin('ArgumentObjectType', Thrift.Type.STRING, 5);
9197 output.writeString(this.ArgumentObjectType);
9198 output.writeFieldEnd();
9199 }
9200 if (this.ArgumentObjectArg0Name !== null && this.ArgumentObjectArg0Name !== undefined) {
9201 output.writeFieldBegin('ArgumentObjectArg0Name', Thrift.Type.STRING, 6);
9202 output.writeString(this.ArgumentObjectArg0Name);
9203 output.writeFieldEnd();
9204 }
9205 if (this.ArgumentObjectArg0StringValue !== null && this.ArgumentObjectArg0StringValue !== undefined) {
9206 output.writeFieldBegin('ArgumentObjectArg0StringValue', Thrift.Type.STRING, 7);
9207 output.writeString(this.ArgumentObjectArg0StringValue);
9208 output.writeFieldEnd();
9209 }
9210 if (this.ArgumentObjectArg0NumericValue !== null && this.ArgumentObjectArg0NumericValue !== undefined) {
9211 output.writeFieldBegin('ArgumentObjectArg0NumericValue', Thrift.Type.DOUBLE, 8);
9212 output.writeDouble(this.ArgumentObjectArg0NumericValue);
9213 output.writeFieldEnd();
9214 }
9215 if (this.ArgumentObjectArg1Name !== null && this.ArgumentObjectArg1Name !== undefined) {
9216 output.writeFieldBegin('ArgumentObjectArg1Name', Thrift.Type.STRING, 9);
9217 output.writeString(this.ArgumentObjectArg1Name);
9218 output.writeFieldEnd();
9219 }
9220 if (this.ArgumentObjectArg1StringValue !== null && this.ArgumentObjectArg1StringValue !== undefined) {
9221 output.writeFieldBegin('ArgumentObjectArg1StringValue', Thrift.Type.STRING, 10);
9222 output.writeString(this.ArgumentObjectArg1StringValue);
9223 output.writeFieldEnd();
9224 }
9225 if (this.ArgumentObjectArg1NumericValue !== null && this.ArgumentObjectArg1NumericValue !== undefined) {
9226 output.writeFieldBegin('ArgumentObjectArg1NumericValue', Thrift.Type.DOUBLE, 11);
9227 output.writeDouble(this.ArgumentObjectArg1NumericValue);
9228 output.writeFieldEnd();
9229 }
9230 if (this.ArgumentObjectArg2Name !== null && this.ArgumentObjectArg2Name !== undefined) {
9231 output.writeFieldBegin('ArgumentObjectArg2Name', Thrift.Type.STRING, 12);
9232 output.writeString(this.ArgumentObjectArg2Name);
9233 output.writeFieldEnd();
9234 }
9235 if (this.ArgumentObjectArg2StringValue !== null && this.ArgumentObjectArg2StringValue !== undefined) {
9236 output.writeFieldBegin('ArgumentObjectArg2StringValue', Thrift.Type.STRING, 13);
9237 output.writeString(this.ArgumentObjectArg2StringValue);
9238 output.writeFieldEnd();
9239 }
9240 if (this.ArgumentObjectArg2NumericValue !== null && this.ArgumentObjectArg2NumericValue !== undefined) {
9241 output.writeFieldBegin('ArgumentObjectArg2NumericValue', Thrift.Type.DOUBLE, 14);
9242 output.writeDouble(this.ArgumentObjectArg2NumericValue);
9243 output.writeFieldEnd();
9244 }
9245 if (this.ArgumentObjectArg3Name !== null && this.ArgumentObjectArg3Name !== undefined) {
9246 output.writeFieldBegin('ArgumentObjectArg3Name', Thrift.Type.STRING, 15);
9247 output.writeString(this.ArgumentObjectArg3Name);
9248 output.writeFieldEnd();
9249 }
9250 if (this.ArgumentObjectArg3StringValue !== null && this.ArgumentObjectArg3StringValue !== undefined) {
9251 output.writeFieldBegin('ArgumentObjectArg3StringValue', Thrift.Type.STRING, 16);
9252 output.writeString(this.ArgumentObjectArg3StringValue);
9253 output.writeFieldEnd();
9254 }
9255 if (this.ArgumentObjectArg3NumericValue !== null && this.ArgumentObjectArg3NumericValue !== undefined) {
9256 output.writeFieldBegin('ArgumentObjectArg3NumericValue', Thrift.Type.DOUBLE, 17);
9257 output.writeDouble(this.ArgumentObjectArg3NumericValue);
9258 output.writeFieldEnd();
9259 }
9260 if (this.ArgumentObjectArg4Name !== null && this.ArgumentObjectArg4Name !== undefined) {
9261 output.writeFieldBegin('ArgumentObjectArg4Name', Thrift.Type.STRING, 18);
9262 output.writeString(this.ArgumentObjectArg4Name);
9263 output.writeFieldEnd();
9264 }
9265 if (this.ArgumentObjectArg4StringValue !== null && this.ArgumentObjectArg4StringValue !== undefined) {
9266 output.writeFieldBegin('ArgumentObjectArg4StringValue', Thrift.Type.STRING, 19);
9267 output.writeString(this.ArgumentObjectArg4StringValue);
9268 output.writeFieldEnd();
9269 }
9270 if (this.ArgumentObjectArg4NumericValue !== null && this.ArgumentObjectArg4NumericValue !== undefined) {
9271 output.writeFieldBegin('ArgumentObjectArg4NumericValue', Thrift.Type.DOUBLE, 20);
9272 output.writeDouble(this.ArgumentObjectArg4NumericValue);
9273 output.writeFieldEnd();
9274 }
9275 if (this.ArgumentObjectArg5Name !== null && this.ArgumentObjectArg5Name !== undefined) {
9276 output.writeFieldBegin('ArgumentObjectArg5Name', Thrift.Type.STRING, 21);
9277 output.writeString(this.ArgumentObjectArg5Name);
9278 output.writeFieldEnd();
9279 }
9280 if (this.ArgumentObjectArg5StringValue !== null && this.ArgumentObjectArg5StringValue !== undefined) {
9281 output.writeFieldBegin('ArgumentObjectArg5StringValue', Thrift.Type.STRING, 22);
9282 output.writeString(this.ArgumentObjectArg5StringValue);
9283 output.writeFieldEnd();
9284 }
9285 if (this.ArgumentObjectArg5NumericValue !== null && this.ArgumentObjectArg5NumericValue !== undefined) {
9286 output.writeFieldBegin('ArgumentObjectArg5NumericValue', Thrift.Type.DOUBLE, 23);
9287 output.writeDouble(this.ArgumentObjectArg5NumericValue);
9288 output.writeFieldEnd();
9289 }
9290 if (this.ArgumentObjectArg6Name !== null && this.ArgumentObjectArg6Name !== undefined) {
9291 output.writeFieldBegin('ArgumentObjectArg6Name', Thrift.Type.STRING, 24);
9292 output.writeString(this.ArgumentObjectArg6Name);
9293 output.writeFieldEnd();
9294 }
9295 if (this.ArgumentObjectArg6StringValue !== null && this.ArgumentObjectArg6StringValue !== undefined) {
9296 output.writeFieldBegin('ArgumentObjectArg6StringValue', Thrift.Type.STRING, 25);
9297 output.writeString(this.ArgumentObjectArg6StringValue);
9298 output.writeFieldEnd();
9299 }
9300 if (this.ArgumentObjectArg6NumericValue !== null && this.ArgumentObjectArg6NumericValue !== undefined) {
9301 output.writeFieldBegin('ArgumentObjectArg6NumericValue', Thrift.Type.DOUBLE, 26);
9302 output.writeDouble(this.ArgumentObjectArg6NumericValue);
9303 output.writeFieldEnd();
9304 }
9305 if (this.ArgumentObjectArg7Name !== null && this.ArgumentObjectArg7Name !== undefined) {
9306 output.writeFieldBegin('ArgumentObjectArg7Name', Thrift.Type.STRING, 27);
9307 output.writeString(this.ArgumentObjectArg7Name);
9308 output.writeFieldEnd();
9309 }
9310 if (this.ArgumentObjectArg7StringValue !== null && this.ArgumentObjectArg7StringValue !== undefined) {
9311 output.writeFieldBegin('ArgumentObjectArg7StringValue', Thrift.Type.STRING, 28);
9312 output.writeString(this.ArgumentObjectArg7StringValue);
9313 output.writeFieldEnd();
9314 }
9315 if (this.ArgumentObjectArg7NumericValue !== null && this.ArgumentObjectArg7NumericValue !== undefined) {
9316 output.writeFieldBegin('ArgumentObjectArg7NumericValue', Thrift.Type.DOUBLE, 29);
9317 output.writeDouble(this.ArgumentObjectArg7NumericValue);
9318 output.writeFieldEnd();
9319 }
9320 if (this.ArgumentObjectArg8Name !== null && this.ArgumentObjectArg8Name !== undefined) {
9321 output.writeFieldBegin('ArgumentObjectArg8Name', Thrift.Type.STRING, 30);
9322 output.writeString(this.ArgumentObjectArg8Name);
9323 output.writeFieldEnd();
9324 }
9325 if (this.ArgumentObjectArg8StringValue !== null && this.ArgumentObjectArg8StringValue !== undefined) {
9326 output.writeFieldBegin('ArgumentObjectArg8StringValue', Thrift.Type.STRING, 31);
9327 output.writeString(this.ArgumentObjectArg8StringValue);
9328 output.writeFieldEnd();
9329 }
9330 if (this.ArgumentObjectArg8NumericValue !== null && this.ArgumentObjectArg8NumericValue !== undefined) {
9331 output.writeFieldBegin('ArgumentObjectArg8NumericValue', Thrift.Type.DOUBLE, 32);
9332 output.writeDouble(this.ArgumentObjectArg8NumericValue);
9333 output.writeFieldEnd();
9334 }
9335 if (this.ArgumentObjectArg9Name !== null && this.ArgumentObjectArg9Name !== undefined) {
9336 output.writeFieldBegin('ArgumentObjectArg9Name', Thrift.Type.STRING, 33);
9337 output.writeString(this.ArgumentObjectArg9Name);
9338 output.writeFieldEnd();
9339 }
9340 if (this.ArgumentObjectArg9StringValue !== null && this.ArgumentObjectArg9StringValue !== undefined) {
9341 output.writeFieldBegin('ArgumentObjectArg9StringValue', Thrift.Type.STRING, 34);
9342 output.writeString(this.ArgumentObjectArg9StringValue);
9343 output.writeFieldEnd();
9344 }
9345 if (this.ArgumentObjectArg9NumericValue !== null && this.ArgumentObjectArg9NumericValue !== undefined) {
9346 output.writeFieldBegin('ArgumentObjectArg9NumericValue', Thrift.Type.DOUBLE, 35);
9347 output.writeDouble(this.ArgumentObjectArg9NumericValue);
9348 output.writeFieldEnd();
9349 }
9350 output.writeFieldStop();
9351 output.writeStructEnd();
9352 return;
9353};
9354
9355
9356window.Alt.PositronHost = "account.altvr.com";
9357window.Alt.PositronProtocol = "https";
9358
9359window.engine.call("GetPositronHost").then(function(host) {
9360 Alt.PositronHost = host;
9361});
9362
9363window.engine.call("GetPositronProtocol").then(function(protocol) {
9364 Alt.PositronProtocol = protocol;
9365});
9366
9367window.Alt.Log = function(m) {
9368 console.log(m);
9369};
9370
9371// These overrides are required- these webkitAudioContext methods cause the main Unity
9372// thread to hang (with coherent in-client audio streaming enabled)
9373// Probably _all_ methods that return AudioNodes will do this, but these are the only
9374// ones currently in use.
9375window.webkitAudioContext.prototype.createMediaElementSource = function(myMediaElement) {
9376 console.error("createMediaElementSource is disabled in AltspaceVR.");
9377 return null;
9378}
9379window.webkitAudioContext.prototype.createAnalyser = function() {
9380 console.error("createAnalyser is disabled in AltspaceVR.");
9381 return null;
9382}
9383
9384// Override window.open. Used to prevent pages from creating a pop-up,
9385// which Altspace's browser can't handle currently.
9386window.nativeOpen = window.open;
9387window.nativeOpen.bind(window);
9388window.open = function(url, name, features, replace){
9389 return window.nativeOpen(url, '_self', features, replace);
9390};
9391
9392// Stub out alert, confirm, and prompt
9393window.alert = function(alert) { };
9394window.confirm = function(confirm) { return true; };
9395window.prompt = function(message, defaultValue) { return defaultValue; };
9396
9397if (!window.chrome) {
9398 window.chrome = {};
9399}
9400
9401// Protect console
9402Object.defineProperty(window, 'console', {value: window.console, configurable : false});
9403
9404// Called by YouTube API on YouTube.com.
9405window.onYouTubePlayerReady = function(player) {
9406 window.Alt.CapturedYouTubePlayer = player;
9407};
9408
9409if (typeof(_) != "undefined") {
9410 window.Alt._ = _.noConflict();
9411}
9412
9413if (typeof(Backbone) != "undefined") {
9414 window.Alt.Backbone = Backbone.noConflict();
9415}
9416
9417window.requestAnimationFrame = Alt._.throttle(requestAnimationFrame, 10);
9418
9419(function () {
9420 var iframeWhitelist = ['codepen.io', 's.codepen.io', 'localhost', 'rawgit.com', 'cdn.rawgit.com'];
9421
9422 window.Alt.shouldSupportIFrames = iframeWhitelist.indexOf(location.hostname) >= 0;
9423
9424 var inIFrame = self !== top;
9425
9426 if (window.Alt.shouldSupportIFrames && inIFrame) {
9427 //Since ExecuteScript only works on the topmost document, we 'inject' loaded.min.js manually if we are in an iframe
9428 window.addEventListener('DOMContentLoaded', function () {
9429 [
9430 'coui://uiresources/Altspace/loaded.min.js'
9431 ].forEach(function (src) {
9432 var script = document.createElement('script');
9433 script.src = src;
9434 script.async = false;
9435 document.head.appendChild(script);
9436 });
9437 });
9438 }
9439}());
9440
9441
9442
9443
9444
9445/// <reference path="../deps/EventDispatcher.js" />
9446//New SDK APIs
9447(function () {
9448 var altspace = window.altspace;
9449 var internal = altspace._internal;
9450 internal.couiEngine = window.engine;//TODO: Ideally this gets deleted from here or never is placed on window in the first place
9451
9452 //Wrapper around coherent's engine.call.
9453 //Eventually this could take authentication info, or utilize other channels like a local websocket.
9454 //Catch on Unity side via WebViewFacade.BindCall(name, ...)
9455 internal.callClientFunction = function (name, args, config) {
9456 var couiArgs = {};
9457
9458 if (args) {
9459 if (!config || !config.hasOwnProperty('argsType')) {
9460 console.warn('To use COUI engine.call with arguments, argsType must be defined in the config');
9461 return null;
9462 }
9463
9464 couiArgs.__Type = config.argsType;//This must be the first property on the object. COUI weirdness
9465 for (var k in args) if (args.hasOwnProperty(k)) couiArgs[k] = args[k];
9466 }
9467
9468 return internal.couiEngine.call(name, couiArgs);
9469 }
9470
9471 internal.onClientEvent = function (name, callback, context) {
9472 return internal.couiEngine.on(name, callback, context);
9473 }
9474
9475 function chainWhenFunctionExists(funcPath, args) {
9476 var spinPromise = engine.createDeferred();
9477 var interval;
9478 function spin() {
9479 var funcPromise = executeFunction(funcPath, args);
9480 if (funcPromise) {//This will not fire if the executedFunction does not return a promise
9481 clearInterval(interval);
9482 interval = null;
9483 funcPromise.then(function () {
9484 spinPromise.resolve.apply(spinPromise, arguments);
9485 }, function () {
9486 spinPromise.reject.apply(spinPromise, arguments);
9487 });
9488 }
9489 }
9490 interval = setInterval(spin, 10);
9491 setTimeout(spin, 0);//Fire immediately but don't unleash Zalgo
9492 return spinPromise;
9493 }
9494
9495 // iFrame Events //
9496
9497 var iframes = document.getElementsByTagName('iframe');//This is a live NodeList
9498
9499 function forwardEventToChildIFrames(eventName, eventArgs) {
9500 if (!internal.Alt.shouldSupportIFrames) return;
9501
9502 var event = { isAltspaceIFrameEvent: true, eventName: eventName, eventArgs: eventArgs };
9503
9504 for (var i = 0, max = iframes.length; i < max; i++) {
9505 var iframe = iframes[i];
9506 iframe.contentWindow.postMessage(event, '*');
9507 }
9508 }
9509
9510 window.addEventListener('message', function (event) {
9511
9512 if (!event.data.isAltspaceIFrameEvent) return;//Pretty bad. No origin checks. Maybe have it come from a proxy iframe or something?
9513
9514 var nameAndArgs = event.data.eventArgs;
9515 nameAndArgs.unshift(event.data.eventName);
9516
9517 //console.log('triggering event from parent: ');
9518 //console.dir(nameAndArgs);
9519
9520 window.altspace._internal.couiEngine.trigger.apply(window.altspace._internal.couiEngine, nameAndArgs);
9521 });
9522
9523 // Enclosure //
9524
9525 /**
9526 * Represents an app enclosure in AltspaceVR.
9527 * @typedef {Object} module:altspace~Enclosure
9528 * @property {Number} innerWidth The width of the enclosure in pixels.
9529 * @property {Number} innerHeight The height of the enclosure in pixels.
9530 * @property {Number} innerDepth The depth of the enclosure in pixels.
9531 * @property {Number} pixelsPerMeter The ratio of pixels to meters.
9532 */
9533 internal.enclosure = {//TODO: This should be top level when back / forward bug is fixed
9534 innerWidth: 0,
9535 innerHeight: 0,
9536 innerDepth: 0,
9537 pixelsPerMeter: 0
9538 };
9539 internal.onClientEvent("DimensionsChanged", function (args) {
9540 forwardEventToChildIFrames('DimensionsChanged', [args]);
9541 internal.enclosure.innerWidth = args.Width;
9542 internal.enclosure.innerHeight = args.Height;
9543 internal.enclosure.innerDepth = args.Depth;
9544 });
9545 internal.onClientEvent("PixelsPerMeterChanged", function (args) {
9546 forwardEventToChildIFrames('PixelsPerMeterChanged', [args]);
9547 internal.enclosure.pixelsPerMeter = args.PixelsPerMeter;
9548 });
9549
9550 /**
9551 * Gets the enclosure for the app. The resulting promise resolves to an
9552 * [Enclosure]{@link module:altspace~Enclosure}.
9553 * @method getEnclosure
9554 * @returns {Promise}
9555 * @memberof module:altspace
9556 */
9557 altspace.getEnclosure = function () {
9558 return internal.callClientFunction('GetEnclosure').then(function(args) {
9559 return {
9560 innerWidth: args.Width,
9561 innerHeight: args.Height,
9562 innerDepth: args.Depth,
9563 pixelsPerMeter: args.PixelsPerMeter
9564 }
9565 });
9566 }
9567
9568
9569 // User //
9570
9571 /**
9572 * Details of a user.
9573 * @typedef {Object} module:altspace~User
9574 * @property {String} userId Unique id for this user.
9575 * @property {String} displayName The user's chosen display name.
9576 */
9577
9578 /**
9579 * Gets the current user. The resulting promise resolves to a
9580 * [User]{@link module:altspace~User} object.
9581 * @method getUser
9582 * @returns {Promise}
9583 * @memberof module:altspace
9584 */
9585 altspace.getUser = function () {
9586 return chainWhenFunctionExists('altspace._internal.Alt.Users.getLocalUser');
9587 };
9588
9589 // Spaces //
9590
9591 /**
9592 * Details of a user.
9593 * @typedef {Object} module:altspace~Space
9594 * @property {String} sid Unique id for this space.
9595 * @property {String} name The space's display name.
9596 */
9597
9598 /**
9599 * Gets the space that the app is running in. The resulting promise resolves to a
9600 * [Space]{@link module:altspace~Space}
9601 * @method getSpace
9602 * @returns {Promise}
9603 * @memberof module:altspace
9604 */
9605 altspace.getSpace = function () {
9606 return internal.callClientFunction('GetSpace').then(function(args) {
9607 return {
9608 sid: args.SID,
9609 name: args.Name,
9610 }
9611 });
9612 }
9613
9614
9615 // Events //
9616
9617 EventDispatcher.prototype.apply(altspace);
9618
9619 // Touchpad //
9620 var shouldSendTouchpadUpdates = false;
9621
9622 function hasTouchpadListeners() {
9623 function hasListeners(type) {
9624 return altspace._listeners[type] && altspace._listeners[type].length;
9625 };
9626 return (
9627 hasListeners('touchpadup') || hasListeners('touchpaddown') ||
9628 hasListeners('touchpadmove') || hasListeners('touchpadgesture'));
9629 }
9630 function isTouchpadUpdateEvent(type) {
9631 return (
9632 type === 'touchpadup' || type === 'touchpaddown' ||
9633 type === 'touchpadmove' || type === 'touchpadgesture');
9634 }
9635 function onListenerAdded(event) {
9636 if (isTouchpadUpdateEvent(event.listenerType) && !shouldSendTouchpadUpdates) {
9637 internal.callClientFunction("EnableTouchpadUpdates");
9638 shouldSendTouchpadUpdates = true;
9639 }
9640 }
9641 function onListenerRemoved(event) {
9642 if (isTouchpadUpdateEvent(event.listenerType) && !hasTouchpadListeners()) {
9643 internal.callClientFunction("DisableTouchpadUpdates");
9644 shouldSendTouchpadUpdates = false;
9645 }
9646 }
9647 altspace.addEventListener('listeneradded', onListenerAdded);
9648 altspace.addEventListener('listenerremoved', onListenerRemoved);
9649
9650 var lastX;
9651 var lastY;
9652 internal.onClientEvent('TouchpadUpdated', function () {
9653 var args = arguments;
9654 forwardEventToChildIFrames('TouchpadUpdated', args);
9655
9656 var x = args[0];
9657 var y = args[1];
9658 var up = args[2];
9659 var down = args[3];
9660
9661 /**
9662 * The TouchpadEvent interface represents events that occur due to the user interacting with the Samsung GearVR Touchpad
9663 *
9664 * The best way to think about the units returned from the displacement properties is that they are the number of pixels that would be theoretically scrolled by swiping on the touchpad.
9665 * Due to built-in acceleration, this can range from approximately 300 to 700 pixels for a full swipe of the touchpad.
9666 * The coordinate system can also be thought of as the value you would add to the document position to scroll due to the swipe. (left is +x, up is +y)
9667 *
9668 * @typedef {Object} module:altspace~TouchpadEvent
9669 * @property {Number} displacementX - The horizontal distance that the user has dragged their finger since pressing it on the touchpad. Sliding the finger left on the touchpad increases this value
9670 * @property {Number} displacementY - The vertical distance that the user has dragged their finger since pressing it on the touchpad. Sliding the finger up on the touchpad increases this value
9671 */
9672
9673 /**
9674 * The touchpadup event is fired from the [altspace]{@link module:altspace} object when the user lifts their finger up from the touchpad.
9675 *
9676 * @event module:altspace#touchpadup
9677 * @type {module:altspace~TouchpadEvent}
9678 */
9679
9680 /**
9681 * The touchpaddown event is fired from the [altspace]{@link module:altspace} object when the user presses their finger down on the touchpad.
9682 * The displacement for this event will always be [0, 0]
9683 *
9684 * @event module:altspace#touchpaddown
9685 * @type {module:altspace~TouchpadEvent}
9686 */
9687
9688 /**
9689 * The touchpadmove event is fired from the [altspace]{@link module:altspace} object while the user slides their finger across the trackpad.
9690 *
9691 * @event module:altspace#touchpadmove
9692 * @type {module:altspace~TouchpadEvent}
9693 */
9694 if (up) {
9695 altspace.dispatchEvent({
9696 type: 'touchpadup',
9697 displacementX: x,
9698 displacementY: y
9699 });
9700 }
9701 if (down) {
9702 altspace.dispatchEvent({
9703 type: 'touchpaddown',
9704 displacementX: 0,
9705 displacementY: 0
9706 });
9707 }
9708 var displacementChanged = x !== lastX || y !== lastY;
9709 var hasDisplacement = !(x === 0 && y === 0);
9710 if (hasDisplacement && displacementChanged) {
9711 altspace.dispatchEvent({
9712 type: 'touchpadmove',
9713 displacementX: x,
9714 displacementY: y
9715 });
9716 }
9717
9718 lastX = x;
9719 lastY = y;
9720 });
9721
9722
9723 /**
9724 * Possible touchpad gestures
9725 * @enum {TouchpadGesture}
9726 */
9727 var TouchpadGesture = {
9728 0: 'tap',
9729 1: 'up',
9730 2: 'down',
9731 3: 'left',
9732 4: 'right'
9733 };
9734
9735 /**
9736 * The touchpadgesture event is fired from the [altspace]{@link module:altspace} object when the user lifts their finger off the touchpad. If it is within a minimum radius, a tap is triggered. Otherwise the primary direction of movement is used to generate a directional gesture.
9737 *
9738 * @event module:altspace#touchpadgesture
9739 * @property {TouchpadGesture} gesture - One of 'tap', 'up', 'down', 'left', 'right'
9740 */
9741 internal.onClientEvent('TouchpadGesture', function () {
9742 var args = arguments;
9743 forwardEventToChildIFrames('TouchpadGesture', args);
9744
9745 altspace.dispatchEvent({
9746 type: 'touchpadgesture',
9747 gesture: TouchpadGesture[args[0]]
9748 });
9749 });
9750
9751 //Three.js
9752
9753 (function() {
9754 var currentScene;
9755 var renderer;
9756
9757 var dispatchEvent = function (event) {
9758
9759 var shouldStopPropagation;
9760 var shouldStopPropagationImmediately;
9761
9762 if (event.bubbles) {
9763
9764 event.currentTarget = this;
9765
9766 event.stopPropagation = function () {
9767 shouldStopPropagation = true;
9768 }
9769
9770 event.stopImmediatePropagation = function () {
9771 shouldStopPropagationImmediately = true;
9772 }
9773 }
9774
9775 if (!event.target)
9776 event.target = this;
9777
9778 if (this._listeners) {
9779
9780 var listeners = this._listeners;
9781 var listenerArray = listeners[event.type];
9782
9783 if (listenerArray) {
9784
9785 var array = [];
9786 var length = listenerArray.length;
9787
9788 for (var i = 0; i < length; i++) {
9789
9790 array[i] = listenerArray[i];
9791
9792 }
9793
9794 for (var i = 0; i < length; i++) {
9795
9796 array[i].call(this, event);
9797
9798 if (shouldStopPropagationImmediately) return;
9799
9800 }
9801
9802 }
9803
9804 }
9805
9806
9807 if (event.bubbles && this.parent && this.parent.dispatchEvent && !shouldStopPropagation) {
9808
9809 dispatchEvent.call(this.parent, event);
9810
9811 }
9812
9813 }
9814
9815 /**
9816 * Gets the renderer instance for this app.
9817 * @method getThreeJSRenderer
9818 * @returns {AltRenderer}
9819 * @memberof module:altspace
9820 */
9821 altspace.getThreeJSRenderer = function (options)
9822 {
9823 options = options || {};
9824 if (!window.THREE) {
9825 console.warn('The AltspaceVR three.js renderer cannot be used without a valid version of three.js loaded to window.THREE');
9826 return null;
9827 }
9828 if (parseInt(window.THREE.REVISION) < 69) {
9829 console.warn('The AltspaceVR three.js renderer cannot be used with a revision of three.js less than 69');
9830 return null;
9831 }
9832 if (renderer) return renderer;
9833
9834 renderer = new altspace._internal.AltRenderer(options);
9835
9836 internal.callClientFunction("ThreeJSApiUsed");
9837 return renderer;
9838 }
9839
9840 function filterInternalInfo (debugInfoObj) {
9841 for (var key in debugInfoObj) {
9842 if (debugInfoObj.hasOwnProperty(key)) {
9843 if (key[0] === '_') {
9844 delete debugInfoObj[key];
9845 }
9846 if (typeof debugInfoObj[key] === 'object') {
9847 filterInternalInfo(debugInfoObj[key]);
9848 }
9849 }
9850 }
9851 }
9852
9853 /**
9854 * Debug information about an object in an app.
9855 * @typedef {Object} module:altspace~ThreeJSDebugInfo
9856 * @property {String} uuid The Three.js UUID for this object.
9857 * @property {Number} vertexCount Number of vertices in this object's
9858 * geometry.
9859 * @property {Boolean} isVisible If this object is visible in the scene
9860 * @property {Boolean} isMaterialVisible If this object's material is
9861 * visible.
9862 * @property {Boolean} isCulled If this object has been culled due to it
9863 * moving out of the app enclosure bounds.
9864 * @property {Object} position The object's position vector.
9865 * @property {Object} quaternion The object's orientation quarternion.
9866 */
9867
9868 /**
9869 * Retrieves debug information about 3D objects in an app.
9870 * The resulting promise resolves to an array of
9871 * [ThreeJSDebugInfo]{@link module:altspace~ThreeJSDebugInfo} objects.
9872 * @method getThreeJSDebugInfo
9873 * @returns {Promise}
9874 * @memberof module:altspace
9875 */
9876 altspace.getThreeJSDebugInfo = function () {
9877 return internal.callClientFunction('GetThreeJSDebugInfo').then(
9878 function(debugInfo) {
9879 debugInfo.forEach(filterInternalInfo);
9880 return debugInfo;
9881 }
9882 );
9883 };
9884
9885 internal.setThreeJSScene = function (scene) {
9886 currentScene = scene;
9887 }
9888
9889 function getObjectByProperty(name, value) {
9890
9891 if (this[name] === value) return this;
9892
9893 for (var i = 0, l = this.children.length; i < l; i++) {
9894
9895 var child = this.children[i];
9896 var object = getObjectByProperty.call(child, name, value);
9897
9898 if (object !== undefined) {
9899
9900 return object;
9901
9902 }
9903
9904 }
9905
9906 return undefined;
9907
9908 }
9909
9910 var cachedTargets = {};
9911 //TODO: optimize cursor events by ensuring that event listeners exist before turning on the firehose
9912
9913 /**
9914 * The ThreeJSCursorEvent interface represents events that occur due to the user interacting with three.js objects using the cursor
9915 *
9916 *
9917 * @typedef {Object} THREE.Object3D#ThreeJSCursorEvent
9918 * @property {THREE.Ray} ray - The ray that was used to project the cursor. Will often come from either the user's center eye or a motion controller they are holding.
9919 * @property {THREE.Vector3} point - The point in world space where the ray intersected an object.
9920 * @property {Boolean} bubbles - Whether this event will bubble up the three.js hierarchy. True for all ThreeJSCursorEvents. Roughly matches DOM bubbling (does not have a capture step).
9921 * @property {THREE.Object3D} target - The [THREE.Object3D]{@link THREE.Object3D} the event originally fired on.
9922 * @property {THREE.Object3D} currentTarget - The [THREE.Object3D]{@link THREE.Object3D} the event is currently firing on as it bubbles.
9923 * @property {Function} stopPropagation - Allows the remaining event listeners for this event on this [THREE.Object3D]{@link THREE.Object3D} to fire and then stops.
9924 * @property {Function} stopImmediatePropagation - Stops the firing of any more event listeners for this event.
9925 */
9926
9927 /**
9928 * The cursorenter event is fired from an [THREE.Object3D]{@link THREE.Object3D} when the user's cursor
9929 * moves over the object.
9930 *
9931 * @event THREE.Object3D.cursorenter
9932 * @type {THREE.Object3D#ThreeJSCursorEvent}
9933 * @static
9934 */
9935
9936 /**
9937 * The cursorleave event is fired from an [THREE.Object3D]{@link THREE.Object3D} when the user's cursor
9938 * moves off the object.
9939 *
9940 * @event THREE.Object3D.cursorleave
9941 * @type {THREE.Object3D#ThreeJSCursorEvent}
9942 * @static
9943 */
9944
9945 /**
9946 * The cursorup event is fired from an [THREE.Object3D]{@link THREE.Object3D} when the user's primary cursor button is lifted up over an object
9947 *
9948 * @event THREE.Object3D.cursorup
9949 * @type {THREE.Object3D#ThreeJSCursorEvent}
9950 * @static
9951 */
9952
9953 /**
9954 * The cursordown event is fired from an [THREE.Object3D]{@link THREE.Object3D} when the user's primary cursor button is pressed down over an object
9955 *
9956 * @event THREE.Object3D.cursordown
9957 * @type {THREE.Object3D#ThreeJSCursorEvent}
9958 * @static
9959 */
9960
9961 /**
9962 * The cursormove event is fired from a [THREE.Scene]{@link THREE.Scene} when the user's cursor moves over or near an object
9963 *
9964 * @event THREE.Scene#cursormove
9965 * @type {THREE.Object3D#ThreeJSCursorEvent}
9966 */
9967 internal.onClientEvent('ThreeJSCursorEvent', function() {
9968 var args = Array.prototype.slice.call(arguments);
9969 forwardEventToChildIFrames('ThreeJSCursorEvent', args);
9970
9971 if (!currentScene) return;
9972 if (!window.THREE) return;
9973
9974 var eventType = args[0];
9975 var targetMeshId = args[1];
9976 var hasTargetMesh = args[2];
9977 var cursorHitPosition = new THREE.Vector3(args[3], args[4], args[5]);//TODO reuse
9978 var ray = new THREE.Ray(new THREE.Vector3(args[6], args[7], args[8]),
9979 new THREE.Vector3(args[9], args[10], args[11]));
9980
9981 var target = currentScene;
9982
9983 if (hasTargetMesh) {
9984 target = cachedTargets[targetMeshId];
9985
9986 if (!target) {
9987 var findTarget = currentScene.getObjectByProperty || getObjectByProperty;
9988 target = findTarget.call(currentScene, 'id', targetMeshId);
9989 cachedTargets[targetMeshId] = target;
9990 }
9991 if (!target) {
9992 console.warn("ThreeJS cursor event fired for non-existant Object3D");
9993 return;
9994 }
9995 }
9996
9997 var event = { type: eventType, ray: ray, point: cursorHitPosition, bubbles: true }
9998
9999 dispatchEvent.call(target, event);
10000 });
10001
10002 // Gamepad //
10003
10004 var gamepads = [];
10005 var requestedGamepads = false;
10006
10007 /**
10008 * Get a list of currently connected gamepads. Currently this requires polling this function until it returns a non-empty array. Connected gamepads are represented as
10009 * [Gamepad]{@link module:altspace~Gamepad}
10010 * objects. This should work with a range of gamepads, but has only been tested with an Xbox One and HTC Vive controllers on Windows.
10011 * @method getGamepads
10012 * @returns {Array}
10013 * @memberof module:altspace
10014 */
10015 altspace.getGamepads = function() {
10016 if (!requestedGamepads) {
10017 internal.callClientFunction('StartUpdatingGamepad');
10018 requestedGamepads = true;
10019 }
10020 return gamepads;
10021 };
10022
10023 var GamepadButton = function() {
10024 this.pressed = false;
10025 this.value = 0;
10026 }
10027
10028 /**
10029 * Represents a gamepad. Can be retrived via [altspace.getGamepads]{@link module:altspace.getGamepads}. See the official [Gamepad]{@link https://developer.mozilla.org/en-US/docs/Web/API/Gamepad} spec for more details.
10030 *
10031 * See {@link https://github.com/AltspaceVR/AltspaceSDK/examples/steamvr} for a usage example
10032 *
10033 * ### SteamVR Gamepad Mappings
10034 * #### Buttons
10035 * | Index | Button |
10036 * |-------|-----------------|
10037 * | 0 | Trigger (analog)|
10038 * | 1 | Grip |
10039 * | 2 | Touchpad |
10040 * | 4 | Touchpad Up |
10041 * | 5 | Touchpad Right |
10042 * | 6 | Touchpad Down |
10043 * | 7 | Touchpad Left |
10044 *
10045 * #### Axes
10046 * | Index | Axis |
10047 * |-------|------------|
10048 * | 0 | Touchpad X |
10049 * | 1 | Touchpad Y |
10050 *
10051
10052 * @property {string} mapping - Controller mapping. In addtion to the "standard" mapping in the HTML5 Gamepad spec, steamvr input devices are exposed with a "steamvr" mapping.
10053 *
10054 * @property {string} hand - "left" for the controller in the users left hand, "right for the right hand. If only one controller is connected, only a "right" controller will be returned..
10055 *
10056 * @property {object} position - The position in enclosure space of a SteamVR input device (only available on gamepads with mapping == 'steamvr')
10057 * @property {number} position.x - x coordinate
10058 * @property {number} position.y - y coordinate
10059 * @property {number} position.z - z coordinate
10060 *
10061 * @property {object} rotation - The orientation quaternion in enclosure space of a SteamVR input device (only available on gamepads with mapping == 'steamvr').
10062 * @property {number} rotation.x - x component
10063 * @property {number} rotation.y - y component
10064 * @property {number} rotation.z - z component
10065 * @property {number} rotation.w - w component
10066 *
10067 * @class module:altspace~Gamepad
10068 * @memberof module:altspace
10069 */
10070 var Gamepad = function(mapping) {
10071 var numButtons = 0;
10072 var numAxes = 0;
10073
10074 if (mapping === 'standard') {
10075 numButtons = 16;
10076 numAxes = 4;
10077 } else if (mapping === 'steamvr') {
10078 numButtons = 7;
10079 numAxes = 2;
10080 this.position = { x: 0, y: 0, z: 0 };
10081 this.rotation = { x: 0, y: 0, z: 0, w: 0 };
10082 }
10083
10084 this.mapping = mapping; // 0
10085 this.id = 0; // 1
10086 this.index = 0; // 2
10087 this.timestamp = 0; // 3
10088 this.connected = false; // 4
10089
10090 this.axes = [];
10091 this.buttons = [];
10092
10093 var i;
10094 for (i = 0; i < numAxes; i++) {
10095 this.axes[i] = 0;
10096 }
10097
10098 for (i = 0; i < numButtons; i++) {
10099 this.buttons[i] = new GamepadButton();
10100 }
10101 };
10102 /**
10103 * Prevents default actions on specific axes and buttons.
10104 * @instance
10105 * @method preventDefault
10106 * @param {Array} axes An array of booleans, arranged according to the axis order of the layout. A true value for a given location will block the default action for that axis.
10107 * @param {Array} buttons An array of booleans, arranged according to the button order of the layout. A true value for a given location will block the default action for that button.
10108 * @memberof module:altspace~Gamepad
10109 */
10110 Gamepad.prototype.preventDefault = function(axes, buttons) {
10111 //Convert bool array to string "mask" of zeros and ones,
10112 //since passing arrays or lists through coui isn't working.
10113 var a = '';
10114 var b = '';
10115 for (var i=0; i < axes.length; i++) a += axes[i] ? '1' : '0';
10116 for (var i=0; i < buttons.length; i++) b += buttons[i] ? '1' : '0';
10117 internal.callClientFunction('BlockGamepad', {
10118 Index: this.index,
10119 Axes: a,
10120 Buttons: b
10121 }, { argsType: 'BlockGamepadType' });
10122 }
10123
10124 navigator.getGamepads = altspace.getGamepads;
10125 if (navigator.webkitGetGamepads) navigator.webkitGetGamepads = altspace.getGamepads;
10126
10127 internal.onClientEvent('GamepadUpdated', function () {
10128 var args = Array.prototype.slice.call(arguments); //do we need to do this?
10129 forwardEventToChildIFrames('GamepadUpdated', args);
10130
10131 var o = 0;
10132
10133 var mapping = args[o++];
10134 var id = args[o++];
10135 var index = args[o++];
10136 var timestamp = args[o++];
10137 var connected = args[o++];
10138
10139
10140 if (!gamepads[index]) {
10141 gamepads[index] = new Gamepad(mapping);
10142 }
10143
10144 var gamepad = gamepads[index];
10145 gamepad.id = id;
10146 gamepad.index = index;
10147 gamepad.timestamp = timestamp;
10148 gamepad.connected = connected;
10149
10150 var i;
10151 var numAxes = gamepad.axes.length;
10152 var numButtons = gamepad.buttons.length;
10153 for (i = 0; i < numAxes; i++) {
10154 gamepad.axes[i] = args[o++];
10155 }
10156 for (i = 0; i < numButtons; i++) {
10157 gamepad.buttons[i].pressed = args[o++];
10158 }
10159 for (i = 0; i < numButtons; i++) {
10160 gamepad.buttons[i].value = args[o++];
10161 }
10162
10163 if (gamepad.mapping === 'steamvr') {
10164 gamepad.hand = args[o++];
10165
10166 gamepad.position.x = args[o++];
10167 gamepad.position.y = args[o++];
10168 gamepad.position.z = args[o++];
10169
10170 gamepad.rotation.x = args[o++];
10171 gamepad.rotation.y = args[o++];
10172 gamepad.rotation.z = args[o++];
10173 gamepad.rotation.w = args[o++];
10174 }
10175 });
10176
10177 // Tracking Skeleton //
10178
10179 (function () {
10180 var TrackingSkeleton;
10181 var TrackingJoint;
10182
10183 var trackingSkeleton;
10184 var getPromise;//If you call get multiple times we might lose the promise
10185
10186 var firstUpdate = true;
10187 function init(trackingSkeletonFrame) {
10188 firstUpdate = false;
10189 trackingSkeleton = new TrackingSkeleton(trackingSkeletonFrame);
10190 getPromise.resolve(trackingSkeleton);
10191 }
10192
10193 internal.onClientEvent("UpdateTrackingSkeleton", function() {
10194 var args = Array.prototype.slice.call(arguments);
10195
10196 forwardEventToChildIFrames('UpdateTrackingSkeleton', args);
10197 if (!getPromise) return;//Don't automatically create or update a skeleton if we are just passing the event to a lower iframe
10198
10199 var trackingSkeletonFrame = args;
10200 if (firstUpdate) {
10201 init(trackingSkeletonFrame);
10202 return;
10203 }
10204 trackingSkeleton.updateFromFrame(trackingSkeletonFrame);
10205 });
10206
10207 function defineClasses() {
10208 /**
10209 * Represents a joint on a user's skeleton. TrackingJoint should
10210 * not be instantiated directly, instead it should be retrieved
10211 * via [TrackingSkeleton.getJoint]{@link module:altspace~TrackingSkeleton#getJoint}.
10212 * @class module:altspace~TrackingJoint
10213 * @memberof module:altspace
10214 * @extends {THREE.Object3D}
10215 */
10216 TrackingJoint = function (skeletonFrame, offset) {
10217
10218 THREE.Object3D.call(this);
10219
10220 this.type = "TrackingJoint";
10221
10222 /**
10223 * A number from 0 to 3 indicating the confidence of the
10224 * tracking
10225 * @instance
10226 * @member {Number} confidence
10227 * @memberof module:altspace~TrackingJoint
10228 */
10229 this.confidence = skeletonFrame[offset + 1];//TODO: nice string
10230
10231 /**
10232 * The name of the joint comprised of its side, body part,
10233 * and index. E.g. 'LeftPinky0'.
10234 * @instance
10235 * @member {String} name
10236 * @memberof module:altspace~TrackingJoint
10237 */
10238 this.name = this.location = skeletonFrame[offset];//TODO: three part break;
10239 };
10240 TrackingJoint.prototype = Object.create(THREE.Object3D.prototype);
10241 TrackingJoint.prototype.constructor = TrackingJoint;
10242 TrackingJoint.prototype.updateFromFrame = function (skeletonFrame, offset) {
10243 this.position.set(skeletonFrame[offset + 2], skeletonFrame[offset + 3], skeletonFrame[offset + 4]);
10244 var quaternion = new THREE.Quaternion(skeletonFrame[offset + 5], skeletonFrame[offset + 6], skeletonFrame[offset + 7], skeletonFrame[offset + 8]);
10245 this.rotation.setFromQuaternion(quaternion);
10246 }
10247
10248
10249 /**
10250 * Represents a user's body. TrackingSkeleton should not
10251 * be instantiated directly, instead it should be retrieved via
10252 * [altspace.getThreeJSTrackingSkeleton]{@link module:altspace.getThreeJSTrackingSkeleton}.
10253 * @class module:altspace~TrackingSkeleton
10254 * @memberof module:altspace
10255 * @extends {THREE.Object3D}
10256 */
10257 TrackingSkeleton = function (initialFrame) {
10258
10259 THREE.Object3D.call(this);
10260
10261 this.type = "TrackingSkeleton";
10262
10263 /**
10264 * A dictionary of tracking joints by joint name.
10265 * @instance
10266 * @member {Object<String, module:altspace~TrackingJoint>} trackingJoints
10267 * @memberof module:altspace~TrackingSkeleton
10268 */
10269 this.trackingJoints = {};
10270 this.updateFromFrame(initialFrame);
10271 };
10272 TrackingSkeleton.prototype = Object.create(THREE.Object3D.prototype);
10273 TrackingSkeleton.prototype.constructor = TrackingSkeleton;
10274 TrackingSkeleton.prototype.updateFromFrame = function (skeletonFrame) {
10275 // Frame is array of location, confidence, p.x, p.y, p.z, r.x, r.y, r.z, r.w
10276 for (var offset = 0, max = skeletonFrame.length; offset < max; offset += 9) {
10277 var jointLocation = skeletonFrame[offset];
10278 var trackingJoint = this.trackingJoints[jointLocation];
10279
10280 if (!trackingJoint) {
10281 trackingJoint = this.trackingJoints[jointLocation] = new TrackingJoint(skeletonFrame, offset);
10282 this.add(trackingJoint);
10283 }
10284
10285 trackingJoint.updateFromFrame(skeletonFrame, offset);
10286 }
10287 }
10288 /**
10289 * Gets a joint on the skeleton.
10290 * @instance
10291 * @method getJoint
10292 * @param {String} bodyPart One of 'Eye, 'Head', 'Neck',
10293 * 'Spine', 'Hips', 'UpperLeg', 'LowerLeg', 'Foot', 'Toes',
10294 * 'Shoulder', 'UpperArm', 'LowerArm', 'Hand', 'Thumb',
10295 * 'Index', 'Middle', 'Ring' or 'Pinky'.
10296 * @param {String} [side='Center'] One of 'Left', 'Center' or
10297 * 'Right'.
10298 * @param {Number} [subIndex=0] The index of a specific part of
10299 * the join.
10300 * @return {module:altspace~TrackingJoint}
10301 * @memberof module:altspace~TrackingSkeleton
10302 */
10303 TrackingSkeleton.prototype.getJoint = function (bodyPart, side, subIndex) {
10304 side = side || "Center";
10305 subIndex = subIndex === undefined ? 0 : subIndex;
10306 //They are stored and accessed in pascal case, but this seems fine given the analogy to TypeScript enums.
10307 return this.trackingJoints[side + bodyPart + subIndex];//Might be a faster way to do this.
10308 }
10309 }
10310
10311 /**
10312 * Get the tracking skeleton representing the body of the current
10313 * user. The resulting promise resolves to a
10314 * [TrackingSkeleton]{@link module:altspace~TrackingSkeleton}
10315 * object.
10316 * @method getThreeJSTrackingSkeleton
10317 * @returns {Promise}
10318 * @memberof module:altspace
10319 */
10320 altspace.getThreeJSTrackingSkeleton = function () {
10321 getPromise = engine.createDeferred();
10322
10323 if (trackingSkeleton) {//Return the same skeleton on subsequent calls
10324 setTimeout(function () {
10325 getPromise.resolve(trackingSkeleton);
10326 }, 0);
10327 return getPromise;
10328 }
10329
10330 defineClasses();
10331
10332 internal.callClientFunction("GetTrackingSkeleton");
10333 return getPromise;
10334 };
10335
10336 }());
10337
10338 // Native Objects //
10339
10340 (function () {
10341 var NativeObject;
10342 function defineClasses() {
10343 /**
10344 * @ignore until publicly announced
10345 * @class module:altspace~NativeObject
10346 * @memberof module:altspace
10347 * @extends {THREE.Object3D}
10348 */
10349 NativeObject = function (name) {
10350
10351 var geometry = new THREE.BoxGeometry(0.001, 0.001, 0.001);
10352 var material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
10353 THREE.Mesh.call(this, geometry, material);
10354
10355 this.type = "NativeObject";
10356
10357 this.name = name;
10358 };
10359 NativeObject.prototype = Object.create(THREE.Mesh.prototype);
10360 NativeObject.prototype.constructor = NativeObject;
10361 }
10362
10363 altspace.instantiateNativeObject = function (path) {
10364 if (!NativeObject) defineClasses();
10365 //if we need to generate a custom subclass, we can add an extra metadata call here before creating the NativeObject
10366 var nativeObject = new NativeObject(name);
10367 return internal.callClientFunction('InstantiateNativeObject', { Path: path, MeshId: nativeObject.id }, { argsType: 'JSTypeInstantiateNativeObject' }).then(function () {
10368 return nativeObject;
10369 });
10370 }
10371 })();
10372
10373 })();
10374
10375
10376 //Execute Function
10377
10378 function executeFunction(func, args) {
10379 var target = null;
10380 var f = window;
10381
10382 var splitFunc = func.split(".");
10383 for (var i = 0, max = splitFunc.length; i < max; i++) {
10384 var name = splitFunc[i];
10385 target = f;
10386 f = f[name];
10387 if (!f) {
10388 break;
10389 }
10390 }
10391
10392 if (target && f) {
10393 return f.call(target, args);
10394 } else {
10395 return false;
10396 }
10397 };
10398 //engine.on("ExecuteFunction", executeFunction, this);
10399
10400 /**
10401 * True if the app is running inside AltspaceVR.
10402 * @member {Boolean} inClient
10403 * @memberof module:altspace
10404 */
10405 Object.defineProperty(altspace, 'inClient', {
10406 configurable: false,
10407 enumerable: true,
10408 value: true,
10409 writable: false
10410 });
10411
10412 Object.defineProperty(altspace, 'utilities', {
10413 configurable: false,
10414 enumerable: true,
10415 value: {},
10416 writable: false
10417 });
10418
10419 Object.freeze(window.altspace);//Warning, this is only a shallow freeze. You should freeze any other functions or properties that should not be messed with.
10420 //Object.freeze(window.altspace._internal);
10421 })();
10422
10423altspace._internal.AltThriftHelper = (function () {
10424 var thriftString = Thrift.Type.STRING;
10425 var thriftInt = Thrift.Type.I32;
10426 var thriftMap = Thrift.Type.MAP;
10427 var thriftList = Thrift.Type.LIST;
10428 var thriftSet = Thrift.Type.SET;
10429 var thriftStruct = Thrift.Type.STRUCT;
10430 var thriftBool = Thrift.Type.BOOL;
10431 var thriftDouble = Thrift.Type.DOUBLE;
10432
10433 var constr = function (buf) {
10434 this.buf = buf;
10435 this.pos = 0;
10436 }
10437
10438 constr.prototype.writeFieldHeader = function (type, fieldId) {
10439 this.buf.setInt8(this.pos, type);
10440 this.buf.setInt16(this.pos + 1, fieldId);
10441 this.pos += 1 + 2;
10442 };
10443
10444 constr.prototype.writeIntField = function(val, fieldId) {
10445 this.writeFieldHeader(thriftInt, fieldId);
10446 this.buf.setInt32(this.pos, val);
10447 this.pos += 4;
10448 };
10449
10450 constr.prototype.writeStructFieldHeader = function(fieldId) {
10451 this.writeFieldHeader(thriftStruct, fieldId);
10452 };
10453
10454 constr.prototype.writeInt = function(val) {
10455 this.buf.setInt32(this.pos, val);
10456 this.pos += 4;
10457 };
10458
10459 constr.prototype.writeDoubleField = function(val, fieldId) {
10460 if (isNaN(val)) { throw new Error('Value cannot be NaN.'); }
10461 this.writeFieldHeader(thriftDouble, fieldId);
10462 this.buf.setFloat64(this.pos, val);
10463 this.pos += 8;
10464 };
10465
10466 constr.prototype.writeBoolField = function(val, fieldId) {
10467 this.writeFieldHeader(thriftBool, fieldId);
10468 this.buf.setInt8(this.pos, val ? 1 : 0);
10469 this.pos += 1;
10470 };
10471
10472 constr.prototype.writeStringBufferField = function (strBuffer, len, fieldId) {
10473 this.writeFieldHeader(thriftString, fieldId);
10474 this.buf.setInt32(this.pos, len);
10475 this.buf.setBuffer(this.pos + 4, strBuffer);
10476 this.pos += 4 + len;
10477 };
10478
10479 constr.prototype.writeStringField = function(val, fieldId) {
10480 this.writeFieldHeader(thriftString, fieldId);
10481 this.writeString(val);
10482 };
10483
10484 constr.prototype.writeString = function(val) {
10485 var len = this.buf.setUtf8String(this.pos + 4, val);
10486 this.buf.setInt32(this.pos, len);
10487 this.pos += 4 + len;
10488 };
10489
10490 constr.prototype.writeStop = function() {
10491 this.buf.setInt8(this.pos, Thrift.Type.STOP);
10492 this.pos += 1;
10493 };
10494
10495 constr.prototype.writeMapFieldAndGetCountPos = function(keyType, valueType, fieldId) {
10496 this.writeFieldHeader(thriftMap, fieldId);
10497 this.buf.setInt8(this.pos, keyType);
10498 this.buf.setInt8(this.pos + 1, valueType);
10499
10500 var countPos = this.pos + 2;
10501 this.pos += 1 + 1 + 4;
10502
10503 return countPos;
10504 };
10505
10506 constr.prototype.writeListFieldAndGetCountPos = function(valueType, fieldId) {
10507 this.writeFieldHeader(thriftList, fieldId);
10508 this.buf.setInt8(this.pos, valueType);
10509
10510 var countPos = this.pos + 1;
10511 this.pos += 1 + 4;
10512
10513 return countPos;
10514 };
10515
10516 constr.prototype.writeObjectCount = function(countPos, objCount) {
10517 this.buf.setInt32(countPos, objCount);
10518 };
10519
10520 constr.prototype.writeObjectCountAndStop = function(countPos, objCount) {
10521 this.writeObjectCount(countPos, objCount);
10522 this.writeStop();
10523 };
10524
10525 constr.prototype.getArray = function() {
10526 return this.buf.getArray().subarray(0, this.pos)
10527 }
10528
10529 constr.prototype.getBinaryString = function () {
10530 var arr = this.getArray();
10531 return altspace._internal.DynamicThriftBuffer.toBinaryString(arr, arr.length);
10532 };
10533
10534 return constr;
10535}());
10536
10537/*
10538 * AltSceneUpdateSerializer serializes scene object updates into a Thrift message.
10539 *
10540 * Copyright (c) 2015 AltspaceVR
10541 */
10542
10543altspace._internal.AltSceneUpdateSerializer = function (filter) {
10544 var buf = new Buffer(1024 * 1024); // Allocate a meg of RAM for updates
10545 var bindingName = new Buffer(255);
10546 var bindingNameLen = bindingName.setUtf8String(0, "UpdateThreeJSScene");
10547 var thriftHelper = new altspace._internal.AltThriftHelper(buf);
10548 var lastSceneObjectIds;
10549 var lastSceneTransforms = {};
10550 var lastSceneVisibilities = {};
10551 var serializeCount = 0;
10552
10553 var worldPosition = new THREE.Vector3();
10554 var worldRotation = new THREE.Quaternion();
10555 var worldScale = new THREE.Vector3();
10556
10557 var walk = function(obj, f) {
10558 if (filter(obj)) {
10559 f(obj);
10560 }
10561
10562 var children = obj.children;
10563
10564 for(var i = 0, max = children.length; i < max; i++) {
10565 walk(children[i], f);
10566 }
10567 };
10568
10569 var matrixEquals = function(x, y) {
10570 // This is now in THREE.js on Matrix4, but is relatively
10571 // recent addition
10572 var xElements = x.elements;
10573 var yElements = y.elements;
10574
10575 for (var i = 0; i < 16; i++) {
10576 if (xElements[i] !== yElements[i]) return false;
10577 }
10578
10579 return true;
10580 };
10581
10582 this.serializeScene = function (scene) {
10583 var updateCount = 0;
10584 var newSceneObjectIds = {};
10585 var removeCountPos = -1;
10586 var removeCount = 0;
10587
10588 thriftHelper.pos = 0;
10589
10590 thriftHelper.writeStringBufferField(bindingName, bindingNameLen, 1); // BindingName
10591
10592 thriftHelper.writeIntField(0, 2); // RequestID
10593
10594 thriftHelper.writeStructFieldHeader(3); // ThreeJSUpdate
10595
10596 var updateCountPos = thriftHelper.writeListFieldAndGetCountPos(Thrift.Type.STRUCT, 1); // SceneObjectUpdates
10597
10598 walk(scene, function(object3d) {
10599 var meshId = object3d.id;
10600
10601 var isDirtyTransform = true;
10602 var isDirtyVisibility = true;
10603
10604 var lastTransform = lastSceneTransforms[meshId];
10605 var newTransform = object3d.matrixWorld;
10606
10607 var hasLastVisibility = lastSceneVisibilities.hasOwnProperty(meshId);
10608 var newVisibility = object3d.visible;
10609
10610 if (lastTransform) {
10611 isDirtyTransform = !matrixEquals(lastTransform, newTransform);
10612 }
10613
10614 if (isDirtyTransform || !lastTransform) {
10615 lastSceneTransforms[meshId] = newTransform.clone();
10616 }
10617
10618 if (hasLastVisibility) {
10619 isDirtyVisibility = lastSceneVisibilities[meshId] != newVisibility;
10620 }
10621
10622 if (isDirtyVisibility || !hasLastVisibility) {
10623 lastSceneVisibilities[meshId] = newVisibility;
10624 }
10625
10626 newSceneObjectIds[meshId] = true;
10627
10628 if (!isDirtyTransform && !isDirtyVisibility) return;
10629
10630 object3d.matrixWorld.decompose( worldPosition, worldRotation, worldScale );
10631
10632 try {
10633 thriftHelper.writeIntField(meshId, 1);
10634 thriftHelper.writeDoubleField(worldPosition.x, 2);
10635 thriftHelper.writeDoubleField(worldPosition.y, 3);
10636 thriftHelper.writeDoubleField(worldPosition.z, 4);
10637 thriftHelper.writeDoubleField(worldRotation.x, 5);
10638 thriftHelper.writeDoubleField(worldRotation.y, 6);
10639 thriftHelper.writeDoubleField(worldRotation.z, 7);
10640 thriftHelper.writeDoubleField(worldRotation.w, 8);
10641 thriftHelper.writeDoubleField(worldScale.x, 9);
10642 thriftHelper.writeDoubleField(worldScale.y, 10);
10643 thriftHelper.writeDoubleField(worldScale.z, 11);
10644 thriftHelper.writeBoolField(newVisibility, 12);
10645 thriftHelper.writeStop();
10646 }
10647 catch (e) {
10648 throw new Error('AltspaceVR: Could not serialize update for Mesh ' + object3d.uuid + '. ' + e.message);
10649 }
10650 updateCount++;
10651 });
10652
10653 thriftHelper.writeObjectCount(updateCountPos, updateCount);
10654
10655 if (lastSceneObjectIds) {
10656 for (var objId in lastSceneObjectIds) {
10657 if (lastSceneObjectIds.hasOwnProperty(objId)) {
10658 if (!newSceneObjectIds[objId]) {
10659 if (removeCount === 0) {
10660 // SceneObjectsToRemove
10661 removeCountPos = thriftHelper.writeListFieldAndGetCountPos(Thrift.Type.I32, 2);
10662 }
10663
10664 thriftHelper.writeInt(objId);
10665 removeCount++;
10666
10667 delete lastSceneTransforms[objId];
10668 }
10669 }
10670 }
10671 }
10672
10673 if (removeCount > 0) {
10674 thriftHelper.writeObjectCount(removeCountPos, removeCount);
10675 }
10676
10677 thriftHelper.writeIntField(serializeCount, 3); // Index, ordering updates
10678
10679 thriftHelper.writeStop(); // /ThreeJsUpdate
10680 thriftHelper.writeStop(); // /BindCallMessage
10681
10682 lastSceneObjectIds = newSceneObjectIds;
10683
10684 serializeCount++;
10685
10686 // Need to convert to a string type on the way out unfortunately :(
10687 // The WebView layer runs slow if you pass byte[] directly.
10688 return thriftHelper.getBinaryString();
10689 };
10690};
10691
10692/*
10693 * AltGeoMatSerializer serializes a Three.js scene into a Thrift message.
10694 *
10695 * Copyright (c) 2015 AltspaceVR
10696 */
10697altspace._internal.AltGeoMatSerializer = function () {
10698 var PROFILE = false;
10699
10700 var getGeometries = function (obj, geometries) {
10701 if (obj.geometry) {
10702 geometries[obj.geometry.uuid] = obj.geometry;
10703 }
10704 for (var i = 0, l = obj.children.length; i < l; i ++) {
10705 getGeometries(obj.children[i], geometries);
10706 }
10707 };
10708 var geoNeedsUpdate = function (geo) {
10709 return (
10710 geo.needsUpdate === undefined ||
10711 geo.verticesNeedUpdate ||
10712 geo.elementsNeedUpdate ||
10713 geo.uvsNeedUpdate ||
10714 geo.normalsNeedUpdate ||
10715 geo.tangentsNeedUpdate ||
10716 geo.colorsNeedUpdate ||
10717 geo.lineDistancesNeedUpdate ||
10718 geo.groupsNeedUpdate
10719 );
10720 };
10721 var resetGeoFlags = function (geo) {
10722 if (geo) {
10723 geo.needsUpdate = false;
10724 geo.verticesNeedUpdate = false;
10725 geo.elementsNeedUpdate = false;
10726 geo.uvsNeedUpdate = false;
10727 geo.normalsNeedUpdate = false;
10728 geo.tangentsNeedUpdate = false;
10729 geo.colorsNeedUpdate = false;
10730 geo.lineDistancesNeedUpdate = false;
10731 geo.groupsNeedUpdate = false;
10732 }
10733 };
10734
10735 var getThriftGeometryData = function (geometry) {
10736 var thriftGeometryData = new ThreeJSGeometryData();
10737 var jsonData;
10738 if (geometry instanceof THREE.Geometry) {
10739 jsonData = THREE.Geometry.prototype.toJSON.call(geometry).data;
10740 thriftGeometryData.Vertices = jsonData.vertices;
10741 thriftGeometryData.Faces = jsonData.faces;
10742 // The current version of Three.js only produces one UV layer.
10743 thriftGeometryData.Uvs = jsonData.uvs && jsonData.uvs[0];
10744 thriftGeometryData.IsBufferedGeometry = false;
10745 }
10746 else if (geometry instanceof THREE.BufferGeometry) {
10747 jsonData = THREE.BufferGeometry.prototype.toJSON.call(geometry).data;
10748 thriftGeometryData.Vertices = jsonData.attributes.position.array;
10749 thriftGeometryData.Faces = jsonData.index && jsonData.index.array || [];
10750 thriftGeometryData.Uvs = jsonData.attributes.uv && jsonData.attributes.uv.array || [];
10751 thriftGeometryData.IsBufferedGeometry = true;
10752 }
10753 else {
10754 throw new Error('AltspaceVR: Unrecognized geometry type');
10755 }
10756 return thriftGeometryData;
10757 };
10758
10759 var serializeGeometries = function (scene, thriftScene) {
10760 if (!thriftScene.Geometries) { return; }
10761 var geometries = {};
10762 getGeometries(scene, geometries);
10763 for (var j = 0, l = thriftScene.Geometries.length; j < l; j++) {
10764 var geometry = geometries[thriftScene.Geometries[j].Uuid];
10765 resetGeoFlags(geometry);
10766 var origParams = geometry.parameters;
10767 // Temporarily delete geo params so that toJSON actually serializes
10768 // vertices.
10769 delete geometry.parameters;
10770 thriftScene.Geometries[j].Data = getThriftGeometryData(geometry);
10771 geometry.parameters = origParams;
10772 }
10773 };
10774
10775 var getMaterials = function (obj, materials) {
10776 if (obj.material) {
10777 materials[obj.material.uuid] = obj.material;
10778 }
10779 if (!obj.children) { return; }
10780 for (var i = 0, l = obj.children.length; i < l; i ++) {
10781 getMaterials(obj.children[i], materials);
10782 }
10783 };
10784 var getDataUri = function (image) {
10785 var canvas;
10786 if (image.nodeName === 'CANVAS') {
10787 canvas = image;
10788 }
10789 else {
10790 canvas = document.createElement('canvas');
10791 canvas.width = image.width;
10792 canvas.height = image.height;
10793 var context = canvas.getContext('2d');
10794 context.drawImage(image, 0, 0, image.width, image.height);
10795 }
10796 return canvas.toDataURL('image/png');
10797 };
10798 var previousMatStates = {};
10799 var matNeedsUpdate = function (mat) {
10800 if (!mat) { return false; }
10801 var prevMat = previousMatStates[mat.uuid];
10802 var materialIsNew = prevMat === undefined;
10803 var matVisibilityChanged, matColorChanged, mapChanged;
10804 if (!materialIsNew) {
10805 matVisibilityChanged = mat.visible !== prevMat.visible;
10806 matSideChanged = mat.side !== prevMat.side;
10807 matTransparentChanged = mat.transparent !== prevMat.transparent;
10808 matOpacityChanged = mat.opacity !== prevMat.opacity;
10809 matColorChanged = mat.color !== prevMat.color && (!mat.color || !mat.color.equals(prevMat.color));
10810 mapChanged = mat.map && (
10811 mat.map.needsUpdate ||
10812 (
10813 mat.map.image &&
10814 mat.map.image.src !== prevMat.mapSrc
10815 ) ||
10816 mat.map.version !== prevMat.mapVersion ||
10817 mat.map.offset.x !== prevMat.mapOffsetX ||
10818 mat.map.offset.y !== prevMat.mapOffsetY ||
10819 mat.map.repeat.x !== prevMat.mapRepeatX ||
10820 mat.map.repeat.y !== prevMat.mapRepeatY ||
10821 // Note: We only use wrapS because Unity does not support wrap modes on each axis.
10822 mat.map.wrapS !== prevMat.mapWrapS
10823 );
10824 }
10825 var mapIsEmptyOrTextureIsLoaded = mat.map && mat.map.image || !mat.map;
10826
10827 var needsUpdate = (
10828 materialIsNew ||
10829 matVisibilityChanged ||
10830 matSideChanged ||
10831 matTransparentChanged ||
10832 matOpacityChanged ||
10833 matColorChanged ||
10834 mapChanged
10835 ) && mapIsEmptyOrTextureIsLoaded;
10836
10837 return needsUpdate;
10838 };
10839 var updatePreviousMatStates = function (mat, sourceHash) {
10840 var prevMat = previousMatStates[mat.uuid];
10841 if (prevMat === undefined) {
10842 prevMat = previousMatStates[mat.uuid] = {};
10843 }
10844 prevMat.visible = mat.visible;
10845 prevMat.side = mat.side;
10846 prevMat.transparent = mat.transparent;
10847 prevMat.opacity = mat.opacity;
10848 prevMat.color = mat.color && mat.color.clone();
10849 if (mat.map) {
10850 prevMat.mapSrc = mat.map.image && mat.map.image.src;
10851 prevMat.mapVersion = mat.map.version;
10852 prevMat.mapOffsetX = mat.map.offset.x;
10853 prevMat.mapOffsetY = mat.map.offset.y;
10854 prevMat.mapRepeatX = mat.map.repeat.x;
10855 prevMat.mapRepeatY = mat.map.repeat.y;
10856 prevMat.mapWrapS = mat.map.wrapS;
10857 }
10858 prevMat.sourceHash = sourceHash;
10859 };
10860
10861 var hashString = function(str) {
10862 var hash = 5381;
10863 var i = str.length - 1;
10864 var step = Math.max(Math.floor(i / 1024), 1); // Hack, take 1024 sampled bytes from really large data for perf.
10865
10866 while (i >= 0) {
10867 hash = (hash * 33) ^ str.charCodeAt(i);
10868 i -= step;
10869 }
10870
10871 return hash >>> 0;
10872 };
10873
10874 var serializeMaterials = function (scene, thriftScene) {
10875 if (!thriftScene.Materials) { return; }
10876 var materials = {};
10877 getMaterials(scene, materials);
10878 for (var j = 0, l = thriftScene.Materials.length; j < l; j++) {
10879 var outMaterial = thriftScene.Materials[j];
10880
10881 var material = materials[outMaterial.Uuid];
10882 outMaterial.Visible = material.visible;
10883 outMaterial.Side = material.side;
10884 outMaterial.Transparent = material.transparent;
10885 outMaterial.Opacity = material.opacity;
10886 outMaterial.SourceHash = -1;
10887 outMaterial.TextureDataUri = '';
10888 outMaterial.Src = '';
10889
10890 var image = material.map && material.map.image;
10891
10892 if (image) {
10893 outMaterial.MapOffsetX = material.map.offset.x;
10894 outMaterial.MapOffsetY = material.map.offset.y;
10895 outMaterial.MapRepeatX = material.map.repeat.x;
10896 outMaterial.MapRepeatY = material.map.repeat.y;
10897 // Note: We only use wrapS because Unity does not support wrap modes on each axis.
10898 outMaterial.MapWrapS = material.map.wrapS;
10899 var prevMatState = previousMatStates[material.uuid];
10900 var prevMapSrc = prevMatState && prevMatState.mapSrc;
10901 var prevMapVersion = prevMatState && prevMatState.mapVersion;
10902 var prevSourceHash = prevMatState && prevMatState.sourceHash;
10903
10904 if (prevSourceHash) {
10905 outMaterial.SourceHash = prevSourceHash;
10906 outMaterial.TextureDataUri = '';
10907 outMaterial.Src = '';
10908 }
10909
10910 if (image.src && prevMapSrc !== image.src) {
10911 outMaterial.Src = image.src;
10912 outMaterial.SourceHash = hashString(outMaterial.Src);
10913 outMaterial.TextureDataUri = '';
10914 material.map.needsUpdate = false;
10915 } else if (
10916 (!prevMatState && !image.src) || // Non-src material initial load
10917 material.map.needsUpdate || // Material updated
10918 (prevMatState && material.map.version !== prevMapVersion) // Material version changed
10919 ) {
10920 console.warn(
10921 'AltspaceVR: Serializing texture for material ' + material.uuid + '. ' +
10922 'Improve performance by using textures with power-of-two dimensions.');
10923 var dataUri = getDataUri(image);
10924 var textureData = new Buffer(dataUri.length);
10925 textureData.setRawString(0, dataUri);
10926 outMaterial.TextureDataUri = textureData;
10927 outMaterial.SourceHash = hashString(dataUri);
10928 outMaterial.Src = '';
10929 material.map.needsUpdate = false;
10930 }
10931 }
10932 else {
10933 outMaterial.MapOffsetX = outMaterial.MapOffsetY = 0;
10934 outMaterial.MapRepeatX = outMaterial.MapRepeatY = 1;
10935 outMaterial.MapWrapS = THREE.RepeatWrapping;
10936 }
10937
10938 updatePreviousMatStates(material, outMaterial.SourceHash);
10939 }
10940 };
10941
10942 var resetFlags = function (obj) {
10943 var isMesh = obj instanceof THREE.Mesh;
10944 var geo = isMesh && obj.geo;
10945 resetGeoFlags(geo);
10946 var mat = isMesh && obj.material;
10947 if (mat) {
10948 mat.needsUpdate = false;
10949 }
10950 var map = mat && mat.map;
10951 if (map) {
10952 map.needsUpdate = false;
10953 }
10954 for (var i = 0; i < obj.children.length; i++) {
10955 resetFlags(obj.children[i]);
10956 }
10957 };
10958 var sceneMeshes = {};
10959
10960 var getThriftGeometry = function (geoUuid) {
10961 var thriftGeometry = new ThreeJSGeometry();
10962 thriftGeometry.Uuid = geoUuid;
10963 return thriftGeometry;
10964 };
10965
10966 var getThriftMaterial = function (material) {
10967 var thriftMaterial = new ThreeJSMaterial();
10968 thriftMaterial.Uuid = material.uuid;
10969 thriftMaterial.Color = material.color ? material.color.getHex() : -1;
10970 return thriftMaterial;
10971 };
10972
10973 var getVertexCount = function (geometry) {
10974 return (
10975 // THREE.Geometry
10976 geometry.faces && geometry.faces.length ||
10977 // THREE.BufferGeometry
10978 geometry.attributes && geometry.attributes.position && geometry.attributes.position.count * 3
10979 );
10980 };
10981
10982 var hasValidGeometry = function (obj) {
10983 if (!obj.geometry) { return false; }
10984 return getVertexCount(obj.geometry) > 0;
10985 };
10986
10987 // Unity cannot load meshes with more than 65000 vertices.
10988 var maxVertexCount = 65000;
10989
10990 var getMeshesGeosMats = function (obj, meshes, geos, mats) {
10991 if (obj instanceof THREE.Mesh && hasValidGeometry(obj)) {
10992 var vertexCount = getVertexCount(obj.geometry);
10993 if (vertexCount > maxVertexCount) {
10994 if (!sceneMeshes[obj.uuid]) {
10995 console.error(
10996 'AltspaceVR: Skipping mesh ' + obj.uuid +
10997 ' since its vertex count (' + vertexCount.toLocaleString() + ') exceeds ' +
10998 maxVertexCount.toLocaleString() +
10999 ' (This message will not be shown again for this object until the app is reloaded)'
11000 );
11001 sceneMeshes[obj.uuid] = true;
11002 }
11003 return;
11004 }
11005 var geoNeededUpdate, matNeededUpdate;
11006 if (!geos[obj.geometry.uuid] && geoNeedsUpdate(obj.geometry)) {
11007 geos[obj.geometry.uuid] = getThriftGeometry(obj.geometry.uuid);
11008 geoNeededUpdate = true;
11009 }
11010 if (!mats[obj.material.uuid] && matNeedsUpdate(obj.material)) {
11011 mats[obj.material.uuid] = getThriftMaterial(obj.material);
11012 matNeededUpdate = true;
11013 }
11014 if (
11015 geoNeededUpdate ||
11016 matNeededUpdate ||
11017 !sceneMeshes[obj.uuid]
11018 ) {
11019 var thriftMesh = new ThreeJSMesh();
11020 thriftMesh.Geometry = obj.geometry.uuid;
11021 thriftMesh.Material = obj.material.uuid;
11022 thriftMesh.MeshId = obj.id;
11023 meshes.push(thriftMesh);
11024 sceneMeshes[obj.uuid] = true;
11025 }
11026 }
11027 if (!obj.children) { return; }
11028 for (var i = 0; i < obj.children.length; i++) {
11029 getMeshesGeosMats(obj.children[i], meshes, geos, mats);
11030 }
11031 };
11032 var getValues = function (obj) {
11033 var values = [];
11034 for (var key in obj) {
11035 if (obj.hasOwnProperty(key)) {
11036 values.push(obj[key]);
11037 }
11038 }
11039 return values;
11040 };
11041 var getThriftScene = function (scene) {
11042 var thriftScene = new ThreeJSScene();
11043 var meshes = [];
11044 var geos = {};
11045 var mats = {};
11046 getMeshesGeosMats(scene, meshes, geos, mats);
11047 thriftScene.Geometries = getValues(geos);
11048 thriftScene.Materials = getValues(mats);
11049 thriftScene.Meshes = meshes;
11050 return thriftScene;
11051 };
11052 var sceneUuidList = [];
11053
11054 var serializeCount = 0;
11055 var totalSerializeLength = 0;
11056 var serializeLength = 0;
11057 var totalTime = 0;
11058 var needsUpdateTime = 0;
11059 var needsUpdateCount = 0;
11060 var serializeTime = 0;
11061 var lastLog = performance.now();
11062 var logPerformance = function () {
11063 var serializeLengthKB = serializeLength / 1024;
11064 console.log(
11065 '\nserializeCount', serializeCount,
11066 '\naverageSerializeMS', (serializeTime / serializeCount).toFixed(3),
11067 '\nserializedKB', serializeLengthKB.toFixed(3),
11068 '\naverageKB', (serializeLengthKB / serializeCount).toFixed(3),
11069 '\nneedsUpdateCount', needsUpdateCount,
11070 '\naverageNeedsUpdateMS', (needsUpdateTime / needsUpdateCount).toFixed(3),
11071 '\ntotalMS', totalTime.toFixed(3),
11072 '\ntotalSerializedKB', (totalSerializeLength / 1024).toFixed(3)
11073 );
11074 };
11075
11076 this.sceneNeedsUpdate = function (scene) {
11077 var start;
11078 if (PROFILE) {
11079 start = performance.now();
11080 }
11081
11082 var needsUpdate = false;
11083 var objCounter = 0;
11084 scene.traverse(function (obj) {
11085 var sceneListChanged = sceneUuidList[objCounter] !== obj.uuid;
11086 if (
11087 sceneListChanged ||
11088 hasValidGeometry(obj) &&
11089 (
11090 geoNeedsUpdate(obj.geometry) ||
11091 matNeedsUpdate(obj.material)
11092 )
11093 ) {
11094 needsUpdate = true;
11095 }
11096 sceneUuidList[objCounter] = obj.uuid;
11097 objCounter++;
11098 });
11099
11100 if (PROFILE) {
11101 var delta = performance.now() - start;
11102 needsUpdateTime += delta;
11103 totalTime += delta;
11104 needsUpdateCount++;
11105 if (performance.now() - lastLog > 1000) {
11106 logPerformance();
11107 serializeCount = serializeLength = serializeTime = needsUpdateTime = needsUpdateCount = 0;
11108 lastLog = performance.now();
11109 }
11110 }
11111
11112 return needsUpdate;
11113 };
11114 this.serializeScene = function (scene) {
11115 var start;
11116 if (PROFILE) {
11117 start = performance.now();
11118 }
11119
11120 var thriftScene = getThriftScene(scene);
11121 serializeGeometries(scene, thriftScene);
11122 serializeMaterials(scene, thriftScene);
11123
11124 var bindCallMessage = new BindCallMessage();
11125 bindCallMessage.BindingName = "RenderThreeJSScene";
11126 bindCallMessage.RequestID = 0;
11127 bindCallMessage.ThreeJSScene = thriftScene;
11128
11129 var output = altspace._internal.ScratchThriftBuffer.getBinaryString(bindCallMessage);
11130
11131 if (PROFILE) {
11132 var delta = performance.now() - start;
11133 serializeTime += delta;
11134 serializeCount++;
11135 serializeLength += output.length;
11136 totalSerializeLength += output.length;
11137 totalTime += delta;
11138 }
11139 return output;
11140 };
11141 this.hasValidGeometry = hasValidGeometry;
11142};
11143
11144
11145/*
11146 * AltRenderer renders a Three.js scene in the Altspace web browser.
11147 *
11148 * Author: Gavan Wilhite
11149 * Copyright (c) 2015 AltspaceVR
11150 */
11151
11152var GEO_MAT_VERSION = '0.2.0';
11153
11154/**
11155 * AltRenderer renders a Three.js scene in AltspaceVR. AltRenderer should not
11156 * be instantiated directly, instead it should be retrieved via
11157 * [altspace.getThreeJSRenderer]{@link module:altspace.getThreeJSRenderer}.
11158 * @class module:altspace~AltRenderer
11159 * @memberof module:altspace
11160 */
11161altspace._internal.AltRenderer = function ( options ) {
11162 options = options || {};
11163 console.log( 'THREE.AltRenderer', THREE.REVISION );
11164
11165 var serializationFilter;
11166 var geoMatSerializer;
11167
11168 if (!options.version || options.version === GEO_MAT_VERSION) {
11169 options.version = GEO_MAT_VERSION;
11170 geoMatSerializer = new altspace._internal.AltGeoMatSerializer();
11171 serializationFilter = function (object3d) {
11172 return (
11173 object3d instanceof THREE.Mesh &&
11174 geoMatSerializer.hasValidGeometry(object3d)
11175 );
11176 };
11177 }
11178 else {
11179 // TODO Deprecate v0.1
11180 options.version = '0.1.0';
11181 serializationFilter = function (object3d) {
11182 // Objects loaded by AltOBJMTLLoader have a 'src' property.
11183 return object3d.userData.hasOwnProperty('src');
11184 };
11185 }
11186 console.log("AltRenderer version " + options.version);
11187
11188 var sceneUpdateSerializer = new altspace._internal.AltSceneUpdateSerializer(serializationFilter);
11189
11190 Object.defineProperty(this, "domElement", {
11191 get : function(){
11192 console.log("AltRenderer.domElement not implemented");
11193 return null;
11194 },
11195 configurable: true
11196 });
11197
11198 function sendClientThriftMessage(func, message) {
11199 altspace._internal.callClientFunction(
11200 func,
11201 { Message: message },
11202 { argsType: "ThriftMessage" }
11203 );
11204 }
11205
11206 function sendSceneToAltspace(serializedScene){
11207 sendClientThriftMessage("RenderThreeJSScene", serializedScene);
11208 }
11209
11210 function sendUpdatesToAltspace(sceneUpdateMessage){
11211 sendClientThriftMessage("UpdateThreeJSScene", sceneUpdateMessage);
11212 }
11213
11214 var initialRender = true;
11215 /**
11216 * Render the given scene in AltspaceVR.
11217 * @instance render
11218 * @method render
11219 * @param {THREE.Scene} scene
11220 * @memberof module:altspace~AltRenderer
11221 */
11222 this.render = throttle(function ( scene ) {
11223 altspace._internal.setThreeJSScene(scene);
11224 scene.updateMatrixWorld();
11225 if (options.version === GEO_MAT_VERSION) {
11226 if(geoMatSerializer.sceneNeedsUpdate(scene) || initialRender) {
11227 initialRender = false;
11228 var serializedScene = geoMatSerializer.serializeScene(scene);
11229 sendSceneToAltspace( serializedScene );
11230 }
11231 }
11232
11233 var sceneUpdateMessage = sceneUpdateSerializer.serializeScene(scene);
11234 sendUpdatesToAltspace(sceneUpdateMessage);
11235 }, 33);
11236
11237 function throttle(func, wait, options) {
11238 var context, args, result;
11239 var timeout = null;
11240 var previous = 0;
11241 if (!options) options = {};
11242 var later = function() {
11243 previous = options.leading === false ? 0 : Date.now();
11244 timeout = null;
11245 result = func.apply(context, args);
11246 if (!timeout) context = args = null;
11247 };
11248 return function() {
11249 var now = Date.now();
11250 if (!previous && options.leading === false) previous = now;
11251 var remaining = wait - (now - previous);
11252 context = this;
11253 args = arguments;
11254 if (remaining <= 0 || remaining > wait) {
11255 if (timeout) {
11256 clearTimeout(timeout);
11257 timeout = null;
11258 }
11259 previous = now;
11260 result = func.apply(context, args);
11261 if (!timeout) context = args = null;
11262 } else if (!timeout && options.trailing !== false) {
11263 timeout = setTimeout(later, remaining);
11264 }
11265 return result;
11266 };
11267 }
11268
11269};