websocket-rails 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +32 -0
- data/Gemfile +2 -1
- data/README.md +29 -34
- data/lib/assets/javascripts/websocket_rails/abstract_connection.js.coffee +45 -0
- data/lib/assets/javascripts/websocket_rails/channel.js.coffee +34 -17
- data/lib/assets/javascripts/websocket_rails/event.js.coffee +13 -11
- data/lib/assets/javascripts/websocket_rails/http_connection.js.coffee +44 -45
- data/lib/assets/javascripts/websocket_rails/main.js +1 -0
- data/lib/assets/javascripts/websocket_rails/websocket_connection.js.coffee +20 -34
- data/lib/assets/javascripts/websocket_rails/websocket_rails.js.coffee +60 -15
- data/lib/generators/websocket_rails/install/templates/websocket_rails.rb +15 -0
- data/lib/rails/config/routes.rb +1 -1
- data/lib/rails/tasks/websocket_rails.tasks +6 -2
- data/lib/websocket_rails/channel.rb +28 -2
- data/lib/websocket_rails/channel_manager.rb +16 -0
- data/lib/websocket_rails/configuration.rb +26 -1
- data/lib/websocket_rails/connection_adapters/http.rb +7 -0
- data/lib/websocket_rails/connection_adapters/web_socket.rb +3 -1
- data/lib/websocket_rails/connection_manager.rb +1 -1
- data/lib/websocket_rails/controller_factory.rb +1 -1
- data/lib/websocket_rails/event.rb +9 -2
- data/lib/websocket_rails/logging.rb +0 -1
- data/lib/websocket_rails/synchronization.rb +11 -7
- data/lib/websocket_rails/version.rb +1 -1
- data/spec/javascripts/generated/assets/abstract_connection.js +71 -0
- data/spec/javascripts/generated/assets/channel.js +58 -34
- data/spec/javascripts/generated/assets/event.js +12 -16
- data/spec/javascripts/generated/assets/http_connection.js +67 -65
- data/spec/javascripts/generated/assets/websocket_connection.js +36 -51
- data/spec/javascripts/generated/assets/websocket_rails.js +68 -21
- data/spec/javascripts/generated/specs/channel_spec.js +102 -19
- data/spec/javascripts/generated/specs/helpers.js +17 -0
- data/spec/javascripts/generated/specs/websocket_connection_spec.js +72 -19
- data/spec/javascripts/generated/specs/websocket_rails_spec.js +146 -47
- data/spec/javascripts/support/jasmine.yml +10 -2
- data/spec/javascripts/support/jasmine_helper.rb +38 -0
- data/spec/javascripts/websocket_rails/channel_spec.coffee +66 -12
- data/spec/javascripts/websocket_rails/event_spec.coffee +7 -7
- data/spec/javascripts/websocket_rails/helpers.coffee +6 -0
- data/spec/javascripts/websocket_rails/websocket_connection_spec.coffee +53 -15
- data/spec/javascripts/websocket_rails/websocket_rails_spec.coffee +108 -25
- data/spec/unit/base_controller_spec.rb +41 -0
- data/spec/unit/channel_manager_spec.rb +21 -0
- data/spec/unit/channel_spec.rb +43 -3
- data/spec/unit/connection_adapters/http_spec.rb +24 -3
- data/spec/unit/connection_adapters_spec.rb +2 -2
- data/spec/unit/connection_manager_spec.rb +1 -1
- data/spec/unit/event_spec.rb +25 -1
- data/spec/unit/logging_spec.rb +1 -1
- metadata +57 -67
- data/spec/javascripts/support/jasmine_config.rb +0 -63
@@ -71,6 +71,11 @@ module WebsocketRails
|
|
71
71
|
case encoded_data
|
72
72
|
when String
|
73
73
|
event_name, data = JSON.parse encoded_data
|
74
|
+
|
75
|
+
unless event_name.is_a?(String) && data.is_a?(Hash)
|
76
|
+
raise UnknownDataType
|
77
|
+
end
|
78
|
+
|
74
79
|
data = data.merge(:connection => connection).with_indifferent_access
|
75
80
|
Event.new event_name, data
|
76
81
|
# when Array
|
@@ -93,7 +98,7 @@ module WebsocketRails
|
|
93
98
|
include Logging
|
94
99
|
extend StaticEvents
|
95
100
|
|
96
|
-
attr_reader :id, :name, :connection, :namespace, :channel, :user_id
|
101
|
+
attr_reader :id, :name, :connection, :namespace, :channel, :user_id, :token
|
97
102
|
|
98
103
|
attr_accessor :data, :result, :success, :server_token
|
99
104
|
|
@@ -108,7 +113,8 @@ module WebsocketRails
|
|
108
113
|
end
|
109
114
|
@id = options[:id]
|
110
115
|
@data = options[:data].is_a?(Hash) ? options[:data].with_indifferent_access : options[:data]
|
111
|
-
@channel = options[:channel].to_sym if options[:channel]
|
116
|
+
@channel = options[:channel].to_sym rescue options[:channel].to_s.to_sym if options[:channel]
|
117
|
+
@token = options[:token] if options[:token]
|
112
118
|
@connection = options[:connection]
|
113
119
|
@server_token = options[:server_token]
|
114
120
|
@user_id = options[:user_id]
|
@@ -125,6 +131,7 @@ module WebsocketRails
|
|
125
131
|
:data => data,
|
126
132
|
:success => success,
|
127
133
|
:result => result,
|
134
|
+
:token => token,
|
128
135
|
:server_token => server_token
|
129
136
|
}
|
130
137
|
]
|
@@ -33,6 +33,10 @@ module WebsocketRails
|
|
33
33
|
singleton.shutdown!
|
34
34
|
end
|
35
35
|
|
36
|
+
def self.redis
|
37
|
+
singleton.redis
|
38
|
+
end
|
39
|
+
|
36
40
|
def self.singleton
|
37
41
|
@singleton ||= new
|
38
42
|
end
|
@@ -40,7 +44,10 @@ module WebsocketRails
|
|
40
44
|
include Logging
|
41
45
|
|
42
46
|
def redis
|
43
|
-
@redis ||=
|
47
|
+
@redis ||= begin
|
48
|
+
redis_options = WebsocketRails.config.redis_options
|
49
|
+
EM.reactor_running? ? Redis.new(redis_options) : ruby_redis
|
50
|
+
end
|
44
51
|
end
|
45
52
|
|
46
53
|
def ruby_redis
|
@@ -52,9 +59,8 @@ module WebsocketRails
|
|
52
59
|
|
53
60
|
def publish(event)
|
54
61
|
Fiber.new do
|
55
|
-
redis_client = EM.reactor_running? ? redis : ruby_redis
|
56
62
|
event.server_token = server_token
|
57
|
-
|
63
|
+
redis.publish "websocket_rails.events", event.serialize
|
58
64
|
end.resume
|
59
65
|
end
|
60
66
|
|
@@ -157,16 +163,14 @@ module WebsocketRails
|
|
157
163
|
|
158
164
|
def find_user(identifier)
|
159
165
|
Fiber.new do
|
160
|
-
|
161
|
-
raw_user = redis_client.hget('websocket_rails.users', identifier)
|
166
|
+
raw_user = redis.hget('websocket_rails.users', identifier)
|
162
167
|
raw_user ? JSON.parse(raw_user) : nil
|
163
168
|
end.resume
|
164
169
|
end
|
165
170
|
|
166
171
|
def all_users
|
167
172
|
Fiber.new do
|
168
|
-
|
169
|
-
redis_client.hgetall('websocket_rails.users')
|
173
|
+
redis.hgetall('websocket_rails.users')
|
170
174
|
end.resume
|
171
175
|
end
|
172
176
|
|
@@ -0,0 +1,71 @@
|
|
1
|
+
|
2
|
+
/*
|
3
|
+
Abstract Interface for the WebSocketRails client.
|
4
|
+
*/
|
5
|
+
|
6
|
+
(function() {
|
7
|
+
WebSocketRails.AbstractConnection = (function() {
|
8
|
+
function AbstractConnection(url, dispatcher) {
|
9
|
+
this.dispatcher = dispatcher;
|
10
|
+
this.message_queue = [];
|
11
|
+
}
|
12
|
+
|
13
|
+
AbstractConnection.prototype.close = function() {};
|
14
|
+
|
15
|
+
AbstractConnection.prototype.trigger = function(event) {
|
16
|
+
if (this.dispatcher.state !== 'connected') {
|
17
|
+
return this.message_queue.push(event);
|
18
|
+
} else {
|
19
|
+
return this.send_event(event);
|
20
|
+
}
|
21
|
+
};
|
22
|
+
|
23
|
+
AbstractConnection.prototype.send_event = function(event) {
|
24
|
+
if (this.connection_id != null) {
|
25
|
+
return event.connection_id = this.connection_id;
|
26
|
+
}
|
27
|
+
};
|
28
|
+
|
29
|
+
AbstractConnection.prototype.on_close = function(event) {
|
30
|
+
var close_event;
|
31
|
+
if (this.dispatcher && this.dispatcher._conn === this) {
|
32
|
+
close_event = new WebSocketRails.Event(['connection_closed', event]);
|
33
|
+
this.dispatcher.state = 'disconnected';
|
34
|
+
return this.dispatcher.dispatch(close_event);
|
35
|
+
}
|
36
|
+
};
|
37
|
+
|
38
|
+
AbstractConnection.prototype.on_error = function(event) {
|
39
|
+
var error_event;
|
40
|
+
if (this.dispatcher && this.dispatcher._conn === this) {
|
41
|
+
error_event = new WebSocketRails.Event(['connection_error', event]);
|
42
|
+
this.dispatcher.state = 'disconnected';
|
43
|
+
return this.dispatcher.dispatch(error_event);
|
44
|
+
}
|
45
|
+
};
|
46
|
+
|
47
|
+
AbstractConnection.prototype.on_message = function(event_data) {
|
48
|
+
if (this.dispatcher && this.dispatcher._conn === this) {
|
49
|
+
return this.dispatcher.new_message(event_data);
|
50
|
+
}
|
51
|
+
};
|
52
|
+
|
53
|
+
AbstractConnection.prototype.setConnectionId = function(connection_id) {
|
54
|
+
this.connection_id = connection_id;
|
55
|
+
};
|
56
|
+
|
57
|
+
AbstractConnection.prototype.flush_queue = function() {
|
58
|
+
var event, _i, _len, _ref;
|
59
|
+
_ref = this.message_queue;
|
60
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
61
|
+
event = _ref[_i];
|
62
|
+
this.trigger(event);
|
63
|
+
}
|
64
|
+
return this.message_queue = [];
|
65
|
+
};
|
66
|
+
|
67
|
+
return AbstractConnection;
|
68
|
+
|
69
|
+
})();
|
70
|
+
|
71
|
+
}).call(this);
|
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
/*
|
2
3
|
The channel object is returned when you subscribe to a channel.
|
3
4
|
|
@@ -6,51 +7,53 @@ For instance:
|
|
6
7
|
var awesome_channel = dispatcher.subscribe('awesome_channel');
|
7
8
|
awesome_channel.bind('event', function(data) { console.log('channel event!'); });
|
8
9
|
awesome_channel.trigger('awesome_event', awesome_object);
|
9
|
-
*/
|
10
|
-
|
10
|
+
*/
|
11
11
|
|
12
12
|
(function() {
|
13
13
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
14
14
|
|
15
15
|
WebSocketRails.Channel = (function() {
|
16
|
-
function Channel(name, _dispatcher, is_private) {
|
17
|
-
var event, event_name;
|
16
|
+
function Channel(name, _dispatcher, is_private, on_success, on_failure) {
|
17
|
+
var event, event_name, _ref;
|
18
18
|
this.name = name;
|
19
19
|
this._dispatcher = _dispatcher;
|
20
|
-
this.is_private = is_private;
|
20
|
+
this.is_private = is_private != null ? is_private : false;
|
21
|
+
this.on_success = on_success;
|
22
|
+
this.on_failure = on_failure;
|
21
23
|
this._failure_launcher = __bind(this._failure_launcher, this);
|
22
24
|
this._success_launcher = __bind(this._success_launcher, this);
|
23
|
-
this.
|
24
|
-
this.
|
25
|
-
this.
|
26
|
-
this.destroy = __bind(this.destroy, this);
|
25
|
+
this._callbacks = {};
|
26
|
+
this._token = void 0;
|
27
|
+
this._queue = [];
|
27
28
|
if (this.is_private) {
|
28
29
|
event_name = 'websocket_rails.subscribe_private';
|
29
30
|
} else {
|
30
31
|
event_name = 'websocket_rails.subscribe';
|
31
32
|
}
|
33
|
+
this.connection_id = (_ref = this._dispatcher._conn) != null ? _ref.connection_id : void 0;
|
32
34
|
event = new WebSocketRails.Event([
|
33
35
|
event_name, {
|
34
36
|
data: {
|
35
37
|
channel: this.name
|
36
38
|
}
|
37
|
-
}, this.
|
39
|
+
}, this.connection_id
|
38
40
|
], this._success_launcher, this._failure_launcher);
|
39
41
|
this._dispatcher.trigger_event(event);
|
40
|
-
this._callbacks = {};
|
41
42
|
}
|
42
43
|
|
43
44
|
Channel.prototype.destroy = function() {
|
44
|
-
var event, event_name;
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
var event, event_name, _ref;
|
46
|
+
if (this.connection_id === ((_ref = this._dispatcher._conn) != null ? _ref.connection_id : void 0)) {
|
47
|
+
event_name = 'websocket_rails.unsubscribe';
|
48
|
+
event = new WebSocketRails.Event([
|
49
|
+
event_name, {
|
50
|
+
data: {
|
51
|
+
channel: this.name
|
52
|
+
}
|
53
|
+
}, this.connection_id
|
54
|
+
]);
|
55
|
+
this._dispatcher.trigger_event(event);
|
56
|
+
}
|
54
57
|
return this._callbacks = {};
|
55
58
|
};
|
56
59
|
|
@@ -67,24 +70,35 @@ For instance:
|
|
67
70
|
event = new WebSocketRails.Event([
|
68
71
|
event_name, {
|
69
72
|
channel: this.name,
|
70
|
-
data: message
|
71
|
-
|
73
|
+
data: message,
|
74
|
+
token: this._token
|
75
|
+
}, this.connection_id
|
72
76
|
]);
|
73
|
-
|
77
|
+
if (!this._token) {
|
78
|
+
return this._queue.push(event);
|
79
|
+
} else {
|
80
|
+
return this._dispatcher.trigger_event(event);
|
81
|
+
}
|
74
82
|
};
|
75
83
|
|
76
84
|
Channel.prototype.dispatch = function(event_name, message) {
|
77
|
-
var callback, _i, _len, _ref, _results;
|
78
|
-
if (
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
85
|
+
var callback, _i, _len, _ref, _ref1, _results;
|
86
|
+
if (event_name === 'websocket_rails.channel_token') {
|
87
|
+
this.connection_id = (_ref = this._dispatcher._conn) != null ? _ref.connection_id : void 0;
|
88
|
+
this._token = message['token'];
|
89
|
+
return this.flush_queue();
|
90
|
+
} else {
|
91
|
+
if (this._callbacks[event_name] == null) {
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
_ref1 = this._callbacks[event_name];
|
95
|
+
_results = [];
|
96
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
97
|
+
callback = _ref1[_i];
|
98
|
+
_results.push(callback(message));
|
99
|
+
}
|
100
|
+
return _results;
|
86
101
|
}
|
87
|
-
return _results;
|
88
102
|
};
|
89
103
|
|
90
104
|
Channel.prototype._success_launcher = function(data) {
|
@@ -99,6 +113,16 @@ For instance:
|
|
99
113
|
}
|
100
114
|
};
|
101
115
|
|
116
|
+
Channel.prototype.flush_queue = function() {
|
117
|
+
var event, _i, _len, _ref;
|
118
|
+
_ref = this._queue;
|
119
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
120
|
+
event = _ref[_i];
|
121
|
+
this._dispatcher.trigger_event(event);
|
122
|
+
}
|
123
|
+
return this._queue = [];
|
124
|
+
};
|
125
|
+
|
102
126
|
return Channel;
|
103
127
|
|
104
128
|
})();
|
@@ -1,28 +1,21 @@
|
|
1
|
+
|
1
2
|
/*
|
2
3
|
The Event object stores all the relevant event information.
|
3
|
-
*/
|
4
|
-
|
4
|
+
*/
|
5
5
|
|
6
6
|
(function() {
|
7
|
-
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
8
|
-
|
9
7
|
WebSocketRails.Event = (function() {
|
10
8
|
function Event(data, success_callback, failure_callback) {
|
11
9
|
var attr;
|
12
10
|
this.success_callback = success_callback;
|
13
11
|
this.failure_callback = failure_callback;
|
14
|
-
this.run_callbacks = __bind(this.run_callbacks, this);
|
15
|
-
this.attributes = __bind(this.attributes, this);
|
16
|
-
this.serialize = __bind(this.serialize, this);
|
17
|
-
this.is_ping = __bind(this.is_ping, this);
|
18
|
-
this.is_result = __bind(this.is_result, this);
|
19
|
-
this.is_channel = __bind(this.is_channel, this);
|
20
12
|
this.name = data[0];
|
21
13
|
attr = data[1];
|
22
14
|
if (attr != null) {
|
23
15
|
this.id = attr['id'] != null ? attr['id'] : ((1 + Math.random()) * 0x10000) | 0;
|
24
16
|
this.channel = attr.channel != null ? attr.channel : void 0;
|
25
17
|
this.data = attr.data != null ? attr.data : attr;
|
18
|
+
this.token = attr.token != null ? attr.token : void 0;
|
26
19
|
this.connection_id = data[2];
|
27
20
|
if (attr.success != null) {
|
28
21
|
this.result = true;
|
@@ -36,7 +29,7 @@ The Event object stores all the relevant event information.
|
|
36
29
|
};
|
37
30
|
|
38
31
|
Event.prototype.is_result = function() {
|
39
|
-
return this.result
|
32
|
+
return typeof this.result !== 'undefined';
|
40
33
|
};
|
41
34
|
|
42
35
|
Event.prototype.is_ping = function() {
|
@@ -51,15 +44,18 @@ The Event object stores all the relevant event information.
|
|
51
44
|
return {
|
52
45
|
id: this.id,
|
53
46
|
channel: this.channel,
|
54
|
-
data: this.data
|
47
|
+
data: this.data,
|
48
|
+
token: this.token
|
55
49
|
};
|
56
50
|
};
|
57
51
|
|
58
|
-
Event.prototype.run_callbacks = function(success,
|
59
|
-
|
60
|
-
|
52
|
+
Event.prototype.run_callbacks = function(success, result) {
|
53
|
+
this.success = success;
|
54
|
+
this.result = result;
|
55
|
+
if (this.success === true) {
|
56
|
+
return typeof this.success_callback === "function" ? this.success_callback(this.result) : void 0;
|
61
57
|
} else {
|
62
|
-
return typeof this.failure_callback === "function" ? this.failure_callback(
|
58
|
+
return typeof this.failure_callback === "function" ? this.failure_callback(this.result) : void 0;
|
63
59
|
}
|
64
60
|
};
|
65
61
|
|
@@ -1,15 +1,22 @@
|
|
1
|
+
|
1
2
|
/*
|
2
3
|
HTTP Interface for the WebSocketRails client.
|
3
|
-
*/
|
4
|
-
|
4
|
+
*/
|
5
5
|
|
6
6
|
(function() {
|
7
|
-
var
|
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.HttpConnection = (function(_super) {
|
11
|
+
__extends(HttpConnection, _super);
|
8
12
|
|
9
|
-
|
10
|
-
|
13
|
+
HttpConnection.prototype.connection_type = 'http';
|
14
|
+
|
15
|
+
HttpConnection.prototype._httpFactories = function() {
|
11
16
|
return [
|
12
17
|
function() {
|
18
|
+
return new XDomainRequest();
|
19
|
+
}, function() {
|
13
20
|
return new XMLHttpRequest();
|
14
21
|
}, function() {
|
15
22
|
return new ActiveXObject("Msxml2.XMLHTTP");
|
@@ -21,93 +28,88 @@
|
|
21
28
|
];
|
22
29
|
};
|
23
30
|
|
24
|
-
HttpConnection.prototype.createXMLHttpObject = function() {
|
25
|
-
var e, factories, factory, xmlhttp, _i, _len;
|
26
|
-
xmlhttp = false;
|
27
|
-
factories = this.httpFactories();
|
28
|
-
for (_i = 0, _len = factories.length; _i < _len; _i++) {
|
29
|
-
factory = factories[_i];
|
30
|
-
try {
|
31
|
-
xmlhttp = factory();
|
32
|
-
} catch (_error) {
|
33
|
-
e = _error;
|
34
|
-
continue;
|
35
|
-
}
|
36
|
-
break;
|
37
|
-
}
|
38
|
-
return xmlhttp;
|
39
|
-
};
|
40
|
-
|
41
31
|
function HttpConnection(url, dispatcher) {
|
42
|
-
|
32
|
+
var e;
|
43
33
|
this.dispatcher = dispatcher;
|
44
|
-
|
45
|
-
this.
|
46
|
-
this.
|
47
|
-
this.parse_stream = __bind(this.parse_stream, this);
|
48
|
-
this.createXMLHttpObject = __bind(this.createXMLHttpObject, this);
|
49
|
-
this._url = this.url;
|
50
|
-
this._conn = this.createXMLHttpObject();
|
34
|
+
HttpConnection.__super__.constructor.apply(this, arguments);
|
35
|
+
this._url = "http://" + url;
|
36
|
+
this._conn = this._createXMLHttpObject();
|
51
37
|
this.last_pos = 0;
|
52
|
-
|
53
|
-
|
54
|
-
|
38
|
+
try {
|
39
|
+
this._conn.onreadystatechange = (function(_this) {
|
40
|
+
return function() {
|
41
|
+
return _this._parse_stream();
|
42
|
+
};
|
43
|
+
})(this);
|
44
|
+
this._conn.addEventListener("load", this.on_close, false);
|
45
|
+
} catch (_error) {
|
46
|
+
e = _error;
|
47
|
+
this._conn.onprogress = (function(_this) {
|
48
|
+
return function() {
|
49
|
+
return _this._parse_stream();
|
50
|
+
};
|
51
|
+
})(this);
|
52
|
+
this._conn.onload = this.on_close;
|
53
|
+
this._conn.readyState = 3;
|
54
|
+
}
|
55
55
|
this._conn.open("GET", this._url, true);
|
56
56
|
this._conn.send();
|
57
57
|
}
|
58
58
|
|
59
|
-
HttpConnection.prototype.
|
60
|
-
|
61
|
-
if (this._conn.readyState === 3) {
|
62
|
-
data = this._conn.responseText.substring(this.last_pos);
|
63
|
-
this.last_pos = this._conn.responseText.length;
|
64
|
-
data = data.replace(/\]\]\[\[/g, "],[");
|
65
|
-
decoded_data = JSON.parse(data);
|
66
|
-
return this.dispatcher.new_message(decoded_data);
|
67
|
-
}
|
59
|
+
HttpConnection.prototype.close = function() {
|
60
|
+
return this._conn.abort();
|
68
61
|
};
|
69
62
|
|
70
|
-
HttpConnection.prototype.
|
71
|
-
|
72
|
-
|
73
|
-
} else {
|
74
|
-
return this.post_data(this.dispatcher.connection_id, event.serialize());
|
75
|
-
}
|
63
|
+
HttpConnection.prototype.send_event = function(event) {
|
64
|
+
HttpConnection.__super__.send_event.apply(this, arguments);
|
65
|
+
return this._post_data(event.serialize());
|
76
66
|
};
|
77
67
|
|
78
|
-
HttpConnection.prototype.
|
68
|
+
HttpConnection.prototype._post_data = function(payload) {
|
79
69
|
return $.ajax(this._url, {
|
80
70
|
type: 'POST',
|
81
71
|
data: {
|
82
|
-
client_id: connection_id,
|
72
|
+
client_id: this.connection_id,
|
83
73
|
data: payload
|
84
74
|
},
|
85
75
|
success: function() {}
|
86
76
|
});
|
87
77
|
};
|
88
78
|
|
89
|
-
HttpConnection.prototype.
|
90
|
-
var
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
79
|
+
HttpConnection.prototype._createXMLHttpObject = function() {
|
80
|
+
var e, factories, factory, xmlhttp, _i, _len;
|
81
|
+
xmlhttp = false;
|
82
|
+
factories = this._httpFactories();
|
83
|
+
for (_i = 0, _len = factories.length; _i < _len; _i++) {
|
84
|
+
factory = factories[_i];
|
85
|
+
try {
|
86
|
+
xmlhttp = factory();
|
87
|
+
} catch (_error) {
|
88
|
+
e = _error;
|
89
|
+
continue;
|
96
90
|
}
|
97
|
-
|
91
|
+
break;
|
98
92
|
}
|
99
|
-
return
|
93
|
+
return xmlhttp;
|
100
94
|
};
|
101
95
|
|
102
|
-
HttpConnection.prototype.
|
103
|
-
var
|
104
|
-
|
105
|
-
|
106
|
-
|
96
|
+
HttpConnection.prototype._parse_stream = function() {
|
97
|
+
var data, e, event_data;
|
98
|
+
if (this._conn.readyState === 3) {
|
99
|
+
data = this._conn.responseText.substring(this.last_pos);
|
100
|
+
this.last_pos = this._conn.responseText.length;
|
101
|
+
data = data.replace(/\]\]\[\[/g, "],[");
|
102
|
+
try {
|
103
|
+
event_data = JSON.parse(data);
|
104
|
+
return this.on_message(event_data);
|
105
|
+
} catch (_error) {
|
106
|
+
e = _error;
|
107
|
+
}
|
108
|
+
}
|
107
109
|
};
|
108
110
|
|
109
111
|
return HttpConnection;
|
110
112
|
|
111
|
-
})();
|
113
|
+
})(WebSocketRails.AbstractConnection);
|
112
114
|
|
113
115
|
}).call(this);
|