This repository has been archived by the owner on Apr 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
fm.websync.subscribers.js
1515 lines (1144 loc) · 41.9 KB
/
fm.websync.subscribers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Vendor: Frozen Mountain Software
* Title: WebSync Client Subscribers Extension for JavaScript
* Version: 4.2.0
* Copyright Frozen Mountain Software 2011+
*/
if (typeof global !== 'undefined' && !global.window) { global.window = global; global.document = { cookie: '' }; }
if (!window.fm) { window.fm = {}; }
if (!window.fm.websync) { window.fm.websync = {}; }
if (!window.fm.websync.subscribers) { window.fm.websync.subscribers = {}; }
var __hasProp = {}.hasOwnProperty;
var __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
/**
@class fm.websync.subscribers.subscriberChangeType
<div>
The subscribers change type.
</div><div>
The type of change to the subscribers of a channel, subscribe or unsubscribe.
</div>
@extends fm.enum
*/
fm.websync.subscribers.subscriberChangeType = {
/**
@type {fm.websync.subscribers.subscriberChangeType}
@description <div>
Indicates that new clients are subscribing to the channel.
</div>
*/
Subscribe: 1,
/**
@type {fm.websync.subscribers.subscriberChangeType}
@description <div>
Indicates that existing clients are unsubscribing from the channel.
</div>
*/
Unsubscribe: 2
};
/**
@class fm.websync.subscribers.base
<div>
Base methods supporting the Subscribers extension.
</div>
@extends fm.object
*/
fm.websync.subscribers.base = (function(_super) {
__extends(base, _super);
/**
@ignore
@description <div>
The channel prefix applied to Subscribers notifications.
</div>
*/
base._subscribersChannelPrefix = "/fm/subscribers";
/**
@ignore
@description <div>
The reserved name for the Subscribers extension.
</div>
*/
base._subscribersExtensionName = "fm.subscribers";
/**
@ignore
@description
*/
function base() {
if (arguments.length === 1 && fm.util.isPlainObject(arguments[0]) && fm.util.canAttachProperties(this, arguments[0])) {
base.__super__.constructor.call(this);
fm.util.attachProperties(this, arguments[0]);
return;
}
}
/**
<div>
Gets the subscribed clients.
</div><param name="extensible">The extensible base.</param><returns>The subscribed clients.</returns>
@function getSubscribedClients
@param {fm.websync.extensible} extensible
@return {fm.hash}
*/
base.getSubscribedClients = function() {
var dictionary, extensible, _var0;
extensible = arguments[0];
dictionary = fm.websync.subscribers.serializer.deserializeSubscribedClients(extensible.getExtensionValueJson("fm.subscribers"));
_var0 = dictionary;
if (_var0 === null || typeof _var0 === 'undefined') {
throw new Error("Subscribed clients could not be parsed.");
}
return dictionary;
};
/**
<div>
Sets the subscribed clients.
</div><param name="extensible">The extensible base.</param><param name="subscribedClients">The subscribed clients.</param>
@function setSubscribedClients
@param {fm.websync.extensible} extensible
@param {fm.hash} subscribedClients
@return {void}
*/
base.setSubscribedClients = function() {
var extensible, subscribedClients;
extensible = arguments[0];
subscribedClients = arguments[1];
return extensible.setExtensionValueJson("fm.subscribers", fm.websync.subscribers.serializer.serializeSubscribedClients(subscribedClients));
};
return base;
}).call(this, fm.object);
/**
@class fm.websync.subscribers.clientUnsubscribeArgs
<div>
Arguments for the subscriber change callback.
</div>
@extends fm.websync.baseSuccessArgs
*/
fm.websync.subscribers.clientUnsubscribeArgs = (function(_super) {
__extends(clientUnsubscribeArgs, _super);
/**
@ignore
@description
*/
clientUnsubscribeArgs.prototype._channel = null;
/**
@ignore
@description
*/
clientUnsubscribeArgs.prototype._unsubscribedClient = null;
/**
@ignore
@description
*/
function clientUnsubscribeArgs() {
this.setUnsubscribedClient = __bind(this.setUnsubscribedClient, this);
this.setChannel = __bind(this.setChannel, this);
this.getUnsubscribedClient = __bind(this.getUnsubscribedClient, this);
this.getChannel = __bind(this.getChannel, this);
if (arguments.length === 1 && fm.util.isPlainObject(arguments[0]) && fm.util.canAttachProperties(this, arguments[0])) {
clientUnsubscribeArgs.__super__.constructor.call(this);
fm.util.attachProperties(this, arguments[0]);
return;
}
clientUnsubscribeArgs.__super__.constructor.call(this);
}
/**
<div>
Gets the channel on which the change occurred.
</div>
@function getChannel
@return {fm.string}
*/
clientUnsubscribeArgs.prototype.getChannel = function() {
return this._channel;
};
/**
<div>
Gets the client who unsubscribed from the channel.
</div>
@function getUnsubscribedClient
@return {fm.websync.subscribedClient}
*/
clientUnsubscribeArgs.prototype.getUnsubscribedClient = function() {
return this._unsubscribedClient;
};
/**
<div>
Sets the channel on which the change occurred.
</div>
@function setChannel
@param {fm.string} value
@return {void}
*/
clientUnsubscribeArgs.prototype.setChannel = function() {
var value;
value = arguments[0];
return this._channel = value;
};
/**
<div>
Sets the client who unsubscribed from the channel.
</div>
@function setUnsubscribedClient
@param {fm.websync.subscribedClient} value
@return {void}
*/
clientUnsubscribeArgs.prototype.setUnsubscribedClient = function() {
var value;
value = arguments[0];
return this._unsubscribedClient = value;
};
return clientUnsubscribeArgs;
})(fm.websync.baseSuccessArgs);
/**
@class fm.websync.subscribers.serializer
@extends fm.object
*/
fm.websync.subscribers.serializer = (function(_super) {
__extends(serializer, _super);
/**
@ignore
@description
*/
function serializer() {
if (arguments.length === 1 && fm.util.isPlainObject(arguments[0]) && fm.util.canAttachProperties(this, arguments[0])) {
serializer.__super__.constructor.call(this);
fm.util.attachProperties(this, arguments[0]);
return;
}
serializer.__super__.constructor.call(this);
}
/**
@function createSubscribedClients
@return {fm.hash}
*/
serializer.createSubscribedClients = function() {
return {};
};
/**
@function createSubscriberChange
@return {fm.websync.subscribers.subscriberChange}
*/
serializer.createSubscriberChange = function() {
return new fm.websync.subscribers.subscriberChange();
};
/**
<div>
Deserializes a subscribed clients collection from JSON.
</div><param name="subscribedClientsJson">The subscribed clients collection (in JSON) to deserialize.</param><returns>The deserialized subscribed clients collection.</returns>
@function deserializeSubscribedClients
@param {fm.string} subscribedClientsJson
@return {fm.hash}
*/
serializer.deserializeSubscribedClients = function() {
var subscribedClientsJson;
subscribedClientsJson = arguments[0];
return fm.serializer.deserializeObject(subscribedClientsJson, serializer.createSubscribedClients, serializer.deserializeSubscribedClientsCallback);
};
/**
@function deserializeSubscribedClientsCallback
@param {fm.hash} subscribedClients
@param {fm.string} name
@param {fm.string} valueJson
@return {void}
*/
serializer.deserializeSubscribedClientsCallback = function() {
var name, subscribedClients, valueJson;
subscribedClients = arguments[0];
name = arguments[1];
valueJson = arguments[2];
return subscribedClients[name] = fm.websync.subscribedClient.fromJsonMultiple(valueJson);
};
/**
<div>
Deserializes a subscriber change object from JSON.
</div><param name="subscriberChangeJson">The subscriber change object (in JSON) to deserialize.</param><returns>The deserialized subscriber change object.</returns>
@function deserializeSubscriberChange
@param {fm.string} subscriberChangeJson
@return {fm.websync.subscribers.subscriberChange}
*/
serializer.deserializeSubscriberChange = function() {
var subscriberChangeJson;
subscriberChangeJson = arguments[0];
return fm.serializer.deserializeObjectFast(subscriberChangeJson, serializer.createSubscriberChange, serializer.deserializeSubscriberChangeCallback);
};
/**
@function deserializeSubscriberChangeCallback
@param {fm.websync.subscribers.subscriberChange} subscriberChange
@param {fm.string} name
@param {fm.string} valueJson
@return {void}
*/
serializer.deserializeSubscriberChangeCallback = function() {
var name, str, subscriberChange, valueJson, _var0;
subscriberChange = arguments[0];
name = arguments[1];
valueJson = arguments[2];
str = name;
_var0 = str;
if (_var0 !== null && typeof _var0 !== 'undefined') {
if (!(str === "client")) {
if (str === "type") {
return subscriberChange.setType(fm.websync.subscribers.serializer.deserializeSubscriberChangeType(valueJson));
}
} else {
return subscriberChange.setClient(fm.websync.subscribedClient.fromJson(valueJson));
}
}
};
/**
<div>
Deserializes a subscriber change type from JSON.
</div><param name="subscriberChangeTypeJson">The subscriber change type (in JSON) to deserialize.</param><returns>The deserialized subscriber change type.</returns>
@function deserializeSubscriberChangeType
@param {fm.string} subscriberChangeTypeJson
@return {fm.websync.subscribers.subscriberChangeType}
*/
serializer.deserializeSubscriberChangeType = function() {
var subscriberChangeTypeJson;
subscriberChangeTypeJson = arguments[0];
switch (fm.serializer.deserializeString(subscriberChangeTypeJson)) {
case "subscribe":
return fm.websync.subscribers.subscriberChangeType.Subscribe;
case "unsubscribe":
return fm.websync.subscribers.subscriberChangeType.Unsubscribe;
}
throw new Error("Unknown subscriber change type.");
};
/**
<div>
Serializes a subscribed clients collection to JSON.
</div><param name="subscribedClients">The subscribed clients collection to serialize.</param><returns>The serialized subscribed clients collection.</returns>
@function serializeSubscribedClients
@param {fm.hash} subscribedClients
@return {fm.string}
*/
serializer.serializeSubscribedClients = function() {
var subscribedClients;
subscribedClients = arguments[0];
return fm.serializer.serializeObject(subscribedClients, serializer.serializeSubscribedClientsCallback);
};
/**
@function serializeSubscribedClientsCallback
@param {fm.hash} subscribedClients
@param {fm.hash} jsonObject
@return {void}
*/
serializer.serializeSubscribedClientsCallback = function() {
var jsonObject, str, subscribedClients, _i, _len, _results, _var0;
subscribedClients = arguments[0];
jsonObject = arguments[1];
_var0 = fm.hashExtensions.getKeys(subscribedClients);
_results = [];
for (_i = 0, _len = _var0.length; _i < _len; _i++) {
str = _var0[_i];
_results.push(jsonObject[str] = fm.websync.subscribedClient.toJsonMultiple(subscribedClients[str]));
}
return _results;
};
/**
<div>
Serializes a subscriber change object to JSON.
</div><param name="subscriberChange">The subscriber change object to serialize.</param><returns>The serialized subscriber change object.</returns>
@function serializeSubscriberChange
@param {fm.websync.subscribers.subscriberChange} subscriberChange
@return {fm.string}
*/
serializer.serializeSubscriberChange = function() {
var subscriberChange;
subscriberChange = arguments[0];
return fm.serializer.serializeObjectFast(subscriberChange, serializer.serializeSubscriberChangeCallback);
};
/**
@function serializeSubscriberChangeCallback
@param {fm.websync.subscribers.subscriberChange} subscriberChange
@param {fm.hash} jsonObject
@return {void}
*/
serializer.serializeSubscriberChangeCallback = function() {
var jsonObject, subscriberChange, _var0;
subscriberChange = arguments[0];
jsonObject = arguments[1];
_var0 = subscriberChange.getClient();
if (_var0 !== null && typeof _var0 !== 'undefined') {
jsonObject["client"] = fm.websync.subscribedClient.toJson(subscriberChange.getClient());
}
return jsonObject["type"] = fm.websync.subscribers.serializer.serializeSubscriberChangeType(subscriberChange.getType());
};
/**
<div>
Serializes a subscriber change type to JSON.
</div><param name="subscriberChangeType">The subscriber change type to serialize.</param><returns>The serialized subscriber change type.</returns>
@function serializeSubscriberChangeType
@param {fm.websync.subscribers.subscriberChangeType} subscriberChangeType
@return {fm.string}
*/
serializer.serializeSubscriberChangeType = function() {
var str, subscriberChangeType;
subscriberChangeType = arguments[0];
switch (subscriberChangeType) {
case fm.websync.subscribers.subscriberChangeType.Subscribe:
str = "subscribe";
break;
case fm.websync.subscribers.subscriberChangeType.Unsubscribe:
str = "unsubscribe";
break;
default:
throw new Error("Unknown subscriber change type.");
}
return fm.serializer.serializeString(str);
};
return serializer;
}).call(this, fm.object);
/**
@class fm.websync.subscribers.subscriberChangeCallback
@extends fm.object
*/
fm.websync.subscribers.subscriberChangeCallback = (function(_super) {
__extends(subscriberChangeCallback, _super);
/**
@ignore
@description
*/
subscriberChangeCallback.prototype._dynamicProperties = null;
/**
@ignore
@description
*/
subscriberChangeCallback.prototype._onClientSubscribe = null;
/**
@ignore
@description
*/
subscriberChangeCallback.prototype._onClientUnsubscribe = null;
/**
@ignore
@description
*/
function subscriberChangeCallback() {
this.setOnClientUnsubscribe = __bind(this.setOnClientUnsubscribe, this);
this.setOnClientSubscribe = __bind(this.setOnClientSubscribe, this);
this.setDynamicProperties = __bind(this.setDynamicProperties, this);
this.onReceive = __bind(this.onReceive, this);
this.getOnClientUnsubscribe = __bind(this.getOnClientUnsubscribe, this);
this.getOnClientSubscribe = __bind(this.getOnClientSubscribe, this);
this.getDynamicProperties = __bind(this.getDynamicProperties, this);
var dynamicProperties, onClientSubscribe, onClientUnsubscribe;
if (arguments.length === 1 && fm.util.isPlainObject(arguments[0]) && fm.util.canAttachProperties(this, arguments[0])) {
subscriberChangeCallback.__super__.constructor.call(this);
fm.util.attachProperties(this, arguments[0]);
return;
}
onClientSubscribe = arguments[0];
onClientUnsubscribe = arguments[1];
dynamicProperties = arguments[2];
subscriberChangeCallback.__super__.constructor.call(this);
this.setOnClientSubscribe(onClientSubscribe);
this.setOnClientUnsubscribe(onClientUnsubscribe);
this.setDynamicProperties(dynamicProperties);
}
/**
@function getDynamicProperties
@return {fm.hash}
*/
subscriberChangeCallback.prototype.getDynamicProperties = function() {
return this._dynamicProperties;
};
/**
@function getOnClientSubscribe
@return {fm.singleAction}
*/
subscriberChangeCallback.prototype.getOnClientSubscribe = function() {
return this._onClientSubscribe;
};
/**
@function getOnClientUnsubscribe
@return {fm.singleAction}
*/
subscriberChangeCallback.prototype.getOnClientUnsubscribe = function() {
return this._onClientUnsubscribe;
};
/**
@function onReceive
@param {fm.websync.subscribeReceiveArgs} receiveArgs
@return {void}
*/
subscriberChangeCallback.prototype.onReceive = function() {
var args2, args3, args4, change, p, receiveArgs, _var0, _var1, _var2;
receiveArgs = arguments[0];
change = fm.websync.subscribers.serializer.deserializeSubscriberChange(receiveArgs.getDataJson());
_var0 = change.getClient().getClientId();
if ((_var0 === null ? _var0 !== receiveArgs.getClient().getClientId() : !_var0.equals(receiveArgs.getClient().getClientId()))) {
if (change.getType() === fm.websync.subscribers.subscriberChangeType.Subscribe) {
_var1 = this.getOnClientSubscribe();
if (_var1 !== null && typeof _var1 !== 'undefined') {
args2 = new fm.websync.subscribers.clientSubscribeArgs();
args2.setSubscribedClient(change.getClient());
args2.setChannel(receiveArgs.getChannel().substring("/fm/subscribers".length));
args2.setTimestamp(receiveArgs.getTimestamp());
args2.setClient(receiveArgs.getClient());
args2.setDynamicProperties(this.getDynamicProperties());
p = args2;
p.copyExtensions(receiveArgs);
return this.getOnClientSubscribe()(p);
}
} else {
_var2 = this.getOnClientUnsubscribe();
if (_var2 !== null && typeof _var2 !== 'undefined') {
args4 = new fm.websync.subscribers.clientUnsubscribeArgs();
args4.setUnsubscribedClient(change.getClient());
args4.setChannel(receiveArgs.getChannel().substring("/fm/subscribers".length));
args4.setTimestamp(receiveArgs.getTimestamp());
args4.setClient(receiveArgs.getClient());
args4.setDynamicProperties(this.getDynamicProperties());
args3 = args4;
args3.copyExtensions(receiveArgs);
return this.getOnClientUnsubscribe()(args3);
}
}
}
};
/**
@function setDynamicProperties
@param {fm.hash} value
@return {void}
*/
subscriberChangeCallback.prototype.setDynamicProperties = function() {
var value;
value = arguments[0];
return this._dynamicProperties = value;
};
/**
@function setOnClientSubscribe
@param {fm.singleAction} value
@return {void}
*/
subscriberChangeCallback.prototype.setOnClientSubscribe = function() {
var value;
value = arguments[0];
return this._onClientSubscribe = value;
};
/**
@function setOnClientUnsubscribe
@param {fm.singleAction} value
@return {void}
*/
subscriberChangeCallback.prototype.setOnClientUnsubscribe = function() {
var value;
value = arguments[0];
return this._onClientUnsubscribe = value;
};
return subscriberChangeCallback;
})(fm.object);
/**
@class fm.websync.subscribers.subscribeArgsExtensions
<div>
<see cref="fm.websync.subscribeArgs">fm.websync.subscribeArgs</see> extension methods for the Subscribers extension.
</div><div>
<p>
The subscribers extension provides support for initial state load and differential
updates on the clients actively subscribed to the channel(s).
</p>
<p>
The extension is activated by adding a reference to your project.
</p>
</div>
*/
fm.websync.subscribers.subscribeArgsExtensions = (function() {
/**
@ignore
@description
*/
function subscribeArgsExtensions() {
if (arguments.length === 1 && fm.util.isPlainObject(arguments[0]) && fm.util.canAttachProperties(this, arguments[0])) {
subscribeArgsExtensions.__super__.constructor.call(this);
fm.util.attachProperties(this, arguments[0]);
return;
}
}
/**
@function addToChannelsCache
@param {fm.websync.client} client
@param {fm.string} channel
@return {void}
*/
subscribeArgsExtensions.addToChannelsCache = function() {
var channel, channelsCache, client, _var0;
client = arguments[0];
channel = arguments[1];
channelsCache = fm.websync.subscribers.subscribeArgsExtensions.getChannelsCache(client);
_var0 = channelsCache;
if (!((_var0 === null || typeof _var0 === 'undefined') || fm.arrayExtensions.contains(channelsCache, channel))) {
return fm.arrayExtensions.add(channelsCache, channel);
}
};
/**
@function client_OnDisconnectResponse
@param {fm.websync.client} client
@param {fm.websync.clientDisconnectResponseArgs} args
@return {void}
*/
subscribeArgsExtensions.client_OnDisconnectResponse = function() {
var args, channelsCache, client, str, _i, _len, _results, _var0, _var1;
client = arguments[0];
args = arguments[1];
channelsCache = fm.websync.subscribers.subscribeArgsExtensions.getChannelsCache(client);
_var0 = channelsCache;
if (_var0 !== null && typeof _var0 !== 'undefined') {
_var1 = channelsCache;
_results = [];
for (_i = 0, _len = _var1.length; _i < _len; _i++) {
str = _var1[_i];
_results.push(args.getClient().unsetCustomOnReceive(str));
}
return _results;
}
};
/**
@function client_OnSubscribeEnd
@param {fm.websync.client} client
@param {fm.websync.clientSubscribeEndArgs} args
@return {void}
*/
subscribeArgsExtensions.client_OnSubscribeEnd = function() {
var args, callback, channel, client, onClientSubscribe, onClientUnsubscribe, str, _i, _len, _results, _var0, _var1, _var2, _var3;
client = arguments[0];
args = arguments[1];
_var0 = args.getException();
if (_var0 === null || typeof _var0 === 'undefined') {
onClientSubscribe = fm.websync.subscribers.subscribeArgsExtensions.getOnClientSubscribe(args.getMethodArgs());
onClientUnsubscribe = fm.websync.subscribers.subscribeArgsExtensions.getOnClientUnsubscribe(args.getMethodArgs());
_var1 = onClientSubscribe;
_var2 = onClientUnsubscribe;
if ((_var1 !== null && typeof _var1 !== 'undefined') || (_var2 !== null && typeof _var2 !== 'undefined')) {
_var3 = args.getResponse().getChannels();
_results = [];
for (_i = 0, _len = _var3.length; _i < _len; _i++) {
str = _var3[_i];
channel = fm.stringExtensions.concat("/fm/subscribers", str);
fm.websync.subscribers.subscribeArgsExtensions.addToChannelsCache(client, channel);
callback = new fm.websync.subscribers.subscriberChangeCallback(onClientSubscribe, onClientUnsubscribe, args.getMethodArgs().getDynamicProperties());
_results.push(args.getClient().setCustomOnReceive(channel, callback.onReceive));
}
return _results;
}
}
};
/**
@function client_OnSubscribeRequest
@param {fm.websync.client} client
@param {fm.websync.clientSubscribeRequestArgs} args
@return {void}
*/
subscribeArgsExtensions.client_OnSubscribeRequest = function() {
var args, client, list, onClientSubscribe, onClientUnsubscribe, str, _i, _len, _var0, _var1, _var2, _var3;
client = arguments[0];
args = arguments[1];
_var0 = fm.websync.subscribers.subscribeArgsExtensions.getChannelsCache(client);
if (_var0 === null || typeof _var0 === 'undefined') {
fm.websync.subscribers.subscribeArgsExtensions.setChannelsCache(client, []);
}
onClientSubscribe = fm.websync.subscribers.subscribeArgsExtensions.getOnClientSubscribe(args.getMethodArgs());
onClientUnsubscribe = fm.websync.subscribers.subscribeArgsExtensions.getOnClientUnsubscribe(args.getMethodArgs());
_var1 = onClientSubscribe;
_var2 = onClientUnsubscribe;
if ((_var1 !== null && typeof _var1 !== 'undefined') || (_var2 !== null && typeof _var2 !== 'undefined')) {
list = [];
_var3 = args.getMethodArgs().getChannels();
for (_i = 0, _len = _var3.length; _i < _len; _i++) {
str = _var3[_i];
fm.arrayExtensions.add(list, str);
fm.arrayExtensions.add(list, fm.stringExtensions.concat("/fm/subscribers", str));
}
return args.getMethodArgs().setChannels(fm.arrayExtensions.toArray(list));
}
};
/**
@function client_OnSubscribeResponse
@param {fm.websync.client} client
@param {fm.websync.clientSubscribeResponseArgs} args
@return {void}
*/
subscribeArgsExtensions.client_OnSubscribeResponse = function() {
var args, client, list, str, _i, _len, _var0, _var1;
client = arguments[0];
args = arguments[1];
_var0 = args.getException();
if (_var0 === null || typeof _var0 === 'undefined') {
list = [];
_var1 = args.getResponse().getChannels();
for (_i = 0, _len = _var1.length; _i < _len; _i++) {
str = _var1[_i];
if (!fm.stringExtensions.startsWith(str, "/fm/subscribers/")) {
fm.arrayExtensions.add(list, str);
}
}
args.getMethodArgs().setChannels(fm.arrayExtensions.toArray(list));
return args.getResponse().setChannels(fm.arrayExtensions.toArray(list));
}
};
/**
@function client_OnUnsubscribeRequest
@param {fm.websync.client} client
@param {fm.websync.clientUnsubscribeRequestArgs} args
@return {void}
*/
subscribeArgsExtensions.client_OnUnsubscribeRequest = function() {
var args, client, list, str, _i, _len, _var0;
client = arguments[0];
args = arguments[1];
list = [];
_var0 = args.getMethodArgs().getChannels();
for (_i = 0, _len = _var0.length; _i < _len; _i++) {
str = _var0[_i];
fm.arrayExtensions.add(list, str);
fm.arrayExtensions.add(list, fm.stringExtensions.concat("/fm/subscribers", str));
}
return args.getMethodArgs().setChannels(fm.arrayExtensions.toArray(list));
};
/**
@function client_OnUnsubscribeResponse
@param {fm.websync.client} client
@param {fm.websync.clientUnsubscribeResponseArgs} args
@return {void}
*/
subscribeArgsExtensions.client_OnUnsubscribeResponse = function() {
var args, client, list, str, _i, _j, _len, _len1, _var0, _var1, _var2;
client = arguments[0];
args = arguments[1];
_var0 = args.getException();
if (_var0 === null || typeof _var0 === 'undefined') {
_var1 = args.getResponse().getChannels();
for (_i = 0, _len = _var1.length; _i < _len; _i++) {
str = _var1[_i];
if (fm.stringExtensions.startsWith(str, "/fm/subscribers")) {
fm.websync.subscribers.subscribeArgsExtensions.removeFromChannelsCache(client, str);
args.getClient().unsetCustomOnReceive(str);
}
}
list = [];
_var2 = args.getResponse().getChannels();
for (_j = 0, _len1 = _var2.length; _j < _len1; _j++) {
str = _var2[_j];
if (!fm.stringExtensions.startsWith(str, "/fm/subscribers/")) {
fm.arrayExtensions.add(list, str);
}
}
args.getMethodArgs().setChannels(fm.arrayExtensions.toArray(list));
return args.getResponse().setChannels(fm.arrayExtensions.toArray(list));
}
};
/**
@function getChannelsCache
@param {fm.websync.client} client
@return {fm.array}
*/
subscribeArgsExtensions.getChannelsCache = function() {
var client;
client = arguments[0];
return fm.global.tryCastArray(client.getDynamicValue("fm.subscribers.channels"));
};
/**
<div>
Gets the callback invoked when a client subscribes.
</div><param name="args">The <see cref="fm.websync.subscribeArgs">fm.websync.subscribeArgs</see> to extend.</param><returns>The callback invoked when a client subscribes.</returns>
@function getOnClientSubscribe
@param {fm.websync.subscribeArgs} args
@return {fm.singleAction}
*/
subscribeArgsExtensions.getOnClientSubscribe = function() {
var args;
args = arguments[0];
return args.getDynamicValue("fm.subscribers.onClientSubscribe");
};
/**
<div>
Gets the callback invoked when a client unsubscribes.
</div><param name="args">The <see cref="fm.websync.subscribeArgs">fm.websync.subscribeArgs</see> to extend.</param><returns>The callback invoked when a client unsubscribes.</returns>
@function getOnClientUnsubscribe
@param {fm.websync.subscribeArgs} args
@return {fm.singleAction}
*/
subscribeArgsExtensions.getOnClientUnsubscribe = function() {
var args;
args = arguments[0];
return args.getDynamicValue("fm.subscribers.onClientUnsubscribe");
};
/**
@function removeFromChannelsCache