websocket-rails 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/CHANGELOG.md +22 -0
  2. data/Gemfile +4 -0
  3. data/README.md +66 -159
  4. data/Rakefile +31 -4
  5. data/bin/thin-socketrails +16 -1
  6. data/lib/assets/javascripts/websocket_rails/channel.js.coffee +23 -8
  7. data/lib/assets/javascripts/websocket_rails/event.js.coffee +40 -0
  8. data/lib/assets/javascripts/websocket_rails/http_connection.js.coffee +18 -10
  9. data/lib/assets/javascripts/websocket_rails/main.js +1 -0
  10. data/lib/assets/javascripts/websocket_rails/websocket_connection.js.coffee +15 -10
  11. data/lib/assets/javascripts/websocket_rails/websocket_rails.js.coffee +41 -23
  12. data/lib/websocket-rails.rb +4 -4
  13. data/lib/websocket_rails/base_controller.rb +61 -29
  14. data/lib/websocket_rails/channel.rb +14 -5
  15. data/lib/websocket_rails/channel_manager.rb +3 -1
  16. data/lib/websocket_rails/connection_adapters.rb +34 -12
  17. data/lib/websocket_rails/connection_manager.rb +4 -0
  18. data/lib/websocket_rails/dispatcher.rb +27 -3
  19. data/lib/websocket_rails/engine.rb +2 -5
  20. data/lib/websocket_rails/event.rb +87 -42
  21. data/lib/websocket_rails/event_map.rb +70 -20
  22. data/lib/websocket_rails/event_queue.rb +4 -0
  23. data/lib/websocket_rails/internal_events.rb +21 -3
  24. data/lib/websocket_rails/logging.rb +18 -0
  25. data/lib/websocket_rails/version.rb +1 -1
  26. data/spec/dummy/log/test.log +0 -429
  27. data/spec/integration/connection_manager_spec.rb +3 -5
  28. data/spec/javascripts/generated/assets/channel.js +98 -0
  29. data/spec/javascripts/generated/assets/event.js +78 -0
  30. data/spec/javascripts/generated/assets/http_connection.js +108 -0
  31. data/spec/javascripts/generated/assets/websocket_connection.js +66 -0
  32. data/spec/javascripts/generated/assets/websocket_rails.js +180 -0
  33. data/spec/javascripts/generated/specs/channel_spec.js +66 -0
  34. data/spec/javascripts/generated/specs/event_spec.js +107 -0
  35. data/spec/javascripts/generated/specs/websocket_connection_spec.js +117 -0
  36. data/spec/javascripts/generated/specs/websocket_rails_spec.js +232 -0
  37. data/spec/javascripts/support/jasmine.yml +44 -0
  38. data/spec/javascripts/support/jasmine_config.rb +63 -0
  39. data/spec/javascripts/support/vendor/sinon-1.3.4.js +3555 -0
  40. data/spec/javascripts/websocket_rails/channel_spec.coffee +51 -0
  41. data/spec/javascripts/websocket_rails/event_spec.coffee +69 -0
  42. data/spec/javascripts/websocket_rails/websocket_connection_spec.coffee +86 -0
  43. data/spec/javascripts/websocket_rails/websocket_rails_spec.coffee +166 -0
  44. data/spec/support/helper_methods.rb +10 -1
  45. data/spec/unit/channel_spec.rb +28 -4
  46. data/spec/unit/connection_adapters_spec.rb +17 -0
  47. data/spec/unit/connection_manager_spec.rb +1 -1
  48. data/spec/unit/dispatcher_spec.rb +1 -1
  49. data/spec/unit/event_spec.rb +15 -11
  50. metadata +22 -4
@@ -277,432 +277,3 @@ Connecting to database specified by database.yml
277
277
  Connecting to database specified by database.yml
278
278
  Connecting to database specified by database.yml
279
279
  Connecting to database specified by database.yml
