websocket-rails-js 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/Gemfile +11 -0
  4. data/Guardfile +6 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +13 -0
  7. data/Rakefile +36 -0
  8. data/app/assets/javascripts/websocket_rails/abstract_connection.js.coffee +45 -0
  9. data/app/assets/javascripts/websocket_rails/channel.js.coffee +66 -0
  10. data/app/assets/javascripts/websocket_rails/connection.js.coffee +62 -0
  11. data/app/assets/javascripts/websocket_rails/event.js.coffee +43 -0
  12. data/app/assets/javascripts/websocket_rails/http_connection.js.coffee +56 -0
  13. data/app/assets/javascripts/websocket_rails/main.js +6 -0
  14. data/app/assets/javascripts/websocket_rails/websocket_connection.js.coffee +29 -0
  15. data/app/assets/javascripts/websocket_rails/websocket_rails.js.coffee +148 -0
  16. data/lib/websocket-rails-js.rb +1 -0
  17. data/lib/websocket_rails/js/engine.rb +8 -0
  18. data/lib/websocket_rails/js/version.rb +5 -0
  19. data/spec/javascripts/helpers/.gitkeep +0 -0
  20. data/spec/javascripts/helpers/helpers.coffee +7 -0
  21. data/spec/javascripts/support/jasmine.yml +139 -0
  22. data/spec/javascripts/support/jasmine_helper.rb +15 -0
  23. data/spec/javascripts/support/jquery.min.js +4 -0
  24. data/spec/javascripts/support/sinon-1.7.1.js +4343 -0
  25. data/spec/javascripts/websocket_rails/channel_spec.js.coffee +99 -0
  26. data/spec/javascripts/websocket_rails/connection_spec.js.coffee +136 -0
  27. data/spec/javascripts/websocket_rails/event_spec.js.coffee +70 -0
  28. data/spec/javascripts/websocket_rails/helpers.js.coffee +7 -0
  29. data/spec/javascripts/websocket_rails/websocket_rails_spec.js.coffee +233 -0
  30. data/src/websocket_rails/abstract_connection.js +71 -0
  31. data/src/websocket_rails/channel.js +133 -0
  32. data/src/websocket_rails/connection.js +91 -0
  33. data/src/websocket_rails/event.js +66 -0
  34. data/src/websocket_rails/http_connection.js +97 -0
  35. data/src/websocket_rails/websocket_connection.js +59 -0
  36. data/src/websocket_rails/websocket_rails.js +218 -0
  37. data/websocket-rails-js.gemspec +25 -0
  38. data/websocket_rails.0.0.1.min.js +1 -0
  39. metadata +135 -0