280
- Connecting to database specified by database.yml
281
- Connecting to database specified by database.yml
282
- Connecting to database specified by database.yml
283
- Connecting to database specified by database.yml
284
- Connecting to database specified by database.yml
285
- Connecting to database specified by database.yml
286
- Connecting to database specified by database.yml
287
- Connecting to database specified by database.yml
288
- Connecting to database specified by database.yml
289
- Connecting to database specified by database.yml
290
- Connecting to database specified by database.yml
291
- Connecting to database specified by database.yml
292
- Connecting to database specified by database.yml
293
- Connecting to database specified by database.yml
294
- Connecting to database specified by database.yml
295
- Connecting to database specified by database.yml
296
- Connecting to database specified by database.yml
297
- Connecting to database specified by database.yml
298
- Connecting to database specified by database.yml
299
- Connecting to database specified by database.yml
300
- Connecting to database specified by database.yml
301
- Connecting to database specified by database.yml
302
- Connecting to database specified by database.yml
303
- Connecting to database specified by database.yml
304
- Connecting to database specified by database.yml
305
- Connecting to database specified by database.yml
306
- Connecting to database specified by database.yml
307
- Connecting to database specified by database.yml
308
- Connecting to database specified by database.yml
309
- Connecting to database specified by database.yml
310
- Connecting to database specified by database.yml
311
- Connecting to database specified by database.yml
312
- Connecting to database specified by database.yml
313
- Connecting to database specified by database.yml
314
- Connecting to database specified by database.yml
315
- Connecting to database specified by database.yml
316
- Connecting to database specified by database.yml
317
- Connecting to database specified by database.yml
318
- Connecting to database specified by database.yml
319
- Connecting to database specified by database.yml
320
- Connecting to database specified by database.yml
321
- Connecting to database specified by database.yml
322
- Connecting to database specified by database.yml
323
- Connecting to database specified by database.yml
324
- Connecting to database specified by database.yml
325
- Connecting to database specified by database.yml
326
- Connecting to database specified by database.yml
327
- Connecting to database specified by database.yml
328
- Connecting to database specified by database.yml
329
- Connecting to database specified by database.yml
330
- Connecting to database specified by database.yml
331
- Connecting to database specified by database.yml
332
- Connecting to database specified by database.yml
333
- Connecting to database specified by database.yml
334
- Connecting to database specified by database.yml
335
- Connecting to database specified by database.yml
336
- Connecting to database specified by database.yml
337
- Connecting to database specified by database.yml
338
- Connecting to database specified by database.yml
339
- Connecting to database specified by database.yml
340
- Connecting to database specified by database.yml
341
- Connecting to database specified by database.yml
342
- Connecting to database specified by database.yml
343
- Connecting to database specified by database.yml
344
- Connecting to database specified by database.yml
345
- Connecting to database specified by database.yml
346
- Connecting to database specified by database.yml
347
- Connecting to database specified by database.yml
348
- Connecting to database specified by database.yml
349
- Connecting to database specified by database.yml
350
- Connecting to database specified by database.yml
351
- Connecting to database specified by database.yml
352
- Connecting to database specified by database.yml
353
- Connecting to database specified by database.yml
354
- Connecting to database specified by database.yml
355
- Connecting to database specified by database.yml
356
- Connecting to database specified by database.yml
357
- Connecting to database specified by database.yml
358
- Connecting to database specified by database.yml
359
- Connecting to database specified by database.yml
360
- Connecting to database specified by database.yml
361
- Connecting to database specified by database.yml
362
- Connecting to database specified by database.yml
363
- Connecting to database specified by database.yml
364
- Connecting to database specified by database.yml
365
- Connecting to database specified by database.yml
366
- Connecting to database specified by database.yml
367
- Connecting to database specified by database.yml
368
- Connecting to database specified by database.yml
369
- Connecting to database specified by database.yml
370
- Connecting to database specified by database.yml
371
- Connecting to database specified by database.yml
372
- Connecting to database specified by database.yml
373
- Connecting to database specified by database.yml
374
- Connecting to database specified by database.yml
375
- Connecting to database specified by database.yml
376
- Connecting to database specified by database.yml
377
- Connecting to database specified by database.yml
378
- Connecting to database specified by database.yml
379
- Connecting to database specified by database.yml
380
- Connecting to database specified by database.yml
381
- Connecting to database specified by database.yml
382
- Connecting to database specified by database.yml
383
- Connecting to database specified by database.yml
384
- Connecting to database specified by database.yml
385
- Connecting to database specified by database.yml
386
- Connecting to database specified by database.yml
387
- Connecting to database specified by database.yml
388
- Connecting to database specified by database.yml
389
- Connecting to database specified by database.yml
390
- Connecting to database specified by database.yml
391
- Connecting to database specified by database.yml
392
- Connecting to database specified by database.yml
393
- Connecting to database specified by database.yml
394
- Connecting to database specified by database.yml
395
- Connecting to database specified by database.yml
396
- Connecting to database specified by database.yml
397
- Connecting to database specified by database.yml
398
- Connecting to database specified by database.yml
399
- Connecting to database specified by database.yml
400
- Connecting to database specified by database.yml
401
- Connecting to database specified by database.yml
402
- Connecting to database specified by database.yml
403
- Connecting to database specified by database.yml
404
- Connecting to database specified by database.yml
405
- Connecting to database specified by database.yml
406
- Connecting to database specified by database.yml
407
- Connecting to database specified by database.yml
408
- Connecting to database specified by database.yml
409
- Connecting to database specified by database.yml
410
- Connecting to database specified by database.yml
411
- Connecting to database specified by database.yml
412
- Connecting to database specified by database.yml
413
- Connecting to database specified by database.yml
414
- Connecting to database specified by database.yml
415
- Connecting to database specified by database.yml
416
- Connecting to database specified by database.yml
417
- Connecting to database specified by database.yml
418
- Connecting to database specified by database.yml
419
- Connecting to database specified by database.yml
420
- Connecting to database specified by database.yml
421
- Connecting to database specified by database.yml
422
- Connecting to database specified by database.yml
423
- Connecting to database specified by database.yml
424
- Connecting to database specified by database.yml
425
- Connecting to database specified by database.yml
426
- Connecting to database specified by database.yml
427
- Connecting to database specified by database.yml
428
- Connecting to database specified by database.yml
429
- Connecting to database specified by database.yml
430
- Connecting to database specified by database.yml
431
- Connecting to database specified by database.yml
432
- Connecting to database specified by database.yml
433
- Connecting to database specified by database.yml
434
- Connecting to database specified by database.yml
435
- Connecting to database specified by database.yml
436
- Connecting to database specified by database.yml
437
- Connecting to database specified by database.yml
438
- Connecting to database specified by database.yml
439
- Connecting to database specified by database.yml
440
- Connecting to database specified by database.yml
441
- Connecting to database specified by database.yml
442
- Connecting to database specified by database.yml
443
- Connecting to database specified by database.yml
444
- Connecting to database specified by database.yml
445
- Connecting to database specified by database.yml
446
- Connecting to database specified by database.yml
447
- Connecting to database specified by database.yml
448
- Connecting to database specified by database.yml
449
- Connecting to database specified by database.yml
450
- Connecting to database specified by database.yml
451
- Connecting to database specified by database.yml
452
- Connecting to database specified by database.yml
453
- Connecting to database specified by database.yml
454
- Connecting to database specified by database.yml
455
- Connecting to database specified by database.yml
456
- Connecting to database specified by database.yml
457
- Connecting to database specified by database.yml
458
- Connecting to database specified by database.yml
459
- Connecting to database specified by database.yml
460
- Connecting to database specified by database.yml
461
- Connecting to database specified by database.yml
462
- Connecting to database specified by database.yml
463
- Connecting to database specified by database.yml
464
- Connecting to database specified by database.yml
465
- Connecting to database specified by database.yml
466
- Connecting to database specified by database.yml
467
- Connecting to database specified by database.yml
468
- Connecting to database specified by database.yml
469
- Connecting to database specified by database.yml
470
- Connecting to database specified by database.yml
471
- Connecting to database specified by database.yml
472
- Connecting to database specified by database.yml
473
- Connecting to database specified by database.yml
474
- Connecting to database specified by database.yml
475
- Connecting to database specified by database.yml
476
- Connecting to database specified by database.yml
477
- Connecting to database specified by database.yml
478
- Connecting to database specified by database.yml
479
- Connecting to database specified by database.yml
480
- Connecting to database specified by database.yml
481
- Connecting to database specified by database.yml
482
- Connecting to database specified by database.yml
483
- Connecting to database specified by database.yml
484
- Connecting to database specified by database.yml
485
- Connecting to database specified by database.yml
486
- Connecting to database specified by database.yml
487
- Connecting to database specified by database.yml
488
- Connecting to database specified by database.yml
489
- Connecting to database specified by database.yml
490
- Connecting to database specified by database.yml
491
- Connecting to database specified by database.yml
492
- Connecting to database specified by database.yml
493
- Connecting to database specified by database.yml
494
- Connecting to database specified by database.yml
495
- Connecting to database specified by database.yml
496
- Connecting to database specified by database.yml
497
- Connecting to database specified by database.yml
498
- Connecting to database specified by database.yml
499
- Connecting to database specified by database.yml
500
- Connecting to database specified by database.yml
501
- Connecting to database specified by database.yml
502
- Connecting to database specified by database.yml
503
- Connecting to database specified by database.yml
504
- Connecting to database specified by database.yml
505
- Connecting to database specified by database.yml
506
- Connecting to database specified by database.yml
507
- Connecting to database specified by database.yml
508
- Connecting to database specified by database.yml
509
- Connecting to database specified by database.yml
510
- Connecting to database specified by database.yml
511
- Connecting to database specified by database.yml
512
- Connecting to database specified by database.yml
513
- Connecting to database specified by database.yml
514
- Connecting to database specified by database.yml
515
- Connecting to database specified by database.yml
516
- Connecting to database specified by database.yml
517
- Connecting to database specified by database.yml
518
- Connecting to database specified by database.yml
519
- Connecting to database specified by database.yml
520
- Connecting to database specified by database.yml
521
- Connecting to database specified by database.yml
522
- Connecting to database specified by database.yml
523
- Connecting to database specified by database.yml
524
- Connecting to database specified by database.yml
525
- Connecting to database specified by database.yml
526
- Connecting to database specified by database.yml
527
- Connecting to database specified by database.yml
528
- Connecting to database specified by database.yml
529
- Connecting to database specified by database.yml
530
- Connecting to database specified by database.yml
531
- Connecting to database specified by database.yml
532
- Connecting to database specified by database.yml
533
- Connecting to database specified by database.yml
534
- Connecting to database specified by database.yml
535
- Connecting to database specified by database.yml
536
- Connecting to database specified by database.yml
537
- Connecting to database specified by database.yml
538
- Connecting to database specified by database.yml
539
- Connecting to database specified by database.yml
540
- Connecting to database specified by database.yml
541
- Connecting to database specified by database.yml
542
- Connecting to database specified by database.yml
543
- Connecting to database specified by database.yml
544
- Connecting to database specified by database.yml
545
- Connecting to database specified by database.yml
546
- Connecting to database specified by database.yml
547
- Connecting to database specified by database.yml
548
- Connecting to database specified by database.yml
549
- Connecting to database specified by database.yml
550
- Connecting to database specified by database.yml
551
- Connecting to database specified by database.yml
552
- Connecting to database specified by database.yml
553
- Connecting to database specified by database.yml
554
- Connecting to database specified by database.yml
555
- Connecting to database specified by database.yml
556
- Connecting to database specified by database.yml
557
- Connecting to database specified by database.yml
558
- Connecting to database specified by database.yml
559
- Connecting to database specified by database.yml
560
- Connecting to database specified by database.yml
561
- Connecting to database specified by database.yml
562
- Connecting to database specified by database.yml
563
- Connecting to database specified by database.yml
564
- Connecting to database specified by database.yml
565
- Connecting to database specified by database.yml
566
- Connecting to database specified by database.yml
567
- Connecting to database specified by database.yml
568
- Connecting to database specified by database.yml
569
- Connecting to database specified by database.yml
570
- Connecting to database specified by database.yml
571
- Connecting to database specified by database.yml
572
- Connecting to database specified by database.yml
573
- Connecting to database specified by database.yml
574
- Connecting to database specified by database.yml
575
- Connecting to database specified by database.yml
576
- Connecting to database specified by database.yml
577
- Connecting to database specified by database.yml
578
- Connecting to database specified by database.yml
579
- Connecting to database specified by database.yml
580
- Connecting to database specified by database.yml
581
- Connecting to database specified by database.yml
582
- Connecting to database specified by database.yml
583
- Connecting to database specified by database.yml
584
- Connecting to database specified by database.yml
585
- Connecting to database specified by database.yml
586
- Connecting to database specified by database.yml
587
- Connecting to database specified by database.yml
588
- Connecting to database specified by database.yml
589
- Connecting to database specified by database.yml
590
- Connecting to database specified by database.yml
591
- Connecting to database specified by database.yml
592
- Connecting to database specified by database.yml
593
- Connecting to database specified by database.yml
594
- Connecting to database specified by database.yml
595
- Connecting to database specified by database.yml
596
- Connecting to database specified by database.yml
597
- Connecting to database specified by database.yml
598
- Connecting to database specified by database.yml
599
- Connecting to database specified by database.yml
600
- Connecting to database specified by database.yml
601
- Connecting to database specified by database.yml
602
- Connecting to database specified by database.yml
603
- Connecting to database specified by database.yml
604
- Connecting to database specified by database.yml
605
- Connecting to database specified by database.yml
606
- Connecting to database specified by database.yml
607
- Connecting to database specified by database.yml
608
- Connecting to database specified by database.yml
609
- Connecting to database specified by database.yml
610
- Connecting to database specified by database.yml
611
- Connecting to database specified by database.yml
612
- Connecting to database specified by database.yml
613
- Connecting to database specified by database.yml
614
- Connecting to database specified by database.yml
615
- Connecting to database specified by database.yml
616
- Connecting to database specified by database.yml
617
- Connecting to database specified by database.yml
618
- Connecting to database specified by database.yml
619
- Connecting to database specified by database.yml
620
- Connecting to database specified by database.yml
621
- Connecting to database specified by database.yml
622
- Connecting to database specified by database.yml
623
- Connecting to database specified by database.yml
624
- Connecting to database specified by database.yml
625
- Connecting to database specified by database.yml
626
- Connecting to database specified by database.yml
627
- Connecting to database specified by database.yml
628
- Connecting to database specified by database.yml
629
- Connecting to database specified by database.yml
630
- Connecting to database specified by database.yml
631
- Connecting to database specified by database.yml
632
- Connecting to database specified by database.yml
633
- Connecting to database specified by database.yml
634
- Connecting to database specified by database.yml
635
- Connecting to database specified by database.yml
636
- Connecting to database specified by database.yml
637
- Connecting to database specified by database.yml
638
- Connecting to database specified by database.yml
639
- Connecting to database specified by database.yml
640
- Connecting to database specified by database.yml
641
- Connecting to database specified by database.yml
642
- Connecting to database specified by database.yml
643
- Connecting to database specified by database.yml
644
- Connecting to database specified by database.yml
645
- Connecting to database specified by database.yml
646
- Connecting to database specified by database.yml
647
- Connecting to database specified by database.yml
648
- Connecting to database specified by database.yml
649
- Connecting to database specified by database.yml
650
- Connecting to database specified by database.yml
651
- Connecting to database specified by database.yml
652
- Connecting to database specified by database.yml
653
- Connecting to database specified by database.yml
654
- Connecting to database specified by database.yml
655
- Connecting to database specified by database.yml
656
- Connecting to database specified by database.yml
657
- Connecting to database specified by database.yml
658
- Connecting to database specified by database.yml
659
- Connecting to database specified by database.yml
660
- Connecting to database specified by database.yml
661
- Connecting to database specified by database.yml
662
- Connecting to database specified by database.yml
663
- Connecting to database specified by database.yml
664
- Connecting to database specified by database.yml
665
- Connecting to database specified by database.yml
666
- Connecting to database specified by database.yml
667
- Connecting to database specified by database.yml
668
- Connecting to database specified by database.yml
669
- Connecting to database specified by database.yml
670
- Connecting to database specified by database.yml
671
- Connecting to database specified by database.yml
672
- Connecting to database specified by database.yml
673
- Connecting to database specified by database.yml
674
- Connecting to database specified by database.yml
675
- Connecting to database specified by database.yml
676
- Connecting to database specified by database.yml
677
- Connecting to database specified by database.yml
678
- Connecting to database specified by database.yml
679
- Connecting to database specified by database.yml
680
- Connecting to database specified by database.yml
681
- Connecting to database specified by database.yml
682
- Connecting to database specified by database.yml
683
- Connecting to database specified by database.yml
684
- Connecting to database specified by database.yml
685
- Connecting to database specified by database.yml
686
- Connecting to database specified by database.yml
687
- Connecting to database specified by database.yml
688
- Connecting to database specified by database.yml
689
- Connecting to database specified by database.yml
690
- Connecting to database specified by database.yml
691
- Connecting to database specified by database.yml
692
- Connecting to database specified by database.yml
693
- Connecting to database specified by database.yml
694
- Connecting to database specified by database.yml
695
- Connecting to database specified by database.yml
696
- Connecting to database specified by database.yml
697
- Connecting to database specified by database.yml
698
- Connecting to database specified by database.yml
699
- Connecting to database specified by database.yml
700
- Connecting to database specified by database.yml
701
- Connecting to database specified by database.yml
702
- Connecting to database specified by database.yml
703
- Connecting to database specified by database.yml
704
- Connecting to database specified by database.yml
705
- Connecting to database specified by database.yml
706
- Connecting to database specified by database.yml
707
- Connecting to database specified by database.yml
708
- Connecting to database specified by database.yml
@@ -64,15 +64,14 @@ module WebsocketRails
64
64
  end