@@ -0,0 +1,59 @@
1
+
2
+ /*
3
+ WebSocket Interface for the WebSocketRails client.
4
+ */
5
+
6
+ (function() {
7
+ var __hasProp = {}.hasOwnProperty,
8
+ __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; };
9
+
10
+ WebSocketRails.WebSocketConnection = (function(_super) {
11
+ __extends(WebSocketConnection, _super);
12
+
13
+ WebSocketConnection.prototype.connection_type = 'websocket';
14
+
15
+ function WebSocketConnection(url, dispatcher) {
16
+ this.url = url;
17
+ this.dispatcher = dispatcher;
18
+ WebSocketConnection.__super__.constructor.apply(this, arguments);
19
+ if (this.url.match(/^wss?:\/\//)) {
20
+ console.log("WARNING: Using connection urls with protocol specified is depricated");
21
+ } else if (window.location.protocol === 'https:') {
22
+ this.url = "wss://" + this.url;
23
+ } else {
24
+ this.url = "ws://" + this.url;
25
+ }
26
+ this._conn = new WebSocket(this.url);
27
+ this._conn.onmessage = (function(_this) {
28
+ return function(event) {
29
+ var event_data;
30
+ event_data = JSON.parse(event.data);
31
+ return _this.on_message(event_data);
32
+ };
33
+ })(this);
34
+ this._conn.onclose = (function(_this) {
35
+ return function(event) {
36
+ return _this.on_close(event);
37
+ };
38
+ })(this);
39
+ this._conn.onerror = (function(_this) {
40
+ return function(event) {
41
+ return _this.on_error(event);
42
+ };
43
+ })(this);
44
+ }
45
+
46
+ WebSocketConnection.prototype.close = function() {
47
+ return this._conn.close();
48
+ };
49
+
50
+ WebSocketConnection.prototype.send_event = function(event) {
51
+ WebSocketConnection.__super__.send_event.apply(this, arguments);
52
+ return this._conn.send(event.serialize());
53
+ };
54
+
55
+ return WebSocketConnection;
56
+
57
+ })(WebSocketRails.AbstractConnection);
58
+
59
+ }).call(this);
@@ -0,0 +1,218 @@
1
+
2
+ /*
3
+ WebsocketRails JavaScript Client
4
+
5
+ Setting up the dispatcher:
6
+ var dispatcher = new WebSocketRails('localhost:3000/websocket');
7
+ dispatcher.on_open = function() {
8
+ // trigger a server event immediately after opening connection
9
+ dispatcher.trigger('new_user',{user_name: 'guest'});
10
+ })
11
+
12
+ Triggering a new event on the server
13
+ dispatcherer.trigger('event_name',object_to_be_serialized_to_json);
14
+
15
+ Listening for new events from the server
16
+ dispatcher.bind('event_name', function(data) {
17
+ console.log(data.user_name);
18
+ });
19
+
20
+ Stop listening for new events from the server
21
+ dispatcher.unbind('event')
22
+ */
23
+
24
+ (function() {
25
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
26
+
27
+ this.WebSocketRails = (function() {
28
+ function WebSocketRails(url, use_websockets) {
29
+ this.url = url;
30
+ this.use_websockets = use_websockets != null ? use_websockets : true;
31
+ this.connection_stale = __bind(this.connection_stale, this);
32
+ this.supports_websockets = __bind(this.supports_websockets, this);
33
+ this.dispatch_channel = __bind(this.dispatch_channel, this);
34
+ this.unsubscribe = __bind(this.unsubscribe, this);
35
+ this.subscribe_private = __bind(this.subscribe_private, this);
36
+ this.subscribe = __bind(this.subscribe, this);
37
+ this.dispatch = __bind(this.dispatch, this);
38
+ this.trigger_event = __bind(this.trigger_event, this);
39
+ this.trigger = __bind(this.trigger, this);
40
+ this.bind = __bind(this.bind, this);
41
+ this.connection_established = __bind(this.connection_established, this);
42
+ this.new_message = __bind(this.new_message, this);
43
+ this.reconnect = __bind(this.reconnect, this);
44
+ this.callbacks = {};
45
+ this.channels = {};
46
+ this.queue = {};
47
+ this.connect();
48
+ }
49
+
50
+ WebSocketRails.prototype.connect = function() {
51
+ this.state = 'connecting';
52
+ if (!(this.supports_websockets() && this.use_websockets)) {
53
+ this._conn = new WebSocketRails.HttpConnection(this.url, this);
54
+ } else {
55
+ this._conn = new WebSocketRails.WebSocketConnection(this.url, this);
56
+ }
57
+ return this._conn.new_message = this.new_message;
58
+ };
59
+
60
+ WebSocketRails.prototype.disconnect = function() {
61
+ if (this._conn) {
62
+ this._conn.close();
63
+ delete this._conn._conn;
64
+ delete this._conn;
65
+ }
66
+ return this.state = 'disconnected';
67
+ };
68
+
69
+ WebSocketRails.prototype.reconnect = function() {
70
+ var event, id, old_connection_id, _ref, _ref1;
71
+ old_connection_id = (_ref = this._conn) != null ? _ref.connection_id : void 0;
72
+ this.disconnect();
73
+ this.connect();
74
+ _ref1 = this.queue;
75
+ for (id in _ref1) {
76
+ event = _ref1[id];
77
+ if (event.connection_id === old_connection_id && !event.is_result()) {
78
+ this.trigger_event(event);
79
+ }
80
+ }
81
+ return this.reconnect_channels();
82
+ };
83
+
84
+ WebSocketRails.prototype.new_message = function(data) {
85
+ var event, _ref;
86
+ event = new WebSocketRails.Event(data);
87
+ if (event.is_result()) {
88
+ if ((_ref = this.queue[event.id]) != null) {
89
+ _ref.run_callbacks(event.success, event.data);
90
+ }
91
+ this.queue[event.id] = null;
92
+ } else if (event.is_channel()) {
93
+ this.dispatch_channel(event);
94
+ } else {
95
+ this.dispatch(event);
96
+ }
97
+ if (this.state === 'connecting' && event.name === 'client_connected') {
98
+ return this.connection_established(event);
99
+ }
100
+ };
101
+
102
+ WebSocketRails.prototype.connection_established = function(event) {
103
+ this.state = 'connected';
104
+ this._conn.setConnectionId(event.connection_id);
105
+ this._conn.flush_queue();
106
+ if (this.on_open != null) {
107
+ return this.on_open(event.data);
108
+ }
109
+ };
110
+
111
+ WebSocketRails.prototype.bind = function(event_name, callback) {
112
+ var _base;
113
+ if ((_base = this.callbacks)[event_name] == null) {
114
+ _base[event_name] = [];
115
+ }
116
+ return this.callbacks[event_name].push(callback);
117
+ };
118
+
119
+ WebSocketRails.prototype.trigger = function(event_name, data, success_callback, failure_callback) {
120
+ var event;
121
+ event = new WebSocketRails.Event([
122
+ event_name, data, {
123
+ connection_id: this.connection_id
124
+ }
125
+ ], success_callback, failure_callback);
126
+ this.queue[event.id] = event;
127
+ return this._conn.trigger(event);
128
+ };
129
+
130
+ WebSocketRails.prototype.trigger_event = function(event) {
131
+ var _base, _name;
132
+ if ((_base = this.queue)[_name = event.id] == null) {
133
+ _base[_name] = event;
134
+ }
135
+ this._conn.trigger(event);
136
+ return event;
137
+ };
138
+
139
+ WebSocketRails.prototype.dispatch = function(event) {
140
+ var callback, _i, _len, _ref, _results;
141
+ if (this.callbacks[event.name] == null) {
142
+ return;
143
+ }
144
+ _ref = this.callbacks[event.name];
145
+ _results = [];
146
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
147
+ callback = _ref[_i];
148
+ _results.push(callback(event.data));
149
+ }
150
+ return _results;
151
+ };
152
+
153
+ WebSocketRails.prototype.subscribe = function(channel_name, success_callback, failure_callback) {
154
+ var channel;
155
+ if (this.channels[channel_name] == null) {
156
+ channel = new WebSocketRails.Channel(channel_name, this, false, success_callback, failure_callback);
157
+ this.channels[channel_name] = channel;
158
+ return channel;
159
+ } else {
160
+ return this.channels[channel_name];
161
+ }
162
+ };
163
+
164
+ WebSocketRails.prototype.subscribe_private = function(channel_name, success_callback, failure_callback) {
165
+ var channel;
166
+ if (this.channels[channel_name] == null) {
167
+ channel = new WebSocketRails.Channel(channel_name, this, true, success_callback, failure_callback);
168
+ this.channels[channel_name] = channel;
169
+ return channel;
170
+ } else {
171
+ return this.channels[channel_name];
172
+ }
173
+ };
174
+
175
+ WebSocketRails.prototype.unsubscribe = function(channel_name) {
176
+ if (this.channels[channel_name] == null) {
177
+ return;
178
+ }
179
+ this.channels[channel_name].destroy();
180
+ return delete this.channels[channel_name];
181
+ };
182
+
183
+ WebSocketRails.prototype.dispatch_channel = function(event) {
184
+ if (this.channels[event.channel] == null) {
185
+ return;
186
+ }
187
+ return this.channels[event.channel].dispatch(event.name, event.data);
188
+ };
189
+
190
+ WebSocketRails.prototype.supports_websockets = function() {
191
+ return typeof WebSocket === "function" || typeof WebSocket === "object";
192
+ };
193
+
194
+ WebSocketRails.prototype.connection_stale = function() {
195
+ return this.state !== 'connected';
196
+ };
197
+
198
+ WebSocketRails.prototype.reconnect_channels = function() {
199
+ var callbacks, channel, name, _ref, _results;
200
+ _ref = this.channels;
201
+ _results = [];
202
+ for (name in _ref) {
203
+ channel = _ref[name];
204
+ callbacks = channel._callbacks;
205
+ channel.destroy();
206
+ delete this.channels[name];
207
+ channel = channel.is_private ? this.subscribe_private(name) : this.subscribe(name);
208
+ channel._callbacks = callbacks;
209
+ _results.push(channel);
210
+ }
211
+ return _results;
212
+ };
213
+
214
+ return WebSocketRails;
215
+
216
+ })();
217
+
218
+ }).call(this);
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'websocket_rails/js/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "websocket-rails-js"
8
+ spec.version = WebsocketRails::Js::VERSION
9
+ spec.authors = ["Dan Knox", "Rory Low"]
10
+ spec.email = ["dknox@threedotloft.com"]
11
+ spec.summary = %q{JavaScript client for websocket-rails.}
12
+ spec.description = %q{JavaScript client for websocket-rails.}
13
+ spec.homepage = "http://websocket-rails.github.io"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "rails"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1 @@
1
+ (function(){var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}};this.WebSocketRails=function(){function WebSocketRails(url,use_websockets){this.url=url,this.use_websockets=null!=use_websockets?use_websockets:!0,this.connection_stale=__bind(this.connection_stale,this),this.pong=__bind(this.pong,this),this.supports_websockets=__bind(this.supports_websockets,this),this.dispatch_channel=__bind(this.dispatch_channel,this),this.unsubscribe=__bind(this.unsubscribe,this),this.subscribe_private=__bind(this.subscribe_private,this),this.subscribe=__bind(this.subscribe,this),this.dispatch=__bind(this.dispatch,this),this.trigger_event=__bind(this.trigger_event,this),this.trigger=__bind(this.trigger,this),this.unbind=__bind(this.unbind,this),this.bind=__bind(this.bind,this),this.connection_established=__bind(this.connection_established,this),this.new_message=__bind(this.new_message,this),this.reconnect=__bind(this.reconnect,this),this.callbacks={},this.channels={},this.queue={},this.connect()}return WebSocketRails.prototype.connect=function(){return this.state="connecting",this._conn=this.supports_websockets()&&this.use_websockets?new WebSocketRails.WebSocketConnection(this.url,this):new WebSocketRails.HttpConnection(this.url,this),this._conn.new_message=this.new_message},WebSocketRails.prototype.disconnect=function(){return this._conn&&(this._conn.close(),delete this._conn._conn,delete this._conn),this.state="disconnected"},WebSocketRails.prototype.reconnect=function(){var event,id,old_connection_id,_ref,_ref1;old_connection_id=null!=(_ref=this._conn)?_ref.connection_id:void 0,this.disconnect(),this.connect(),_ref1=this.queue;for(id in _ref1)event=_ref1[id],event.connection_id!==old_connection_id||event.is_result()||this.trigger_event(event);return this.reconnect_channels()},WebSocketRails.prototype.new_message=function(data){var event,socket_message,_i,_len,_ref,_results;for(_results=[],_i=0,_len=data.length;_len>_i;_i++)socket_message=data[_i],event=new WebSocketRails.Event(socket_message),event.is_result()?(null!=(_ref=this.queue[event.id])&&_ref.run_callbacks(event.success,event.data),delete this.queue[event.id]):event.is_channel()?this.dispatch_channel(event):event.is_ping()?this.pong():this.dispatch(event),_results.push("connecting"===this.state&&"client_connected"===event.name?this.connection_established(event.data):void 0);return _results},WebSocketRails.prototype.connection_established=function(data){return this.state="connected",this._conn.setConnectionId(data.connection_id),this._conn.flush_queue(),null!=this.on_open?this.on_open(data):void 0},WebSocketRails.prototype.bind=function(event_name,callback){var _base;return null==(_base=this.callbacks)[event_name]&&(_base[event_name]=[]),this.callbacks[event_name].push(callback)},WebSocketRails.prototype.unbind=function(event_name){return delete this.callbacks[event_name]},WebSocketRails.prototype.trigger=function(event_name,data,success_callback,failure_callback){var event,_ref;return event=new WebSocketRails.Event([event_name,data,null!=(_ref=this._conn)?_ref.connection_id:void 0],success_callback,failure_callback),this.trigger_event(event)},WebSocketRails.prototype.trigger_event=function(event){var _base,_name;return null==(_base=this.queue)[_name=event.id]&&(_base[_name]=event),this._conn&&this._conn.trigger(event),event},WebSocketRails.prototype.dispatch=function(event){var callback,_i,_len,_ref,_results;if(null!=this.callbacks[event.name]){for(_ref=this.callbacks[event.name],_results=[],_i=0,_len=_ref.length;_len>_i;_i++)callback=_ref[_i],_results.push(callback(event.data));return _results}},WebSocketRails.prototype.subscribe=function(channel_name,success_callback,failure_callback){var channel;return null==this.channels[channel_name]?(channel=new WebSocketRails.Channel(channel_name,this,!1,success_callback,failure_callback),this.channels[channel_name]=channel,channel):this.channels[channel_name]},WebSocketRails.prototype.subscribe_private=function(channel_name,success_callback,failure_callback){var channel;return null==this.channels[channel_name]?(channel=new WebSocketRails.Channel(channel_name,this,!0,success_callback,failure_callback),this.channels[channel_name]=channel,channel):this.channels[channel_name]},WebSocketRails.prototype.unsubscribe=function(channel_name){return null!=this.channels[channel_name]?(this.channels[channel_name].destroy(),delete this.channels[channel_name]):void 0},WebSocketRails.prototype.dispatch_channel=function(event){return null!=this.channels[event.channel]?this.channels[event.channel].dispatch(event.name,event.data):void 0},WebSocketRails.prototype.supports_websockets=function(){return"function"==typeof WebSocket||"object"==typeof WebSocket},WebSocketRails.prototype.pong=function(){var pong,_ref;return pong=new WebSocketRails.Event(["websocket_rails.pong",{},null!=(_ref=this._conn)?_ref.connection_id:void 0]),this._conn.trigger(pong)},WebSocketRails.prototype.connection_stale=function(){return"connected"!==this.state},WebSocketRails.prototype.reconnect_channels=function(){var callbacks,channel,name,_ref,_results;_ref=this.channels,_results=[];for(name in _ref)channel=_ref[name],callbacks=channel._callbacks,channel.destroy(),delete this.channels[name],channel=channel.is_private?this.subscribe_private(name):this.subscribe(name),channel._callbacks=callbacks,_results.push(channel);return _results},WebSocketRails}()}).call(this),function(){WebSocketRails.Event=function(){function Event(data,success_callback,failure_callback){var attr;this.success_callback=success_callback,this.failure_callback=failure_callback,this.name=data[0],attr=data[1],null!=attr&&(this.id=null!=attr.id?attr.id:65536*(1+Math.random())|0,this.channel=null!=attr.channel?attr.channel:void 0,this.data=null!=attr.data?attr.data:attr,this.token=null!=attr.token?attr.token:void 0,this.connection_id=data[2],null!=attr.success&&(this.result=!0,this.success=attr.success))}return Event.prototype.is_channel=function(){return null!=this.channel},Event.prototype.is_result=function(){return"undefined"!=typeof this.result},Event.prototype.is_ping=function(){return"websocket_rails.ping"===this.name},Event.prototype.serialize=function(){return JSON.stringify([this.name,this.attributes()])},Event.prototype.attributes=function(){return{id:this.id,channel:this.channel,data:this.data,token:this.token}},Event.prototype.run_callbacks=function(success,result){return this.success=success,this.result=result,this.success===!0?"function"==typeof this.success_callback?this.success_callback(this.result):void 0:"function"==typeof this.failure_callback?this.failure_callback(this.result):void 0},Event}()}.call(this),function(){WebSocketRails.AbstractConnection=function(){function AbstractConnection(url,dispatcher){this.dispatcher=dispatcher,this.message_queue=[]}return AbstractConnection.prototype.close=function(){},AbstractConnection.prototype.trigger=function(event){return"connected"!==this.dispatcher.state?this.message_queue.push(event):this.send_event(event)},AbstractConnection.prototype.send_event=function(event){return null!=this.connection_id?event.connection_id=this.connection_id:void 0},AbstractConnection.prototype.on_close=function(event){var close_event;return this.dispatcher&&this.dispatcher._conn===this?(close_event=new WebSocketRails.Event(["connection_closed",event]),this.dispatcher.state="disconnected",this.dispatcher.dispatch(close_event)):void 0},AbstractConnection.prototype.on_error=function(event){var error_event;return this.dispatcher&&this.dispatcher._conn===this?(error_event=new WebSocketRails.Event(["connection_error",event]),this.dispatcher.state="disconnected",this.dispatcher.dispatch(error_event)):void 0},AbstractConnection.prototype.on_message=function(event_data){return this.dispatcher&&this.dispatcher._conn===this?this.dispatcher.new_message(event_data):void 0},AbstractConnection.prototype.setConnectionId=function(connection_id){this.connection_id=connection_id},AbstractConnection.prototype.flush_queue=function(){var event,_i,_len,_ref;for(_ref=this.message_queue,_i=0,_len=_ref.length;_len>_i;_i++)event=_ref[_i],this.trigger(event);return this.message_queue=[]},AbstractConnection}()}.call(this),function(){var __hasProp={}.hasOwnProperty,__extends=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)__hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child};WebSocketRails.WebSocketConnection=function(_super){function WebSocketConnection(url,dispatcher){this.url=url,this.dispatcher=dispatcher,WebSocketConnection.__super__.constructor.apply(this,arguments),this.url.match(/^wss?:\/\//)?console.log("WARNING: Using connection urls with protocol specified is depricated"):this.url="https:"===window.location.protocol?"wss://"+this.url:"ws://"+this.url,this._conn=new WebSocket(this.url),this._conn.onmessage=function(_this){return function(event){var event_data;return event_data=JSON.parse(event.data),_this.on_message(event_data)}}(this),this._conn.onclose=function(_this){return function(event){return _this.on_close(event)}}(this),this._conn.onerror=function(_this){return function(event){return _this.on_error(event)}}(this)}return __extends(WebSocketConnection,_super),WebSocketConnection.prototype.connection_type="websocket",WebSocketConnection.prototype.close=function(){return this._conn.close()},WebSocketConnection.prototype.send_event=function(event){return WebSocketConnection.__super__.send_event.apply(this,arguments),this._conn.send(event.serialize())},WebSocketConnection}(WebSocketRails.AbstractConnection)}.call(this),function(){var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}};WebSocketRails.Channel=function(){function Channel(name,_dispatcher,is_private,on_success,on_failure){var event,event_name,_ref;this.name=name,this._dispatcher=_dispatcher,this.is_private=null!=is_private?is_private:!1,this.on_success=on_success,this.on_failure=on_failure,this._failure_launcher=__bind(this._failure_launcher,this),this._success_launcher=__bind(this._success_launcher,this),this._callbacks={},this._token=void 0,this._queue=[],event_name=this.is_private?"websocket_rails.subscribe_private":"websocket_rails.subscribe",this.connection_id=null!=(_ref=this._dispatcher._conn)?_ref.connection_id:void 0,event=new WebSocketRails.Event([event_name,{data:{channel:this.name}},this.connection_id],this._success_launcher,this._failure_launcher),this._dispatcher.trigger_event(event)}return Channel.prototype.destroy=function(){var event,event_name,_ref;return this.connection_id===(null!=(_ref=this._dispatcher._conn)?_ref.connection_id:void 0)&&(event_name="websocket_rails.unsubscribe",event=new WebSocketRails.Event([event_name,{data:{channel:this.name}},this.connection_id]),this._dispatcher.trigger_event(event)),this._callbacks={}},Channel.prototype.bind=function(event_name,callback){var _base;return null==(_base=this._callbacks)[event_name]&&(_base[event_name]=[]),this._callbacks[event_name].push(callback)},Channel.prototype.unbind=function(event_name){return delete this._callbacks[event_name]},Channel.prototype.trigger=function(event_name,message){var event;return event=new WebSocketRails.Event([event_name,{channel:this.name,data:message,token:this._token},this.connection_id]),this._token?this._dispatcher.trigger_event(event):this._queue.push(event)},Channel.prototype.dispatch=function(event_name,message){var callback,_i,_len,_ref,_ref1,_results;if("websocket_rails.channel_token"===event_name)return this.connection_id=null!=(_ref=this._dispatcher._conn)?_ref.connection_id:void 0,this._token=message.token,this.flush_queue();if(null!=this._callbacks[event_name]){for(_ref1=this._callbacks[event_name],_results=[],_i=0,_len=_ref1.length;_len>_i;_i++)callback=_ref1[_i],_results.push(callback(message));return _results}},Channel.prototype._success_launcher=function(data){return null!=this.on_success?this.on_success(data):void 0},Channel.prototype._failure_launcher=function(data){return null!=this.on_failure?this.on_failure(data):void 0},Channel.prototype.flush_queue=function(){var event,_i,_len,_ref;for(_ref=this._queue,_i=0,_len=_ref.length;_len>_i;_i++)event=_ref[_i],this._dispatcher.trigger_event(event);return this._queue=[]},Channel}()}.call(this);
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: websocket-rails-js
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dan Knox
8
+ - Rory Low
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-12-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.5'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.5'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: JavaScript client for websocket-rails.
57
+ email:
58
+ - dknox@threedotloft.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - Guardfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - app/assets/javascripts/websocket_rails/abstract_connection.js.coffee
70
+ - app/assets/javascripts/websocket_rails/channel.js.coffee
71
+ - app/assets/javascripts/websocket_rails/connection.js.coffee
72
+ - app/assets/javascripts/websocket_rails/event.js.coffee
73
+ - app/assets/javascripts/websocket_rails/http_connection.js.coffee
74
+ - app/assets/javascripts/websocket_rails/main.js
75
+ - app/assets/javascripts/websocket_rails/websocket_connection.js.coffee
76
+ - app/assets/javascripts/websocket_rails/websocket_rails.js.coffee
77
+ - lib/websocket-rails-js.rb
78
+ - lib/websocket_rails/js/engine.rb
79
+ - lib/websocket_rails/js/version.rb
80
+ - spec/javascripts/helpers/.gitkeep
81
+ - spec/javascripts/helpers/helpers.coffee
82
+ - spec/javascripts/support/jasmine.yml
83
+ - spec/javascripts/support/jasmine_helper.rb
84
+ - spec/javascripts/support/jquery.min.js
85
+ - spec/javascripts/support/sinon-1.7.1.js
86
+ - spec/javascripts/websocket_rails/channel_spec.js.coffee
87
+ - spec/javascripts/websocket_rails/connection_spec.js.coffee
88
+ - spec/javascripts/websocket_rails/event_spec.js.coffee
89
+ - spec/javascripts/websocket_rails/helpers.js.coffee
90
+ - spec/javascripts/websocket_rails/websocket_rails_spec.js.coffee
91
+ - src/websocket_rails/abstract_connection.js
92
+ - src/websocket_rails/channel.js
93
+ - src/websocket_rails/connection.js
94
+ - src/websocket_rails/event.js
95
+ - src/websocket_rails/http_connection.js
96
+ - src/websocket_rails/websocket_connection.js
97
+ - src/websocket_rails/websocket_rails.js
98
+ - websocket-rails-js.gemspec
99
+ - websocket_rails.0.0.1.min.js
100
+ homepage: http://websocket-rails.github.io
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: JavaScript client for websocket-rails.
124
+ test_files:
125
+ - spec/javascripts/helpers/.gitkeep
126
+ - spec/javascripts/helpers/helpers.coffee
127
+ - spec/javascripts/support/jasmine.yml
128
+ - spec/javascripts/support/jasmine_helper.rb
129
+ - spec/javascripts/support/jquery.min.js
130
+ - spec/javascripts/support/sinon-1.7.1.js
131
+ - spec/javascripts/websocket_rails/channel_spec.js.coffee
132
+ - spec/javascripts/websocket_rails/connection_spec.js.coffee
133
+ - spec/javascripts/websocket_rails/event_spec.js.coffee
134
+ - spec/javascripts/websocket_rails/helpers.js.coffee
135
+ - spec/javascripts/websocket_rails/websocket_rails_spec.js.coffee