65
65
 
66
66
  context "subscribing to a channel" do
67
- let(:channel_message) { ['websocket_rails.subscribe',{:channel => 'awesome_channel'}] }
68
- let(:encoded_message) { channel_message.to_json }
67
+ let(:channel_message) { ['websocket_rails.subscribe',{:data => { :channel => 'awesome_channel'}}] }
68
+ let(:encoded_channel_message) { channel_message.to_json }
69
69
 
70
70
  it "should subscribe the connection to the correct channel" do
71
71
  @server.call( env )
72
72
  channel = WebsocketRails[:awesome_channel]
73
73
  channel.should_receive(:subscribe).once.with(socket)
74
- Channel.any_instance.stub(:subscribe).and_raise(Exception)
75
- socket.on_message encoded_message
74
+ socket.on_message encoded_channel_message
76
75
  end
77
76
  end
78
77
 
@@ -99,7 +98,6 @@ module WebsocketRails
99
98
 
100
99
  before do
101
100
  ::Faye::WebSocket.stub(:websocket?).and_return(true)
102
- ::Faye::WebSocket.stub(:new).and_return(MockWebSocket.new)
103
101
  @server = ConnectionManager.new
104
102
  end
105
103
 
@@ -0,0 +1,98 @@
1
+
2
+ /*
3
+ The channel object is returned when you subscribe to a channel.
4
+
5
+ For instance:
6
+ var dispatcher = new WebSocketRails('localhost:3000/websocket');
7
+ var awesome_channel = dispatcher.subscribe('awesome_channel');
8
+ awesome_channel.bind('event', function(data) { console.log('channel event!'); });
9
+ awesome_channel.trigger('awesome_event', awesome_object);
10
+ */
11
+
12
+
13
+ (function() {
14
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
15
+
16
+ WebSocketRails.Channel = (function() {
17
+
18
+ function Channel(name, _dispatcher, is_private) {
19
+ var event, event_name;
20
+ this.name = name;
21
+ this._dispatcher = _dispatcher;
22
+ this.is_private = is_private;
23
+ this._failure_launcher = __bind(this._failure_launcher, this);
24
+
25
+ this._success_launcher = __bind(this._success_launcher, this);
26
+
27
+ this.dispatch = __bind(this.dispatch, this);
28
+
29
+ this.trigger = __bind(this.trigger, this);
30
+
31
+ this.bind = __bind(this.bind, this);
32
+
33
+ if (this.is_private) {
34
+ event_name = 'websocket_rails.subscribe_private';
35
+ } else {
36
+ event_name = 'websocket_rails.subscribe';
37
+ }
38
+ event = new WebSocketRails.Event([
39
+ event_name, {
40
+ data: {
41
+ channel: this.name
42
+ }
43
+ }, this._dispatcher.connection_id
44
+ ], this._success_launcher, this._failure_launcher);
45
+ this._dispatcher.trigger_event(event);
46
+ this._callbacks = {};
47
+ }
48
+
49
+ Channel.prototype.bind = function(event_name, callback) {
50
+ var _base, _ref;
51
+ if ((_ref = (_base = this._callbacks)[event_name]) == null) {
52
+ _base[event_name] = [];
53
+ }
54
+ return this._callbacks[event_name].push(callback);
55
+ };
56
+
57
+ Channel.prototype.trigger = function(event_name, message) {
58
+ var event;
59
+ event = new WebSocketRails.Event([
60
+ event_name, {
61
+ channel: this.name,
62
+ data: message
63
+ }, this._dispatcher.connection_id
64
+ ]);
65
+ return this._dispatcher.trigger_event(event);
66
+ };
67
+
68
+ Channel.prototype.dispatch = function(event_name, message) {
69
+ var callback, _i, _len, _ref, _results;
70
+ if (this._callbacks[event_name] == null) {
71
+ return;
72
+ }
73
+ _ref = this._callbacks[event_name];
74
+ _results = [];
75
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
76
+ callback = _ref[_i];
77
+ _results.push(callback(message));
78
+ }
79
+ return _results;
80
+ };
81
+
82
+ Channel.prototype._success_launcher = function(data) {
83
+ if (this.on_success != null) {
84
+ return this.on_success(data);
85
+ }
86
+ };
87
+
88
+ Channel.prototype._failure_launcher = function(data) {
89
+ if (this.on_failure != null) {
90
+ return this.on_failure(data);
91
+ }
92
+ };
93
+
94
+ return Channel;
95
+
96
+ })();
97
+
98
+ }).call(this);
@@ -0,0 +1,78 @@
1
+
2
+ /*
3
+ The Event object stores all the relevant event information.
4
+ */
5
+
6
+
7
+ (function() {
8
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
9
+
10
+ WebSocketRails.Event = (function() {
11
+
12
+ function Event(data, success_callback, failure_callback) {
13
+ var attr;
14
+ this.success_callback = success_callback;
15
+ this.failure_callback = failure_callback;
16
+ this.run_callbacks = __bind(this.run_callbacks, this);
17
+
18
+ this.attributes = __bind(this.attributes, this);
19
+
20
+ this.serialize = __bind(this.serialize, this);
21
+
22
+ this.is_ping = __bind(this.is_ping, this);
23
+
24
+ this.is_result = __bind(this.is_result, this);
25
+
26
+ this.is_channel = __bind(this.is_channel, this);
27
+
28
+ this.name = data[0];
29
+ attr = data[1];
30
+ if (attr != null) {
31
+ this.id = attr['id'] != null ? attr['id'] : ((1 + Math.random()) * 0x10000) | 0;
32
+ this.channel = attr.channel != null ? attr.channel : void 0;
33
+ this.data = attr.data != null ? attr.data : attr;
34
+ this.connection_id = data[2];
35
+ if (attr.success != null) {
36
+ this.result = true;
37
+ this.success = attr.success;
38
+ }
39
+ }
40
+ }
41
+
42
+ Event.prototype.is_channel = function() {
43
+ return this.channel != null;
44
+ };
45
+
46
+ Event.prototype.is_result = function() {
47
+ return this.result === true;
48
+ };
49
+
50
+ Event.prototype.is_ping = function() {
51
+ return this.name === 'websocket_rails.ping';
52
+ };
53
+
54
+ Event.prototype.serialize = function() {
55
+ return JSON.stringify([this.name, this.attributes()]);
56
+ };
57
+
58
+ Event.prototype.attributes = function() {
59
+ return {
60
+ id: this.id,
61
+ channel: this.channel,
62
+ data: this.data
63
+ };
64
+ };
65
+
66
+ Event.prototype.run_callbacks = function(success, data) {
67
+ if (success === true) {
68
+ return typeof this.success_callback === "function" ? this.success_callback(data) : void 0;
69
+ } else {
70
+ return typeof this.failure_callback === "function" ? this.failure_callback(data) : void 0;
71
+ }
72
+ };
73
+
74
+ return Event;
75
+
76
+ })();
77
+
78
+ }).call(this);