face-faye 0.8.9
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +304 -0
- data/README.rdoc +83 -0
- data/lib/faye-browser-min.js +2 -0
- data/lib/faye-browser-min.js.map +8 -0
- data/lib/faye-browser.js +2194 -0
- data/lib/faye.rb +122 -0
- data/lib/faye/adapters/rack_adapter.rb +216 -0
- data/lib/faye/adapters/static_server.rb +56 -0
- data/lib/faye/engines/connection.rb +60 -0
- data/lib/faye/engines/memory.rb +112 -0
- data/lib/faye/engines/proxy.rb +121 -0
- data/lib/faye/error.rb +49 -0
- data/lib/faye/mixins/logging.rb +47 -0
- data/lib/faye/mixins/publisher.rb +30 -0
- data/lib/faye/mixins/timeouts.rb +22 -0
- data/lib/faye/protocol/channel.rb +124 -0
- data/lib/faye/protocol/client.rb +376 -0
- data/lib/faye/protocol/extensible.rb +43 -0
- data/lib/faye/protocol/grammar.rb +58 -0
- data/lib/faye/protocol/publication.rb +5 -0
- data/lib/faye/protocol/server.rb +293 -0
- data/lib/faye/protocol/socket.rb +23 -0
- data/lib/faye/protocol/subscription.rb +24 -0
- data/lib/faye/transport/http.rb +76 -0
- data/lib/faye/transport/local.rb +22 -0
- data/lib/faye/transport/transport.rb +116 -0
- data/lib/faye/transport/web_socket.rb +92 -0
- data/lib/faye/util/namespace.rb +20 -0
- data/spec/browser.html +45 -0
- data/spec/encoding_helper.rb +7 -0
- data/spec/install.sh +78 -0
- data/spec/javascript/channel_spec.js +15 -0
- data/spec/javascript/client_spec.js +729 -0
- data/spec/javascript/engine/memory_spec.js +7 -0
- data/spec/javascript/engine_spec.js +417 -0
- data/spec/javascript/faye_spec.js +34 -0
- data/spec/javascript/grammar_spec.js +66 -0
- data/spec/javascript/node_adapter_spec.js +307 -0
- data/spec/javascript/publisher_spec.js +27 -0
- data/spec/javascript/server/connect_spec.js +168 -0
- data/spec/javascript/server/disconnect_spec.js +121 -0
- data/spec/javascript/server/extensions_spec.js +60 -0
- data/spec/javascript/server/handshake_spec.js +145 -0
- data/spec/javascript/server/integration_spec.js +131 -0
- data/spec/javascript/server/publish_spec.js +85 -0
- data/spec/javascript/server/subscribe_spec.js +247 -0
- data/spec/javascript/server/unsubscribe_spec.js +245 -0
- data/spec/javascript/server_spec.js +121 -0
- data/spec/javascript/transport_spec.js +135 -0
- data/spec/node.js +55 -0
- data/spec/phantom.js +17 -0
- data/spec/ruby/channel_spec.rb +17 -0
- data/spec/ruby/client_spec.rb +741 -0
- data/spec/ruby/engine/memory_spec.rb +7 -0
- data/spec/ruby/engine_examples.rb +427 -0
- data/spec/ruby/faye_spec.rb +30 -0
- data/spec/ruby/grammar_spec.rb +68 -0
- data/spec/ruby/publisher_spec.rb +27 -0
- data/spec/ruby/rack_adapter_spec.rb +236 -0
- data/spec/ruby/server/connect_spec.rb +170 -0
- data/spec/ruby/server/disconnect_spec.rb +120 -0
- data/spec/ruby/server/extensions_spec.rb +68 -0
- data/spec/ruby/server/handshake_spec.rb +143 -0
- data/spec/ruby/server/integration_spec.rb +133 -0
- data/spec/ruby/server/publish_spec.rb +81 -0
- data/spec/ruby/server/subscribe_spec.rb +247 -0
- data/spec/ruby/server/unsubscribe_spec.rb +247 -0
- data/spec/ruby/server_spec.rb +121 -0
- data/spec/ruby/transport_spec.rb +136 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/testswarm +42 -0
- data/spec/thin_proxy.rb +37 -0
- metadata +441 -0
data/History.txt
ADDED
@@ -0,0 +1,304 @@
|
|
1
|
+
=== 0.8.9 / 2013-02-26
|
2
|
+
|
3
|
+
* Specify ciphers for SSL on Node to mitigate the BEAST attack
|
4
|
+
* Mitigate increased risk of socket hang-up errors in Node v0.8.20
|
5
|
+
* Fix race condition when processing outgoing extensions in the Node server
|
6
|
+
* Fix problem loading the client script when using {mount: '/'}
|
7
|
+
* Clean up connection objects when a WebSocket is re-used with a new clientId
|
8
|
+
* All JavaScript code now runs in strict mode
|
9
|
+
* Select transport on handshake, instead of on client creation to allow time for disable() calls
|
10
|
+
* Do not speculatively open WebSocket/EventSource connections if they are disabled
|
11
|
+
* Gracefully handle WebSocket messages with no data on the client side
|
12
|
+
* Close and reconnect WebSocket when onerror is fired, not just when onclose is fired
|
13
|
+
* Fix problem with caching of EventSource connections with stale clientIds
|
14
|
+
* Don't parse query strings when checking if a URL is same-origin or not
|
15
|
+
|
16
|
+
|
17
|
+
=== 0.8.8 / 2013-01-10
|
18
|
+
|
19
|
+
* Patch security hole allowing remote execution of arbitrary Server methods
|
20
|
+
|
21
|
+
|
22
|
+
=== 0.8.7 -- removed due to error while publishing
|
23
|
+
|
24
|
+
|
25
|
+
=== 0.8.6 / 2012-10-07
|
26
|
+
|
27
|
+
* Make sure messages pushed to the client over a socket pass through outgoing extensions
|
28
|
+
|
29
|
+
|
30
|
+
=== 0.8.5 / 2012-09-30
|
31
|
+
|
32
|
+
* Fix a bug in URI.parse() that caused Faye endpoints to inherit search and hash from window.location
|
33
|
+
|
34
|
+
|
35
|
+
=== 0.8.4 / 2012-09-29
|
36
|
+
|
37
|
+
* Optimise upgrade process so that WebSocket is tested earlier and the connection is cached
|
38
|
+
* Check that EventSource actually works to work around broken Opera implementation
|
39
|
+
* Emit 'connection:open' and 'connection:close' events from the Engine proxy
|
40
|
+
* Increase size of client IDs from 128 to 160 bits
|
41
|
+
* Fix bug with relative URL resolution in IE
|
42
|
+
* Limit the JSON-P transport's message buffer so it doesn't create over-long URLs
|
43
|
+
* Send 'Pragma: no-cache' with XHR requests to guard against iOS 6 POST caching
|
44
|
+
* Add 'charset=utf-8' to response Content-Type headers
|
45
|
+
|
46
|
+
|
47
|
+
=== 0.8.3 / 2012-07-15
|
48
|
+
|
49
|
+
* Client#subscribe returns an array of Subscriptions if given an array of channels
|
50
|
+
* Allow different endpoints to be specified per-transport
|
51
|
+
* Only use IE's XDomainRequest for same-protocol requests
|
52
|
+
* Replace URL parser with one that treats relative URLs the same as the browser
|
53
|
+
* Improve logging of malformed requests and detect problems earlier
|
54
|
+
* Make sure socket connections are closed when a client session is timed out
|
55
|
+
* Stop WebSocket reconnecting after window.onbeforeunload
|
56
|
+
|
57
|
+
|
58
|
+
=== 0.8.2 / 2012-04-12
|
59
|
+
|
60
|
+
* Fix replacement of null with {} in copyObject()
|
61
|
+
* Make EventSource transport trigger transport:up/down events
|
62
|
+
* Supply source map for minified JavaScript client, and include source in gem
|
63
|
+
* Return Content-Length: 0 for 304 responses
|
64
|
+
* Handle pre-flight CORS requests from old versions of Safari
|
65
|
+
|
66
|
+
|
67
|
+
=== 0.8.1 / 2012-03-15
|
68
|
+
|
69
|
+
* Make Publisher#trigger safe for event listeners that modify the listener list
|
70
|
+
* Make Server#subscribe return a response if the incoming message has an error
|
71
|
+
* Fix edge case in code that identifies the clientId of socket connections
|
72
|
+
* Return Content-Length headers for HTTP responses
|
73
|
+
* Don't send empty lists of messages from the WebSocket transport
|
74
|
+
* Stop client sending multiple /meta/subscribe messages for subscriptions made before handshaking
|
75
|
+
* Stop client treating incoming published messages as responses to /meta/* messages
|
76
|
+
|
77
|
+
|
78
|
+
=== 0.8.0 / 2012-02-26
|
79
|
+
|
80
|
+
* Extract the Redis engine into a separate library, faye-redis
|
81
|
+
* Stabilize and document the Engine API so others can write backends
|
82
|
+
* Extract WebSocket and EventSource tools into a separate library, faye-websocket
|
83
|
+
* Improve use of WebSocket so messages are immediately pushed rather than polling
|
84
|
+
* Introduce new EventSource-based transport, for proxies that block WebSocket
|
85
|
+
* Support the Rainbows and Goliath web servers for Ruby, same as faye-websocket
|
86
|
+
* Improve detection of network errors and switch to fixed-interval for reconnecting
|
87
|
+
* Add setHeader() method to Client (e.g. for connecting to Salesforce API)
|
88
|
+
* Add timeout() method to Faye.Deferrable to match EventMachine::Deferrable
|
89
|
+
* Fix some bugs in client-side message handlers created with subscribe()
|
90
|
+
* Improve speed and memory consumption of copyObject()
|
91
|
+
* Switch from JSON to Yajl for JSON parsing in Ruby
|
92
|
+
|
93
|
+
|
94
|
+
=== 0.7.1 / 2011-12-22
|
95
|
+
|
96
|
+
* Extension added() and removed() methods now receive the extended object
|
97
|
+
* Detection of WebSockets in RackAdapter is more strict
|
98
|
+
|
99
|
+
|
100
|
+
=== 0.7.0 / 2011-11-22
|
101
|
+
|
102
|
+
* Provide an event API for monitoring engine events on the server side
|
103
|
+
* Implement server-side WebSocket connections for improved latency
|
104
|
+
* Fix WebSocket protocol bugs and expose APIs for developers to use
|
105
|
+
* Make server-side HTTP transports support SSL and cookies
|
106
|
+
* Allow clients to disable selected transports and autodisconnection
|
107
|
+
* Add callback/errback API to Client#publish() interface
|
108
|
+
* Add 'socket' setting for the Redis engine for connecting through a Unix socket
|
109
|
+
|
110
|
+
|
111
|
+
=== 0.6.7 / 2011-10-20
|
112
|
+
|
113
|
+
* Cache client script in memory and add ETag and Last-Modified headers
|
114
|
+
* Fix bug in Node Redis engine where 'undefined' was used if no namespace given
|
115
|
+
* Flush Redis message queues using a transaction to avoid re-delivery of messages
|
116
|
+
* Fix race condition and timing errors present in Redis locking code
|
117
|
+
* Use Cache-Control: no-cache, no-store on JSON-P responses
|
118
|
+
* Improvements to the CORS and JSON-P transports
|
119
|
+
* Prevent retry handlers in transports from being invoked multiple times
|
120
|
+
* Use the current page protocol by default when parsing relative URIs
|
121
|
+
|
122
|
+
|
123
|
+
=== 0.6.6 / 2011-09-12
|
124
|
+
|
125
|
+
* Add :key and :cert options to the Adapter#listen methods for setting up SSL
|
126
|
+
* Fix error detection of CORS transport in IE9 running IE8 compatibility mode
|
127
|
+
* Fix dependency versions so that Rubygems lets Faye install
|
128
|
+
|
129
|
+
|
130
|
+
=== 0.6.5 / 2011-08-29
|
131
|
+
|
132
|
+
* Fix UTF-8 encoding bugs in draft-75/76 and protocol-8 WebSocket parsers
|
133
|
+
* Switch to streaming parser for WebSocket protocol-8
|
134
|
+
* Remove an SREM operation that shouldn't have been in the Redis engine
|
135
|
+
* Move thin_extensions.rb so it's not on the Rubygems load path
|
136
|
+
|
137
|
+
|
138
|
+
=== 0.6.4 / 2011-08-18
|
139
|
+
|
140
|
+
* Support WebSocket protocol used by Chrome 14 and Firefox 6
|
141
|
+
* Fix handling of multibyte characters in WebSocket messages on Node
|
142
|
+
* Improve message routing in Node memory engine to avoid false duplicates
|
143
|
+
|
144
|
+
|
145
|
+
=== 0.6.3 / 2011-07-10
|
146
|
+
|
147
|
+
* Use sequential message IDs to reduce memory usage on the client side
|
148
|
+
* Only send advice with handshake and connect responses
|
149
|
+
* Stop trying to publish /meta/* messages - no-one is listening and it breaks /**
|
150
|
+
* Fix bug causing invalid listeners to appear after a client reconnection
|
151
|
+
* Stop loading 'rubygems' within our library code
|
152
|
+
* Make sure we only queue a message for each client once in the Redis engine
|
153
|
+
* Use lists instead of sets for message queues in Redis
|
154
|
+
* Improve clean-up of expired clients in Redis engine
|
155
|
+
|
156
|
+
|
157
|
+
=== 0.6.2 / 2011-06-19
|
158
|
+
|
159
|
+
* Add authentication, database selection and namespacing to Redis engine
|
160
|
+
* Clean up all client data when removing clients from Redis
|
161
|
+
* Fix cross-origin-long-polling for OPTIONS-aware browsers
|
162
|
+
* Update secure WebSocket detection for recent Node versions
|
163
|
+
* Reinstate 'faye.client' field in Rack environment
|
164
|
+
|
165
|
+
|
166
|
+
=== 0.6.1 / 2011-06-06
|
167
|
+
|
168
|
+
* Fix cross-origin-long-polling support in RackAdapter
|
169
|
+
* Plug some potential memory leaks in Memory engine
|
170
|
+
|
171
|
+
|
172
|
+
=== 0.6.0 / 2011-05-21
|
173
|
+
|
174
|
+
* Extract core logic into the Engine class to support swappable backends
|
175
|
+
* Introduce a Redis-backed engine to support clustered web front-ends
|
176
|
+
* Use CORS for cross-domain long-polling
|
177
|
+
* Make server more resilient against bad requests, including empty message lists
|
178
|
+
* Perform subscription validation on the server and use errbacks to signal errors
|
179
|
+
* Prohibit publishing to wildcard channels
|
180
|
+
* Unsubscribing from a channel is now O(1) instead of O(N)
|
181
|
+
* Much more thorough and consistent unit test coverage of both versions
|
182
|
+
* Automatic integration tests using Terminus and TestSwarm
|
183
|
+
|
184
|
+
|
185
|
+
=== 0.5.5 / 2011-01-16
|
186
|
+
|
187
|
+
* Open a real socket to check for WebSocket usability, not just object detection
|
188
|
+
* Catch server-side errors when handshaking with WebSockets
|
189
|
+
|
190
|
+
|
191
|
+
=== 0.5.4 / 2010-12-19
|
192
|
+
|
193
|
+
* Add a #callback method to Subscriptions to detect when they become active
|
194
|
+
* Add :extensions option to RackAdapter to make it easier to extend middleware
|
195
|
+
* Detect secure WebSocket requests through the HTTP_X_FORWARDED_PROTO header
|
196
|
+
* Handle socket errors when sending WebSocket messages from NodeAdapter
|
197
|
+
* Use exponential backoff to reconnect client-side WebSockets to reduce CPU load
|
198
|
+
|
199
|
+
|
200
|
+
=== 0.5.3 / 2010-10-21
|
201
|
+
|
202
|
+
* Improve detection of wss: requirement for secure WebSocket connections
|
203
|
+
* Correctly use default ports (80,443) for server-side HTTP connections
|
204
|
+
* Support legacy application/x-www-form-urlencoded POST requests
|
205
|
+
* Delete unused Channel objects that have all their subscribers removed
|
206
|
+
* Fix resend/reconnect logic in WebSocket transport
|
207
|
+
* Keep client script in memory rather than reading it from disk every time
|
208
|
+
* Prevent error-adding extensions from breaking the core protocol
|
209
|
+
|
210
|
+
|
211
|
+
=== 0.5.2 / 2010-08-12
|
212
|
+
|
213
|
+
* Support draft-76 of the WebSocket protocol (FF4, Chrome 6)
|
214
|
+
* Reduce Connection::MAX_DELAY to improve latency
|
215
|
+
|
216
|
+
|
217
|
+
=== 0.5.1 / 2010-07-21
|
218
|
+
|
219
|
+
* Fix a publishing problem in Ruby LocalTransport
|
220
|
+
|
221
|
+
|
222
|
+
=== 0.5.0 / 2010-07-17
|
223
|
+
|
224
|
+
* Handle multiple event listeners bound to a channel
|
225
|
+
* Add extension system for adding domain-specific logic to the protocol
|
226
|
+
* Improve handling of client reconnections if the server goes down
|
227
|
+
* Change default polling interval to 0 (immediate reconnect)
|
228
|
+
* Add support for WebSockets (draft75 only) as a network transport
|
229
|
+
* Remove support for Ruby servers other than Thin
|
230
|
+
* Make client and server compatible with CometD (1.x and 2.0) components
|
231
|
+
* Improve clean-up of unused server-side connections
|
232
|
+
* Change Node API for adding Faye service to an HTTP server
|
233
|
+
|
234
|
+
|
235
|
+
=== 0.3.4 / 2010-06-20
|
236
|
+
|
237
|
+
* Stop local clients going into an infinite loop if a subscription block causes a reconnect
|
238
|
+
|
239
|
+
|
240
|
+
=== 0.3.3 / 2010-06-07
|
241
|
+
|
242
|
+
* Bring Node APIs up to date with 0.1.97
|
243
|
+
* Catch ECONNREFUSED errors in Node clients to withstand server outages
|
244
|
+
* Refactor the Server internals
|
245
|
+
|
246
|
+
|
247
|
+
=== 0.3.2 / 2010-04-04
|
248
|
+
|
249
|
+
* Fix problems with JSON serialization when Prototype, MooTools present
|
250
|
+
* Make the client reconnect if it doesn't hear from the server after a timeout
|
251
|
+
* Stop JavaScript server returning NaN for advice.interval
|
252
|
+
* Make Ruby server return an integer for advice.interval
|
253
|
+
* Ensure EventMachine is running before handling messages
|
254
|
+
* Handle 'data' and 'end' events properly in Node HTTP API
|
255
|
+
* Switch to application/json for content types and stop using querystring format in POST bodies
|
256
|
+
* Respond to any URL path under the mount point, not just the exact match
|
257
|
+
|
258
|
+
|
259
|
+
=== 0.3.1 / 2010-03-09
|
260
|
+
|
261
|
+
* Pass client down through Rack stack as env['faye.client']
|
262
|
+
* Refactor some JavaScript internals to mirror Ruby codebase
|
263
|
+
|
264
|
+
|
265
|
+
=== 0.3.0 / 2010-03-01
|
266
|
+
|
267
|
+
* Add server-side clients for Node.js and Ruby environments
|
268
|
+
* Clients support both HTTP and in-process transports
|
269
|
+
* Fix ID generation in JavaScript version to 128-bit IDs
|
270
|
+
* Fix bug in interpretation of ** channel wildcard
|
271
|
+
* Users don't have to call #connect() on clients any more
|
272
|
+
* Fix timeout race conditions that were killing active connections
|
273
|
+
* Support new Node APIs from 0.1.29.
|
274
|
+
|
275
|
+
|
276
|
+
=== 0.2.2 / 2010-02-10
|
277
|
+
|
278
|
+
* Kick out requests with malformed JSON as 400s
|
279
|
+
|
280
|
+
|
281
|
+
=== 0.2.1 / 2010-02-04
|
282
|
+
|
283
|
+
* Fix server-side flushing of callback-polling connections
|
284
|
+
* Backend can be used cross-domain if running on Node or Thin
|
285
|
+
|
286
|
+
|
287
|
+
=== 0.2.0 / 2010-02-02
|
288
|
+
|
289
|
+
* Port server to JavaScript with an adapter for Node.js
|
290
|
+
* Support Thin's async responses in the Ruby version for complete non-blocking
|
291
|
+
* Fix some minor client-side bugs in transport choice
|
292
|
+
|
293
|
+
|
294
|
+
=== 0.1.1 / 2009-07-26
|
295
|
+
|
296
|
+
* Fix a broken client build
|
297
|
+
|
298
|
+
|
299
|
+
=== 0.1.0 / 2009-06-15
|
300
|
+
|
301
|
+
* Ruby Bayeux server and Rack adapter
|
302
|
+
* Internally evented using EventMachine, web frontend blocks
|
303
|
+
* JavaScript client with long-polling and callback-polling
|
304
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
= Faye
|
2
|
+
|
3
|
+
* http://faye.jcoglan.com
|
4
|
+
* http://groups.google.com/group/faye-users
|
5
|
+
* http://github.com/faye/faye
|
6
|
+
|
7
|
+
Faye is a set of tools for dirt-simple publish-subscribe messaging between web
|
8
|
+
clients. It ships with easy-to-use message routing servers for Node.js and Rack
|
9
|
+
applications, and clients that can be used on the server and in the browser.
|
10
|
+
|
11
|
+
See http://faye.jcoglan.com for documentation.
|
12
|
+
|
13
|
+
|
14
|
+
== Questions, issues, ideas
|
15
|
+
|
16
|
+
Please raise questions on the mailing list: http://groups.google.com/group/faye-users,
|
17
|
+
and feel free to announce and share ideas on Faye-related projects here too. I'd
|
18
|
+
appreciate it if we only use the GitHub issue tracker for bona fide bugs; You'll
|
19
|
+
probably get better and quicker answers to questions from the mailing list.
|
20
|
+
|
21
|
+
|
22
|
+
== Development
|
23
|
+
|
24
|
+
To hack on Faye, you'll need Ruby in order to build both the Gem and the NPM
|
25
|
+
package. There are also a few submodules we use for testing. The following
|
26
|
+
should get you up and running:
|
27
|
+
|
28
|
+
# Download the code from Git
|
29
|
+
git clone git://github.com/faye/faye.git
|
30
|
+
cd faye
|
31
|
+
git submodule update --init --recursive
|
32
|
+
|
33
|
+
# Install dependencies
|
34
|
+
bundle install
|
35
|
+
npm install
|
36
|
+
|
37
|
+
# Build Faye
|
38
|
+
bundle exec jake
|
39
|
+
|
40
|
+
# Run tests
|
41
|
+
bundle exec rspec -c spec/
|
42
|
+
node spec/node.js
|
43
|
+
|
44
|
+
# Install Ruby gem
|
45
|
+
gem build faye.gemspec
|
46
|
+
gem install faye-x.x.x.gem
|
47
|
+
|
48
|
+
# Install NPM package
|
49
|
+
npm install build
|
50
|
+
|
51
|
+
|
52
|
+
== To-do
|
53
|
+
|
54
|
+
* Provide reflection API for internal stats on channels, subscriptions, message queues
|
55
|
+
* (Maybe) build a monitoring GUI into the server
|
56
|
+
* Add sugar for authentication extensions for protected subscribe + publish
|
57
|
+
* Provide support for user-defined <tt>/service/*</tt> channels
|
58
|
+
* Let local server-side clients listen to <tt>/meta/*</tt> channels
|
59
|
+
|
60
|
+
|
61
|
+
== License
|
62
|
+
|
63
|
+
(The MIT License)
|
64
|
+
|
65
|
+
Copyright (c) 2009-2013 James Coglan and contributors
|
66
|
+
|
67
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
68
|
+
this software and associated documentation files (the 'Software'), to deal in
|
69
|
+
the Software without restriction, including without limitation the rights to use,
|
70
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
71
|
+
Software, and to permit persons to whom the Software is furnished to do so,
|
72
|
+
subject to the following conditions:
|
73
|
+
|
74
|
+
The above copyright notice and this permission notice shall be included in all
|
75
|
+
copies or substantial portions of the Software.
|
76
|
+
|
77
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
78
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
79
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
80
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
81
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
82
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
83
|
+
|
@@ -0,0 +1,2 @@
|
|
1
|
+
'use strict';var Faye={VERSION:'0.8.9',BAYEUX_VERSION:'1.0',ID_LENGTH:160,JSONP_CALLBACK:'jsonpcallback',CONNECTION_TYPES:['long-polling','cross-origin-long-polling','callback-polling','websocket','eventsource','in-process'],MANDATORY_CONNECTION_TYPES:['long-polling','callback-polling','in-process'],ENV:(typeof global==='undefined')?window:global,extend:function(a,b,d){if(!b)return a;for(var f in b){if(!b.hasOwnProperty(f))continue;if(a.hasOwnProperty(f)&&d===false)continue;if(a[f]!==b[f])a[f]=b[f]}return a},random:function(a){a=a||this.ID_LENGTH;if(a>32){var b=Math.ceil(a/32),d='';while(b--)d+=this.random(32);var f=d.split(''),g='';while(f.length>0)g+=f.pop();return g}var h=Math.pow(2,a)-1,i=h.toString(36).length,d=Math.floor(Math.random()*h).toString(36);while(d.length<i)d='0'+d;return d},clientIdFromMessages:function(a){var b=[].concat(a)[0];return b&&b.clientId},copyObject:function(a){var b,d,f;if(a instanceof Array){b=[];d=a.length;while(d--)b[d]=Faye.copyObject(a[d]);return b}else if(typeof a==='object'){b=(a===null)?null:{};for(f in a)b[f]=Faye.copyObject(a[f]);return b}else{return a}},commonElement:function(a,b){for(var d=0,f=a.length;d<f;d++){if(this.indexOf(b,a[d])!==-1)return a[d]}return null},indexOf:function(a,b){if(a.indexOf)return a.indexOf(b);for(var d=0,f=a.length;d<f;d++){if(a[d]===b)return d}return-1},map:function(a,b,d){if(a.map)return a.map(b,d);var f=[];if(a instanceof Array){for(var g=0,h=a.length;g<h;g++){f.push(b.call(d||null,a[g],g))}}else{for(var i in a){if(!a.hasOwnProperty(i))continue;f.push(b.call(d||null,i,a[i]))}}return f},filter:function(a,b,d){var f=[];for(var g=0,h=a.length;g<h;g++){if(b.call(d||null,a[g],g))f.push(a[g])}return f},asyncEach:function(a,b,d,f){var g=a.length,h=-1,i=0,k=false;var j=function(){i-=1;h+=1;if(h===g)return d&&d.call(f);b(a[h],n)};var m=function(){if(k)return;k=true;while(i>0)j();k=false};var n=function(){i+=1;m()};n()},toJSON:function(a){if(this.stringify)return this.stringify(a,function(key,value){return(this[key]instanceof Array)?this[key]:value});return JSON.stringify(a)},logger:function(a){if(typeof console!=='undefined')console.log(a)},timestamp:function(){var b=new Date(),d=b.getFullYear(),f=b.getMonth()+1,g=b.getDate(),h=b.getHours(),i=b.getMinutes(),k=b.getSeconds();var j=function(a){return a<10?'0'+a:String(a)};return j(d)+'-'+j(f)+'-'+j(g)+' '+j(h)+':'+j(i)+':'+j(k)}};if(typeof window!=='undefined')window.Faye=Faye;Faye.Class=function(a,b){if(typeof a!=='function'){b=a;a=Object}var d=function(){if(!this.initialize)return this;return this.initialize.apply(this,arguments)||this};var f=function(){};f.prototype=a.prototype;d.prototype=new f();Faye.extend(d.prototype,b);return d};Faye.Namespace=Faye.Class({initialize:function(){this._e={}},exists:function(a){return this._e.hasOwnProperty(a)},generate:function(){var a=Faye.random();while(this._e.hasOwnProperty(a))a=Faye.random();return this._e[a]=a},release:function(a){delete this._e[a]}});Faye.Error=Faye.Class({initialize:function(a,b,d){this.code=a;this.params=Array.prototype.slice.call(b);this.message=d},toString:function(){return this.code+':'+this.params.join(',')+':'+this.message}});Faye.Error.parse=function(a){a=a||'';if(!Faye.Grammar.ERROR.test(a))return new this(null,[],a);var b=a.split(':'),d=parseInt(b[0]),f=b[1].split(','),a=b[2];return new this(d,f,a)};Faye.Error.versionMismatch=function(){return new this(300,arguments,"Version mismatch").toString()};Faye.Error.conntypeMismatch=function(){return new this(301,arguments,"Connection types not supported").toString()};Faye.Error.extMismatch=function(){return new this(302,arguments,"Extension mismatch").toString()};Faye.Error.badRequest=function(){return new this(400,arguments,"Bad request").toString()};Faye.Error.clientUnknown=function(){return new this(401,arguments,"Unknown client").toString()};Faye.Error.parameterMissing=function(){return new this(402,arguments,"Missing required parameter").toString()};Faye.Error.channelForbidden=function(){return new this(403,arguments,"Forbidden channel").toString()};Faye.Error.channelUnknown=function(){return new this(404,arguments,"Unknown channel").toString()};Faye.Error.channelInvalid=function(){return new this(405,arguments,"Invalid channel").toString()};Faye.Error.extUnknown=function(){return new this(406,arguments,"Unknown extension").toString()};Faye.Error.publishFailed=function(){return new this(407,arguments,"Failed to publish").toString()};Faye.Error.serverError=function(){return new this(500,arguments,"Internal server error").toString()};Faye.Deferrable={callback:function(a,b){if(!a)return;if(this._v==='succeeded')return a.apply(b,this._j);this._k=this._k||[];this._k.push([a,b])},timeout:function(a,b){var d=this;var f=Faye.ENV.setTimeout(function(){d.setDeferredStatus('failed',b)},a*1000);this._w=f},errback:function(a,b){if(!a)return;if(this._v==='failed')return a.apply(b,this._j);this._l=this._l||[];this._l.push([a,b])},setDeferredStatus:function(){if(this._w)Faye.ENV.clearTimeout(this._w);var a=Array.prototype.slice.call(arguments),b=a.shift(),d;this._v=b;this._j=a;if(b==='succeeded')d=this._k;else if(b==='failed')d=this._l;if(!d)return;var f;while(f=d.shift())f[0].apply(f[1],this._j)}};Faye.Publisher={countListeners:function(a){if(!this._4||!this._4[a])return 0;return this._4[a].length},bind:function(a,b,d){this._4=this._4||{};var f=this._4[a]=this._4[a]||[];f.push([b,d])},unbind:function(a,b,d){if(!this._4||!this._4[a])return;if(!b){delete this._4[a];return}var f=this._4[a],g=f.length;while(g--){if(b!==f[g][0])continue;if(d&&f[g][1]!==d)continue;f.splice(g,1)}},trigger:function(){var a=Array.prototype.slice.call(arguments),b=a.shift();if(!this._4||!this._4[b])return;var d=this._4[b].slice(),f;for(var g=0,h=d.length;g<h;g++){f=d[g];f[0].apply(f[1],a)}}};Faye.Timeouts={addTimeout:function(a,b,d,f){this._6=this._6||{};if(this._6.hasOwnProperty(a))return;var g=this;this._6[a]=Faye.ENV.setTimeout(function(){delete g._6[a];d.call(f)},1000*b)},removeTimeout:function(a){this._6=this._6||{};var b=this._6[a];if(!b)return;clearTimeout(b);delete this._6[a]}};Faye.Logging={LOG_LEVELS:{error:3,warn:2,info:1,debug:0},logLevel:'error',log:function(a,b){if(!Faye.logger)return;var d=Faye.Logging.LOG_LEVELS;if(d[Faye.Logging.logLevel]>d[b])return;var a=Array.prototype.slice.apply(a),f=' ['+b.toUpperCase()+'] [Faye',g=this.className,h=a.shift().replace(/\?/g,function(){try{return Faye.toJSON(a.shift())}catch(e){return'[Object]'}});for(var i in Faye){if(g)continue;if(typeof Faye[i]!=='function')continue;if(this instanceof Faye[i])g=i}if(g)f+='.'+g;f+='] ';Faye.logger(Faye.timestamp()+f+h)}};(function(){for(var d in Faye.Logging.LOG_LEVELS)(function(a,b){Faye.Logging[a]=function(){this.log(arguments,a)}})(d,Faye.Logging.LOG_LEVELS[d])})();Faye.Grammar={LOWALPHA:/^[a-z]$/,UPALPHA:/^[A-Z]$/,ALPHA:/^([a-z]|[A-Z])$/,DIGIT:/^[0-9]$/,ALPHANUM:/^(([a-z]|[A-Z])|[0-9])$/,MARK:/^(\-|\_|\!|\~|\(|\)|\$|\@)$/,STRING:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*$/,TOKEN:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+$/,INTEGER:/^([0-9])+$/,CHANNEL_SEGMENT:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+$/,CHANNEL_SEGMENTS:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/,CHANNEL_NAME:/^\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/,WILD_CARD:/^\*{1,2}$/,CHANNEL_PATTERN:/^(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*\/\*{1,2}$/,VERSION_ELEMENT:/^(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\-|\_))*$/,VERSION:/^([0-9])+(\.(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\-|\_))*)*$/,CLIENT_ID:/^((([a-z]|[A-Z])|[0-9]))+$/,ID:/^((([a-z]|[A-Z])|[0-9]))+$/,ERROR_MESSAGE:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*$/,ERROR_ARGS:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*(,(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)*$/,ERROR_CODE:/^[0-9][0-9][0-9]$/,ERROR:/^([0-9][0-9][0-9]:(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*(,(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)*:(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*|[0-9][0-9][0-9]::(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)$/};Faye.Extensible={addExtension:function(a){this._7=this._7||[];this._7.push(a);if(a.added)a.added(this)},removeExtension:function(a){if(!this._7)return;var b=this._7.length;while(b--){if(this._7[b]!==a)continue;this._7.splice(b,1);if(a.removed)a.removed(this)}},pipeThroughExtensions:function(d,f,g,h){this.debug('Passing through ? extensions: ?',d,f);if(!this._7)return g.call(h,f);var i=this._7.slice();var k=function(a){if(!a)return g.call(h,a);var b=i.shift();if(!b)return g.call(h,a);if(b[d])b[d](a,k);else k(a)};k(f)}};Faye.extend(Faye.Extensible,Faye.Logging);Faye.Channel=Faye.Class({initialize:function(a){this.id=this.name=a},push:function(a){this.trigger('message',a)},isUnused:function(){return this.countListeners('message')===0}});Faye.extend(Faye.Channel.prototype,Faye.Publisher);Faye.extend(Faye.Channel,{HANDSHAKE:'/meta/handshake',CONNECT:'/meta/connect',SUBSCRIBE:'/meta/subscribe',UNSUBSCRIBE:'/meta/unsubscribe',DISCONNECT:'/meta/disconnect',META:'meta',SERVICE:'service',expand:function(a){var b=this.parse(a),d=['/**',a];var f=b.slice();f[f.length-1]='*';d.push(this.unparse(f));for(var g=1,h=b.length;g<h;g++){f=b.slice(0,g);f.push('**');d.push(this.unparse(f))}return d},isValid:function(a){return Faye.Grammar.CHANNEL_NAME.test(a)||Faye.Grammar.CHANNEL_PATTERN.test(a)},parse:function(a){if(!this.isValid(a))return null;return a.split('/').slice(1)},unparse:function(a){return'/'+a.join('/')},isMeta:function(a){var b=this.parse(a);return b?(b[0]===this.META):null},isService:function(a){var b=this.parse(a);return b?(b[0]===this.SERVICE):null},isSubscribable:function(a){if(!this.isValid(a))return null;return!this.isMeta(a)&&!this.isService(a)},Set:Faye.Class({initialize:function(){this._2={}},getKeys:function(){var a=[];for(var b in this._2)a.push(b);return a},remove:function(a){delete this._2[a]},hasSubscription:function(a){return this._2.hasOwnProperty(a)},subscribe:function(a,b,d){if(!b)return;var f;for(var g=0,h=a.length;g<h;g++){f=a[g];var i=this._2[f]=this._2[f]||new Faye.Channel(f);i.bind('message',b,d)}},unsubscribe:function(a,b,d){var f=this._2[a];if(!f)return false;f.unbind('message',b,d);if(f.isUnused()){this.remove(a);return true}else{return false}},distributeMessage:function(a){var b=Faye.Channel.expand(a.channel);for(var d=0,f=b.length;d<f;d++){var g=this._2[b[d]];if(g)g.trigger('message',a.data)}}})});Faye.Publication=Faye.Class(Faye.Deferrable);Faye.Subscription=Faye.Class({initialize:function(a,b,d,f){this._8=a;this._2=b;this._m=d;this._n=f;this._x=false},cancel:function(){if(this._x)return;this._8.unsubscribe(this._2,this._m,this._n);this._x=true},unsubscribe:function(){this.cancel()}});Faye.extend(Faye.Subscription.prototype,Faye.Deferrable);Faye.Client=Faye.Class({UNCONNECTED:1,CONNECTING:2,CONNECTED:3,DISCONNECTED:4,HANDSHAKE:'handshake',RETRY:'retry',NONE:'none',CONNECTION_TIMEOUT:60.0,DEFAULT_RETRY:5.0,DEFAULT_ENDPOINT:'/bayeux',INTERVAL:0.0,initialize:function(a,b){this.info('New client created for ?',a);this._f=b||{};this.endpoint=a||this.DEFAULT_ENDPOINT;this.endpoints=this._f.endpoints||{};this.transports={};this._D=Faye.CookieJar&&new Faye.CookieJar();this._y={};this._o=[];this.retry=this._f.retry||this.DEFAULT_RETRY;this._1=this.UNCONNECTED;this._2=new Faye.Channel.Set();this._g=0;this._p={};this._9={reconnect:this.RETRY,interval:1000*(this._f.interval||this.INTERVAL),timeout:1000*(this._f.timeout||this.CONNECTION_TIMEOUT)};if(Faye.Event)Faye.Event.on(Faye.ENV,'beforeunload',function(){if(Faye.indexOf(this._o,'autodisconnect')<0)this.disconnect()},this)},disable:function(a){this._o.push(a)},setHeader:function(a,b){this._y[a]=b},getClientId:function(){return this._0},getState:function(){switch(this._1){case this.UNCONNECTED:return'UNCONNECTED';case this.CONNECTING:return'CONNECTING';case this.CONNECTED:return'CONNECTED';case this.DISCONNECTED:return'DISCONNECTED'}},handshake:function(b,d){if(this._9.reconnect===this.NONE)return;if(this._1!==this.UNCONNECTED)return;this._1=this.CONNECTING;var f=this;this.info('Initiating handshake with ?',this.endpoint);this._z(Faye.MANDATORY_CONNECTION_TYPES);this._a({channel:Faye.Channel.HANDSHAKE,version:Faye.BAYEUX_VERSION,supportedConnectionTypes:[this._5.connectionType]},function(a){if(a.successful){this._1=this.CONNECTED;this._0=a.clientId;this._z(a.supportedConnectionTypes);this.info('Handshake successful: ?',this._0);this.subscribe(this._2.getKeys(),true);if(b)b.call(d)}else{this.info('Handshake unsuccessful');Faye.ENV.setTimeout(function(){f.handshake(b,d)},this._9.interval);this._1=this.UNCONNECTED}},this)},connect:function(a,b){if(this._9.reconnect===this.NONE)return;if(this._1===this.DISCONNECTED)return;if(this._1===this.UNCONNECTED)return this.handshake(function(){this.connect(a,b)},this);this.callback(a,b);if(this._1!==this.CONNECTED)return;this.info('Calling deferred actions for ?',this._0);this.setDeferredStatus('succeeded');this.setDeferredStatus('deferred');if(this._q)return;this._q=true;this.info('Initiating connection for ?',this._0);this._a({channel:Faye.Channel.CONNECT,clientId:this._0,connectionType:this._5.connectionType},this._A,this)},disconnect:function(){if(this._1!==this.CONNECTED)return;this._1=this.DISCONNECTED;this.info('Disconnecting ?',this._0);this._a({channel:Faye.Channel.DISCONNECT,clientId:this._0},function(a){if(a.successful)this._5.close()},this);this.info('Clearing channel listeners for ?',this._0);this._2=new Faye.Channel.Set()},subscribe:function(d,f,g){if(d instanceof Array)return Faye.map(d,function(c){return this.subscribe(c,f,g)},this);var h=new Faye.Subscription(this,d,f,g),i=(f===true),k=this._2.hasSubscription(d);if(k&&!i){this._2.subscribe([d],f,g);h.setDeferredStatus('succeeded');return h}this.connect(function(){this.info('Client ? attempting to subscribe to ?',this._0,d);if(!i)this._2.subscribe([d],f,g);this._a({channel:Faye.Channel.SUBSCRIBE,clientId:this._0,subscription:d},function(a){if(!a.successful){h.setDeferredStatus('failed',Faye.Error.parse(a.error));return this._2.unsubscribe(d,f,g)}var b=[].concat(a.subscription);this.info('Subscription acknowledged for ? to ?',this._0,b);h.setDeferredStatus('succeeded')},this)},this);return h},unsubscribe:function(d,f,g){if(d instanceof Array)return Faye.map(d,function(c){return this.unsubscribe(c,f,g)},this);var h=this._2.unsubscribe(d,f,g);if(!h)return;this.connect(function(){this.info('Client ? attempting to unsubscribe from ?',this._0,d);this._a({channel:Faye.Channel.UNSUBSCRIBE,clientId:this._0,subscription:d},function(a){if(!a.successful)return;var b=[].concat(a.subscription);this.info('Unsubscription acknowledged for ? from ?',this._0,b)},this)},this)},publish:function(b,d){var f=new Faye.Publication();this.connect(function(){this.info('Client ? queueing published message to ?: ?',this._0,b,d);this._a({channel:b,data:d,clientId:this._0},function(a){if(a.successful)f.setDeferredStatus('succeeded');else f.setDeferredStatus('failed',Faye.Error.parse(a.error))},this)},this);return f},receiveMessage:function(d){this.pipeThroughExtensions('incoming',d,function(a){if(!a)return;if(a.advice)this._E(a.advice);this._F(a);if(a.successful===undefined)return;var b=this._p[a.id];if(!b)return;delete this._p[a.id];b[0].call(b[1],a)},this)},_z:function(b){Faye.Transport.get(this,b,this._o,function(a){this.debug('Selected ? transport for ?',a.connectionType,a.endpoint);if(a===this._5)return;if(this._5)this._5.close();this._5=a;this._5.cookies=this._D;this._5.headers=this._y;a.bind('down',function(){if(this._b!==undefined&&!this._b)return;this._b=false;this.trigger('transport:down')},this);a.bind('up',function(){if(this._b!==undefined&&this._b)return;this._b=true;this.trigger('transport:up')},this)},this)},_a:function(b,d,f){b.id=this._G();if(d)this._p[b.id]=[d,f];this.pipeThroughExtensions('outgoing',b,function(a){if(!a)return;this._5.send(a,this._9.timeout/1000)},this)},_G:function(){this._g+=1;if(this._g>=Math.pow(2,32))this._g=0;return this._g.toString(36)},_E:function(a){Faye.extend(this._9,a);if(this._9.reconnect===this.HANDSHAKE&&this._1!==this.DISCONNECTED){this._1=this.UNCONNECTED;this._0=null;this._A()}},_F:function(a){if(!a.channel||a.data===undefined)return;this.info('Client ? calling listeners for ? with ?',this._0,a.channel,a.data);this._2.distributeMessage(a)},_H:function(){if(!this._q)return;this._q=null;this.info('Closed connection for ?',this._0)},_A:function(){this._H();var a=this;Faye.ENV.setTimeout(function(){a.connect()},this._9.interval)}});Faye.extend(Faye.Client.prototype,Faye.Deferrable);Faye.extend(Faye.Client.prototype,Faye.Publisher);Faye.extend(Faye.Client.prototype,Faye.Logging);Faye.extend(Faye.Client.prototype,Faye.Extensible);Faye.Transport=Faye.extend(Faye.Class({MAX_DELAY:0.0,batching:true,initialize:function(a,b){this._8=a;this.endpoint=b;this._c=[]},close:function(){},send:function(a,b){this.debug('Client ? sending message to ?: ?',this._8._0,this.endpoint,a);if(!this.batching)return this.request([a],b);this._c.push(a);this._I=b;if(a.channel===Faye.Channel.HANDSHAKE)return this.addTimeout('publish',0.01,this.flush,this);if(a.channel===Faye.Channel.CONNECT)this._r=a;if(this.shouldFlush&&this.shouldFlush(this._c))return this.flush();this.addTimeout('publish',this.MAX_DELAY,this.flush,this)},flush:function(){this.removeTimeout('publish');if(this._c.length>1&&this._r)this._r.advice={timeout:0};this.request(this._c,this._I);this._r=null;this._c=[]},receive:function(a){this.debug('Client ? received from ?: ?',this._8._0,this.endpoint,a);for(var b=0,d=a.length;b<d;b++){this._8.receiveMessage(a[b])}},retry:function(a,b){var d=false,f=this._8.retry*1000,g=this;return function(){if(d)return;d=true;Faye.ENV.setTimeout(function(){g.request(a,b)},f)}}}),{MAX_URL_LENGTH:2048,get:function(k,j,m,n,o){var l=k.endpoint;Faye.asyncEach(this._B,function(d,f){var g=d[0],h=d[1],i=k.endpoints[g]||l;if(Faye.indexOf(m,g)>=0)return f();if(Faye.indexOf(j,g)<0){h.isUsable(k,i,function(){});return f()}h.isUsable(k,i,function(a){if(!a)return f();var b=h.hasOwnProperty('create')?h.create(k,i):new h(k,i);n.call(o,b)})},function(){throw new Error('Could not find a usable connection type for '+l);})},register:function(a,b){this._B.push([a,b]);b.prototype.connectionType=a},_B:[]});Faye.extend(Faye.Transport.prototype,Faye.Logging);Faye.extend(Faye.Transport.prototype,Faye.Publisher);Faye.extend(Faye.Transport.prototype,Faye.Timeouts);Faye.Event={_h:[],on:function(a,b,d,f){var g=function(){d.call(f)};if(a.addEventListener)a.addEventListener(b,g,false);else a.attachEvent('on'+b,g);this._h.push({_i:a,_s:b,_m:d,_n:f,_C:g})},detach:function(a,b,d,f){var g=this._h.length,h;while(g--){h=this._h[g];if((a&&a!==h._i)||(b&&b!==h._s)||(d&&d!==h._m)||(f&&f!==h._n))continue;if(h._i.removeEventListener)h._i.removeEventListener(h._s,h._C,false);else h._i.detachEvent('on'+h._s,h._C);this._h.splice(g,1);h=null}}};Faye.Event.on(Faye.ENV,'unload',Faye.Event.detach,Faye.Event);Faye.URI=Faye.extend(Faye.Class({queryString:function(){var a=[];for(var b in this.params){if(!this.params.hasOwnProperty(b))continue;a.push(encodeURIComponent(b)+'='+encodeURIComponent(this.params[b]))}return a.join('&')},isSameOrigin:function(){var a=Faye.URI.parse(Faye.ENV.location.href,false);var b=(a.hostname!==this.hostname)||(a.port!==this.port)||(a.protocol!==this.protocol);return!b},toURL:function(){var a=this.queryString();return this.protocol+'//'+this.hostname+(this.port?':'+this.port:'')+this.pathname+(a?'?'+a:'')+this.hash}}),{parse:function(g,h){if(typeof g!=='string')return g;var i=new this(),k;var j=function(b,d,f){g=g.replace(d,function(a){i[b]=a;return''});if(i[b]===undefined)i[b]=f?Faye.ENV.location[b]:''};j('protocol',/^https?\:/,true);j('host',/^\/\/[^\/]+/,true);if(!/^\//.test(g))g=Faye.ENV.location.pathname.replace(/[^\/]*$/,'')+g;j('pathname',/^\/[^\?#]*/);j('search',/^\?[^#]*/);j('hash',/^#.*/);if(/^\/\//.test(i.host)){i.host=i.host.substr(2);k=i.host.split(':');i.hostname=k[0];i.port=k[1]||''}else{i.hostname=Faye.ENV.location.hostname;i.port=Faye.ENV.location.port}if(h===false){i.params={}}else{var m=i.search.replace(/^\?/,''),n=m?m.split('&'):[],o=n.length,l={};while(o--){k=n[o].split('=');l[decodeURIComponent(k[0]||'')]=decodeURIComponent(k[1]||'')}if(typeof h==='object')Faye.extend(l,h);i.params=l}return i}});if(!this.JSON){JSON={}}(function(){function m(a){return a<10?'0'+a:a}if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(a){return this.getUTCFullYear()+'-'+m(this.getUTCMonth()+1)+'-'+m(this.getUTCDate())+'T'+m(this.getUTCHours())+':'+m(this.getUTCMinutes())+':'+m(this.getUTCSeconds())+'Z'};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(a){return this.valueOf()}}var n=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,o=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,l,q,t={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},p;function s(d){o.lastIndex=0;return o.test(d)?'"'+d.replace(o,function(a){var b=t[a];return typeof b==='string'?b:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+d+'"'}function r(a,b){var d,f,g,h,i=l,k,j=b[a];if(j&&typeof j==='object'&&typeof j.toJSON==='function'){j=j.toJSON(a)}if(typeof p==='function'){j=p.call(b,a,j)}switch(typeof j){case'string':return s(j);case'number':return isFinite(j)?String(j):'null';case'boolean':case'null':return String(j);case'object':if(!j){return'null'}l+=q;k=[];if(Object.prototype.toString.apply(j)==='[object Array]'){h=j.length;for(d=0;d<h;d+=1){k[d]=r(d,j)||'null'}g=k.length===0?'[]':l?'[\n'+l+k.join(',\n'+l)+'\n'+i+']':'['+k.join(',')+']';l=i;return g}if(p&&typeof p==='object'){h=p.length;for(d=0;d<h;d+=1){f=p[d];if(typeof f==='string'){g=r(f,j);if(g){k.push(s(f)+(l?': ':':')+g)}}}}else{for(f in j){if(Object.hasOwnProperty.call(j,f)){g=r(f,j);if(g){k.push(s(f)+(l?': ':':')+g)}}}}g=k.length===0?'{}':l?'{\n'+l+k.join(',\n'+l)+'\n'+i+'}':'{'+k.join(',')+'}';l=i;return g}}Faye.stringify=function(a,b,d){var f;l='';q='';if(typeof d==='number'){for(f=0;f<d;f+=1){q+=' '}}else if(typeof d==='string'){q=d}p=b;if(b&&typeof b!=='function'&&(typeof b!=='object'||typeof b.length!=='number')){throw new Error('JSON.stringify');}return r('',{'':a})};if(typeof JSON.stringify!=='function'){JSON.stringify=Faye.stringify}if(typeof JSON.parse!=='function'){JSON.parse=function(h,i){var k;function j(a,b){var d,f,g=a[b];if(g&&typeof g==='object'){for(d in g){if(Object.hasOwnProperty.call(g,d)){f=j(g,d);if(f!==undefined){g[d]=f}else{delete g[d]}}}}return i.call(a,b,g)}n.lastIndex=0;if(n.test(h)){h=h.replace(n,function(a){return'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(h.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){k=eval('('+h+')');return typeof i==='function'?j({'':k},''):k}throw new SyntaxError('JSON.parse');}}}());Faye.Transport.WebSocket=Faye.extend(Faye.Class(Faye.Transport,{UNCONNECTED:1,CONNECTING:2,CONNECTED:3,batching:false,isUsable:function(a,b){this.callback(function(){a.call(b,true)});this.errback(function(){a.call(b,false)});this.connect()},request:function(b,d){if(b.length===0)return;this._d=this._d||{};for(var f=0,g=b.length;f<g;f++){this._d[b[f].id]=b[f]}this.callback(function(a){a.send(Faye.toJSON(b))});this.connect()},close:function(){if(!this._3)return;this._3.onclose=this._3.onerror=null;this._3.close();delete this._3;this.setDeferredStatus('deferred');this._1=this.UNCONNECTED},connect:function(){if(Faye.Transport.WebSocket._J)return;this._1=this._1||this.UNCONNECTED;if(this._1!==this.UNCONNECTED)return;this._1=this.CONNECTING;var g=Faye.Transport.WebSocket.getClass();if(!g)return this.setDeferredStatus('failed');this._3=new g(Faye.Transport.WebSocket.getSocketUrl(this.endpoint));var h=this;this._3.onopen=function(){h._1=h.CONNECTED;h._t=true;h.setDeferredStatus('succeeded',h._3);h.trigger('up')};this._3.onmessage=function(a){var b=JSON.parse(a.data);if(!b)return;b=[].concat(b);for(var d=0,f=b.length;d<f;d++){delete h._d[b[d].id]}h.receive(b)};this._3.onclose=this._3.onerror=function(){var a=(h._1===h.CONNECTED);h.setDeferredStatus('deferred');h._1=h.UNCONNECTED;h.close();if(a)return h.resend();if(!h._t)return h.setDeferredStatus('failed');var b=h._8.retry*1000;Faye.ENV.setTimeout(function(){h.connect()},b);h.trigger('down')}},resend:function(){if(!this._d)return;var d=Faye.map(this._d,function(a,b){return b});this.request(d)}}),{getSocketUrl:function(a){if(Faye.URI)a=Faye.URI.parse(a).toURL();return a.replace(/^http(s?):/ig,'ws$1:')},getClass:function(){return(Faye.WebSocket&&Faye.WebSocket.Client)||Faye.ENV.WebSocket||Faye.ENV.MozWebSocket},isUsable:function(a,b,d,f){this.create(a,b).isUsable(d,f)},create:function(a,b){var d=a.transports.websocket=a.transports.websocket||{};d[b]=d[b]||new this(a,b);return d[b]}});Faye.extend(Faye.Transport.WebSocket.prototype,Faye.Deferrable);Faye.Transport.register('websocket',Faye.Transport.WebSocket);if(Faye.Event)Faye.Event.on(Faye.ENV,'beforeunload',function(){Faye.Transport.WebSocket._J=true});Faye.Transport.EventSource=Faye.extend(Faye.Class(Faye.Transport,{initialize:function(b,d){Faye.Transport.prototype.initialize.call(this,b,d);if(!Faye.ENV.EventSource)return this.setDeferredStatus('failed');this._K=new Faye.Transport.XHR(b,d);var f=new EventSource(d+'/'+b.getClientId()),g=this;f.onopen=function(){g._t=true;g.setDeferredStatus('succeeded');g.trigger('up')};f.onerror=function(){if(g._t){g.trigger('down')}else{g.setDeferredStatus('failed');f.close()}};f.onmessage=function(a){g.receive(JSON.parse(a.data));g.trigger('up')};this._3=f},isUsable:function(a,b){this.callback(function(){a.call(b,true)});this.errback(function(){a.call(b,false)})},request:function(a,b){this._K.request(a,b)},close:function(){if(!this._3)return;this._3.onerror=null;this._3.close();delete this._3}}),{isUsable:function(b,d,f,g){var h=b.getClientId();if(!h)return f.call(g,false);Faye.Transport.XHR.isUsable(b,d,function(a){if(!a)return f.call(g,false);this.create(b,d).isUsable(f,g)},this)},create:function(a,b){var d=a.transports.eventsource=a.transports.eventsource||{},f=a.getClientId(),b=b+'/'+(f||'');d[b]=d[b]||new this(a,b);return d[b]}});Faye.extend(Faye.Transport.EventSource.prototype,Faye.Deferrable);Faye.Transport.register('eventsource',Faye.Transport.EventSource);Faye.Transport.XHR=Faye.extend(Faye.Class(Faye.Transport,{request:function(f,g){var h=this.retry(f,g),i=Faye.URI.parse(this.endpoint).pathname,k=this,j=Faye.ENV.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();j.open('POST',i,true);j.setRequestHeader('Content-Type','application/json');j.setRequestHeader('Pragma','no-cache');j.setRequestHeader('X-Requested-With','XMLHttpRequest');var m=this.headers;for(var n in m){if(!m.hasOwnProperty(n))continue;j.setRequestHeader(n,m[n])}var o=function(){j.abort()};Faye.Event.on(Faye.ENV,'beforeunload',o);var l=function(){Faye.Event.detach(Faye.ENV,'beforeunload',o);j.onreadystatechange=function(){};j=null};j.onreadystatechange=function(){if(j.readyState!==4)return;var a=null,b=j.status,d=((b>=200&&b<300)||b===304||b===1223);if(!d){l();h();return k.trigger('down')}try{a=JSON.parse(j.responseText)}catch(e){}l();if(a){k.receive(a);k.trigger('up')}else{h();k.trigger('down')}};j.send(Faye.toJSON(f))}}),{isUsable:function(a,b,d,f){d.call(f,Faye.URI.parse(b).isSameOrigin())}});Faye.Transport.register('long-polling',Faye.Transport.XHR);Faye.Transport.CORS=Faye.extend(Faye.Class(Faye.Transport,{request:function(b,d){var f=Faye.ENV.XDomainRequest?XDomainRequest:XMLHttpRequest,g=new f(),h=this.retry(b,d),i=this;g.open('POST',this.endpoint,true);if(g.setRequestHeader)g.setRequestHeader('Pragma','no-cache');var k=function(){if(!g)return false;g.onload=g.onerror=g.ontimeout=g.onprogress=null;g=null;Faye.ENV.clearTimeout(m);return true};g.onload=function(){var a=null;try{a=JSON.parse(g.responseText)}catch(e){}k();if(a){i.receive(a);i.trigger('up')}else{h();i.trigger('down')}};var j=function(){k();h();i.trigger('down')};var m=Faye.ENV.setTimeout(j,1.5*1000*d);g.onerror=j;g.ontimeout=j;g.onprogress=function(){};g.send('message='+encodeURIComponent(Faye.toJSON(b)))}}),{isUsable:function(a,b,d,f){if(Faye.URI.parse(b).isSameOrigin())return d.call(f,false);if(Faye.ENV.XDomainRequest)return d.call(f,Faye.URI.parse(b).protocol===Faye.URI.parse(Faye.ENV.location).protocol);if(Faye.ENV.XMLHttpRequest){var g=new Faye.ENV.XMLHttpRequest();return d.call(f,g.withCredentials!==undefined)}return d.call(f,false)}});Faye.Transport.register('cross-origin-long-polling',Faye.Transport.CORS);Faye.Transport.JSONP=Faye.extend(Faye.Class(Faye.Transport,{shouldFlush:function(a){var b={message:Faye.toJSON(a),jsonp:'__jsonp'+Faye.Transport.JSONP._u+'__'};var d=Faye.URI.parse(this.endpoint,b).toURL();return d.length>=Faye.Transport.MAX_URL_LENGTH},request:function(b,d){var f={message:Faye.toJSON(b)},g=document.getElementsByTagName('head')[0],h=document.createElement('script'),i=Faye.Transport.JSONP.getCallbackName(),k=Faye.URI.parse(this.endpoint,f),j=this.retry(b,d),m=this;Faye.ENV[i]=function(a){o();m.receive(a);m.trigger('up')};var n=Faye.ENV.setTimeout(function(){o();j();m.trigger('down')},1.5*1000*d);var o=function(){if(!Faye.ENV[i])return false;Faye.ENV[i]=undefined;try{delete Faye.ENV[i]}catch(e){}Faye.ENV.clearTimeout(n);h.parentNode.removeChild(h);return true};k.params.jsonp=i;h.type='text/javascript';h.src=k.toURL();g.appendChild(h)}}),{_u:0,getCallbackName:function(){this._u+=1;return'__jsonp'+this._u+'__'},isUsable:function(a,b,d,f){d.call(f,true)}});Faye.Transport.register('callback-polling',Faye.Transport.JSONP);
|
2
|
+
//@ sourceMappingURL=faye-browser-min.js.map
|
@@ -0,0 +1,8 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"file": "faye-browser-min.js",
|
4
|
+
"sourceRoot": "",
|
5
|
+
"sources": ["faye-browser.js"],
|
6
|
+
"names": ["_advice", "_callback", "_callbacks", "_cancelled", "_cbCount", "_channels", "_client", "_clientId", "_connectMessage", "_connectRequest", "_context", "_cookies", "_cycleConnection", "_deferredArgs", "_deferredStatus", "_deliverMessage", "_disabled", "_element", "_errbacks", "_everConnected", "_extensions", "_generateMessageId", "_handleAdvice", "_handler", "_headers", "_messageId", "_messages", "_options", "_outbox", "_registry", "_responseCallbacks", "_selectTransport", "_send", "_socket", "_state", "_subscribers", "_teardownConnection", "_this", "_timeout", "_timeouts", "_timer", "_transport", "_transportUp", "_transports", "_type", "_unloaded", "_used", "_xhr", "abort", "advice", "allowed", "args", "array", "banner", "bitlength", "bridge", "c", "callback", "callbackName", "callbacks", "called", "calls", "channel", "channels", "chars", "cleanUp", "client", "clone", "code", "connEndpoint", "connType", "consume", "context", "copy", "cx", "data", "date", "day", "dead", "delay", "dest", "disabled", "element", "endpoint", "escapable", "event", "eventName", "eventType", "extension", "extensions", "external", "f", "feature", "first", "force", "gap", "hasSubscribe", "head", "headers", "holder", "host", "hour", "i", "id", "indent", "infer", "isUsable", "iterate", "iterator", "j", "k", "key", "keys", "klass", "length", "level", "levels", "limit", "list", "lista", "listb", "listener", "listeners", "location", "loop", "looping", "match", "maxSize", "message", "messageArgs", "messages", "meta", "methods", "mind", "minute", "month", "msg", "n", "name", "names", "needle", "object", "onerror", "options", "overwrite", "pad", "pair", "pairs", "params", "parent", "parsedMessage", "partial", "parts", "path", "pattern", "pipe", "publication", "query", "quote", "register", "rep", "replacer", "response", "responses", "result", "resume", "retry", "reviver", "script", "second", "seconds", "segments", "self", "socket", "sockets", "source", "space", "stage", "status", "str", "string", "subscription", "successful", "text", "timeout", "timer", "transport", "transportTypes", "type", "uri", "url", "usable", "v", "value", "walk", "wasConnected", "wrapped", "ws", "xhr", "xhrClass", "year"],
|
7
|
+
"mappings": "CAAC,IAAI,QAEL,IAAI,MACF,gBAEA,qBACA,cACA,gBAAmB,eACnB,mBAAoB,KAAK,UAAW,MAAM,OAAO,KAAK,UAAW,SAAS,UAAW,YAAa,cAAe,GAAG,UAEpH,6BAA8B,KAAK,UAAW,SAAS,UAAW,GAAG,UAErE,KAAM,OAAO,UAAY,YAAc,OAAS,OAEhD,OAAQ,SAASgF,EAAM+F,EAAQ/B,GAC7B,IAAK+B,EAAQ,OAAO/F,EACpB,IAAK,IAAI+B,EAAI,GAAGgE,GACd,IAAKA,EAAO,eAAehE,GAAM,SACjC,GAAI/B,EAAK,eAAe+B,IAAQiC,IAAc,MAAO,SACrD,GAAIhE,EAAK+B,KAASgE,EAAOhE,GACvB/B,EAAK+B,GAAOgE,EAAOhE,GAEvB,OAAO/B,GAGT,OAAQ,SAAS1B,GACfA,EAAYA,GAAa,KAAK,UAC9B,GAAIA,MACF,IAAIkG,EAAS,KAAK,KAAKlG,MACnB8H,KACJ,MAAO5B,IAAS4B,GAAU,KAAK,WAC/B,IAAIpH,EAAQoH,EAAO,UAAWhB,KAC9B,MAAOpG,EAAM,SAAYoG,GAAUpG,EAAM,MACzC,OAAOoG,EAET,IAAI/C,EAAU,KAAK,MAAO/D,KACtByE,EAAUV,EAAM,aAAa,OAC7B+D,EAAU,KAAK,MAAM,KAAK,SAAW/D,GAAO,aAEhD,MAAO+D,EAAO,OAASrD,EAASqD,MAAeA,EAC/C,OAAOA,GAGT,qBAAsB,SAASlD,GAC7B,IAAIrC,KAAW,OAAOqC,MACtB,OAAOrC,GAASA,EAAM,UAGxB,WAAY,SAASgD,GACnB,IAAI1E,EAAOmC,EAAGS,EACd,GAAI8B,EAAO,WAAW,OACpB1E,KACAmC,EAAIuC,EAAO,OACX,MAAOvC,IAAKnC,E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AAQ,KAAK,YACpBA,EAAO,IAAO7C,EAAS,QACvB1B,EAAK,YAAYuE,OAGnBpK,KAEA,gBAAiB,WACf,KAAKA,MACL,OAAQ,SAAW,KAAKA,IAAY,KAGtC,SAAU,SAAS8D,EAAQiB,EAAU1B,EAAUe,GAC7Cf,EAAS,KAAKe,EAAS,SAI3B,KAAK,UAAU,UAAU,SAAS,SAAU,KAAK,UAAU;"
|
8
|
+
}
|
data/lib/faye-browser.js
ADDED
@@ -0,0 +1,2194 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var Faye = {
|
4
|
+
VERSION: '0.8.9',
|
5
|
+
|
6
|
+
BAYEUX_VERSION: '1.0',
|
7
|
+
ID_LENGTH: 160,
|
8
|
+
JSONP_CALLBACK: 'jsonpcallback',
|
9
|
+
CONNECTION_TYPES: ['long-polling', 'cross-origin-long-polling', 'callback-polling', 'websocket', 'eventsource', 'in-process'],
|
10
|
+
|
11
|
+
MANDATORY_CONNECTION_TYPES: ['long-polling', 'callback-polling', 'in-process'],
|
12
|
+
|
13
|
+
ENV: (typeof global === 'undefined') ? window : global,
|
14
|
+
|
15
|
+
extend: function(dest, source, overwrite) {
|
16
|
+
if (!source) return dest;
|
17
|
+
for (var key in source) {
|
18
|
+
if (!source.hasOwnProperty(key)) continue;
|
19
|
+
if (dest.hasOwnProperty(key) && overwrite === false) continue;
|
20
|
+
if (dest[key] !== source[key])
|
21
|
+
dest[key] = source[key];
|
22
|
+
}
|
23
|
+
return dest;
|
24
|
+
},
|
25
|
+
|
26
|
+
random: function(bitlength) {
|
27
|
+
bitlength = bitlength || this.ID_LENGTH;
|
28
|
+
if (bitlength > 32) {
|
29
|
+
var parts = Math.ceil(bitlength / 32),
|
30
|
+
string = '';
|
31
|
+
while (parts--) string += this.random(32);
|
32
|
+
var chars = string.split(''), result = '';
|
33
|
+
while (chars.length > 0) result += chars.pop();
|
34
|
+
return result;
|
35
|
+
}
|
36
|
+
var limit = Math.pow(2, bitlength) - 1,
|
37
|
+
maxSize = limit.toString(36).length,
|
38
|
+
string = Math.floor(Math.random() * limit).toString(36);
|
39
|
+
|
40
|
+
while (string.length < maxSize) string = '0' + string;
|
41
|
+
return string;
|
42
|
+
},
|
43
|
+
|
44
|
+
clientIdFromMessages: function(messages) {
|
45
|
+
var first = [].concat(messages)[0];
|
46
|
+
return first && first.clientId;
|
47
|
+
},
|
48
|
+
|
49
|
+
copyObject: function(object) {
|
50
|
+
var clone, i, key;
|
51
|
+
if (object instanceof Array) {
|
52
|
+
clone = [];
|
53
|
+
i = object.length;
|
54
|
+
while (i--) clone[i] = Faye.copyObject(object[i]);
|
55
|
+
return clone;
|
56
|
+
} else if (typeof object === 'object') {
|
57
|
+
clone = (object === null) ? null : {};
|
58
|
+
for (key in object) clone[key] = Faye.copyObject(object[key]);
|
59
|
+
return clone;
|
60
|
+
} else {
|
61
|
+
return object;
|
62
|
+
}
|
63
|
+
},
|
64
|
+
|
65
|
+
commonElement: function(lista, listb) {
|
66
|
+
for (var i = 0, n = lista.length; i < n; i++) {
|
67
|
+
if (this.indexOf(listb, lista[i]) !== -1)
|
68
|
+
return lista[i];
|
69
|
+
}
|
70
|
+
return null;
|
71
|
+
},
|
72
|
+
|
73
|
+
indexOf: function(list, needle) {
|
74
|
+
if (list.indexOf) return list.indexOf(needle);
|
75
|
+
|
76
|
+
for (var i = 0, n = list.length; i < n; i++) {
|
77
|
+
if (list[i] === needle) return i;
|
78
|
+
}
|
79
|
+
return -1;
|
80
|
+
},
|
81
|
+
|
82
|
+
map: function(object, callback, context) {
|
83
|
+
if (object.map) return object.map(callback, context);
|
84
|
+
var result = [];
|
85
|
+
|
86
|
+
if (object instanceof Array) {
|
87
|
+
for (var i = 0, n = object.length; i < n; i++) {
|
88
|
+
result.push(callback.call(context || null, object[i], i));
|
89
|
+
}
|
90
|
+
} else {
|
91
|
+
for (var key in object) {
|
92
|
+
if (!object.hasOwnProperty(key)) continue;
|
93
|
+
result.push(callback.call(context || null, key, object[key]));
|
94
|
+
}
|
95
|
+
}
|
96
|
+
return result;
|
97
|
+
},
|
98
|
+
|
99
|
+
filter: function(array, callback, context) {
|
100
|
+
var result = [];
|
101
|
+
for (var i = 0, n = array.length; i < n; i++) {
|
102
|
+
if (callback.call(context || null, array[i], i))
|
103
|
+
result.push(array[i]);
|
104
|
+
}
|
105
|
+
return result;
|
106
|
+
},
|
107
|
+
|
108
|
+
asyncEach: function(list, iterator, callback, context) {
|
109
|
+
var n = list.length,
|
110
|
+
i = -1,
|
111
|
+
calls = 0,
|
112
|
+
looping = false;
|
113
|
+
|
114
|
+
var iterate = function() {
|
115
|
+
calls -= 1;
|
116
|
+
i += 1;
|
117
|
+
if (i === n) return callback && callback.call(context);
|
118
|
+
iterator(list[i], resume);
|
119
|
+
};
|
120
|
+
|
121
|
+
var loop = function() {
|
122
|
+
if (looping) return;
|
123
|
+
looping = true;
|
124
|
+
while (calls > 0) iterate();
|
125
|
+
looping = false;
|
126
|
+
};
|
127
|
+
|
128
|
+
var resume = function() {
|
129
|
+
calls += 1;
|
130
|
+
loop();
|
131
|
+
};
|
132
|
+
resume();
|
133
|
+
},
|
134
|
+
|
135
|
+
// http://assanka.net/content/tech/2009/09/02/json2-js-vs-prototype/
|
136
|
+
toJSON: function(object) {
|
137
|
+
if (this.stringify)
|
138
|
+
return this.stringify(object, function(key, value) {
|
139
|
+
return (this[key] instanceof Array)
|
140
|
+
? this[key]
|
141
|
+
: value;
|
142
|
+
});
|
143
|
+
|
144
|
+
return JSON.stringify(object);
|
145
|
+
},
|
146
|
+
|
147
|
+
logger: function(message) {
|
148
|
+
if (typeof console !== 'undefined') console.log(message);
|
149
|
+
},
|
150
|
+
|
151
|
+
timestamp: function() {
|
152
|
+
var date = new Date(),
|
153
|
+
year = date.getFullYear(),
|
154
|
+
month = date.getMonth() + 1,
|
155
|
+
day = date.getDate(),
|
156
|
+
hour = date.getHours(),
|
157
|
+
minute = date.getMinutes(),
|
158
|
+
second = date.getSeconds();
|
159
|
+
|
160
|
+
var pad = function(n) {
|
161
|
+
return n < 10 ? '0' + n : String(n);
|
162
|
+
};
|
163
|
+
|
164
|
+
return pad(year) + '-' + pad(month) + '-' + pad(day) + ' ' +
|
165
|
+
pad(hour) + ':' + pad(minute) + ':' + pad(second);
|
166
|
+
}
|
167
|
+
};
|
168
|
+
|
169
|
+
if (typeof window !== 'undefined')
|
170
|
+
window.Faye = Faye;
|
171
|
+
|
172
|
+
|
173
|
+
Faye.Class = function(parent, methods) {
|
174
|
+
if (typeof parent !== 'function') {
|
175
|
+
methods = parent;
|
176
|
+
parent = Object;
|
177
|
+
}
|
178
|
+
|
179
|
+
var klass = function() {
|
180
|
+
if (!this.initialize) return this;
|
181
|
+
return this.initialize.apply(this, arguments) || this;
|
182
|
+
};
|
183
|
+
|
184
|
+
var bridge = function() {};
|
185
|
+
bridge.prototype = parent.prototype;
|
186
|
+
|
187
|
+
klass.prototype = new bridge();
|
188
|
+
Faye.extend(klass.prototype, methods);
|
189
|
+
|
190
|
+
return klass;
|
191
|
+
};
|
192
|
+
|
193
|
+
|
194
|
+
Faye.Namespace = Faye.Class({
|
195
|
+
initialize: function() {
|
196
|
+
this._used = {};
|
197
|
+
},
|
198
|
+
|
199
|
+
exists: function(id) {
|
200
|
+
return this._used.hasOwnProperty(id);
|
201
|
+
},
|
202
|
+
|
203
|
+
generate: function() {
|
204
|
+
var name = Faye.random();
|
205
|
+
while (this._used.hasOwnProperty(name))
|
206
|
+
name = Faye.random();
|
207
|
+
return this._used[name] = name;
|
208
|
+
},
|
209
|
+
|
210
|
+
release: function(id) {
|
211
|
+
delete this._used[id];
|
212
|
+
}
|
213
|
+
});
|
214
|
+
|
215
|
+
|
216
|
+
Faye.Error = Faye.Class({
|
217
|
+
initialize: function(code, params, message) {
|
218
|
+
this.code = code;
|
219
|
+
this.params = Array.prototype.slice.call(params);
|
220
|
+
this.message = message;
|
221
|
+
},
|
222
|
+
|
223
|
+
toString: function() {
|
224
|
+
return this.code + ':' +
|
225
|
+
this.params.join(',') + ':' +
|
226
|
+
this.message;
|
227
|
+
}
|
228
|
+
});
|
229
|
+
|
230
|
+
Faye.Error.parse = function(message) {
|
231
|
+
message = message || '';
|
232
|
+
if (!Faye.Grammar.ERROR.test(message)) return new this(null, [], message);
|
233
|
+
|
234
|
+
var parts = message.split(':'),
|
235
|
+
code = parseInt(parts[0]),
|
236
|
+
params = parts[1].split(','),
|
237
|
+
message = parts[2];
|
238
|
+
|
239
|
+
return new this(code, params, message);
|
240
|
+
};
|
241
|
+
|
242
|
+
|
243
|
+
Faye.Error.versionMismatch = function() {
|
244
|
+
return new this(300, arguments, "Version mismatch").toString();
|
245
|
+
};
|
246
|
+
|
247
|
+
Faye.Error.conntypeMismatch = function() {
|
248
|
+
return new this(301, arguments, "Connection types not supported").toString();
|
249
|
+
};
|
250
|
+
|
251
|
+
Faye.Error.extMismatch = function() {
|
252
|
+
return new this(302, arguments, "Extension mismatch").toString();
|
253
|
+
};
|
254
|
+
|
255
|
+
Faye.Error.badRequest = function() {
|
256
|
+
return new this(400, arguments, "Bad request").toString();
|
257
|
+
};
|
258
|
+
|
259
|
+
Faye.Error.clientUnknown = function() {
|
260
|
+
return new this(401, arguments, "Unknown client").toString();
|
261
|
+
};
|
262
|
+
|
263
|
+
Faye.Error.parameterMissing = function() {
|
264
|
+
return new this(402, arguments, "Missing required parameter").toString();
|
265
|
+
};
|
266
|
+
|
267
|
+
Faye.Error.channelForbidden = function() {
|
268
|
+
return new this(403, arguments, "Forbidden channel").toString();
|
269
|
+
};
|
270
|
+
|
271
|
+
Faye.Error.channelUnknown = function() {
|
272
|
+
return new this(404, arguments, "Unknown channel").toString();
|
273
|
+
};
|
274
|
+
|
275
|
+
Faye.Error.channelInvalid = function() {
|
276
|
+
return new this(405, arguments, "Invalid channel").toString();
|
277
|
+
};
|
278
|
+
|
279
|
+
Faye.Error.extUnknown = function() {
|
280
|
+
return new this(406, arguments, "Unknown extension").toString();
|
281
|
+
};
|
282
|
+
|
283
|
+
Faye.Error.publishFailed = function() {
|
284
|
+
return new this(407, arguments, "Failed to publish").toString();
|
285
|
+
};
|
286
|
+
|
287
|
+
Faye.Error.serverError = function() {
|
288
|
+
return new this(500, arguments, "Internal server error").toString();
|
289
|
+
};
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
Faye.Deferrable = {
|
294
|
+
callback: function(callback, context) {
|
295
|
+
if (!callback) return;
|
296
|
+
|
297
|
+
if (this._deferredStatus === 'succeeded')
|
298
|
+
return callback.apply(context, this._deferredArgs);
|
299
|
+
|
300
|
+
this._callbacks = this._callbacks || [];
|
301
|
+
this._callbacks.push([callback, context]);
|
302
|
+
},
|
303
|
+
|
304
|
+
timeout: function(seconds, message) {
|
305
|
+
var _this = this;
|
306
|
+
var timer = Faye.ENV.setTimeout(function() {
|
307
|
+
_this.setDeferredStatus('failed', message);
|
308
|
+
}, seconds * 1000);
|
309
|
+
this._timer = timer;
|
310
|
+
},
|
311
|
+
|
312
|
+
errback: function(callback, context) {
|
313
|
+
if (!callback) return;
|
314
|
+
|
315
|
+
if (this._deferredStatus === 'failed')
|
316
|
+
return callback.apply(context, this._deferredArgs);
|
317
|
+
|
318
|
+
this._errbacks = this._errbacks || [];
|
319
|
+
this._errbacks.push([callback, context]);
|
320
|
+
},
|
321
|
+
|
322
|
+
setDeferredStatus: function() {
|
323
|
+
if (this._timer)
|
324
|
+
Faye.ENV.clearTimeout(this._timer);
|
325
|
+
|
326
|
+
var args = Array.prototype.slice.call(arguments),
|
327
|
+
status = args.shift(),
|
328
|
+
callbacks;
|
329
|
+
|
330
|
+
this._deferredStatus = status;
|
331
|
+
this._deferredArgs = args;
|
332
|
+
|
333
|
+
if (status === 'succeeded')
|
334
|
+
callbacks = this._callbacks;
|
335
|
+
else if (status === 'failed')
|
336
|
+
callbacks = this._errbacks;
|
337
|
+
|
338
|
+
if (!callbacks) return;
|
339
|
+
|
340
|
+
var callback;
|
341
|
+
while (callback = callbacks.shift())
|
342
|
+
callback[0].apply(callback[1], this._deferredArgs);
|
343
|
+
}
|
344
|
+
};
|
345
|
+
|
346
|
+
|
347
|
+
Faye.Publisher = {
|
348
|
+
countListeners: function(eventType) {
|
349
|
+
if (!this._subscribers || !this._subscribers[eventType]) return 0;
|
350
|
+
return this._subscribers[eventType].length;
|
351
|
+
},
|
352
|
+
|
353
|
+
bind: function(eventType, listener, context) {
|
354
|
+
this._subscribers = this._subscribers || {};
|
355
|
+
var list = this._subscribers[eventType] = this._subscribers[eventType] || [];
|
356
|
+
list.push([listener, context]);
|
357
|
+
},
|
358
|
+
|
359
|
+
unbind: function(eventType, listener, context) {
|
360
|
+
if (!this._subscribers || !this._subscribers[eventType]) return;
|
361
|
+
|
362
|
+
if (!listener) {
|
363
|
+
delete this._subscribers[eventType];
|
364
|
+
return;
|
365
|
+
}
|
366
|
+
var list = this._subscribers[eventType],
|
367
|
+
i = list.length;
|
368
|
+
|
369
|
+
while (i--) {
|
370
|
+
if (listener !== list[i][0]) continue;
|
371
|
+
if (context && list[i][1] !== context) continue;
|
372
|
+
list.splice(i,1);
|
373
|
+
}
|
374
|
+
},
|
375
|
+
|
376
|
+
trigger: function() {
|
377
|
+
var args = Array.prototype.slice.call(arguments),
|
378
|
+
eventType = args.shift();
|
379
|
+
|
380
|
+
if (!this._subscribers || !this._subscribers[eventType]) return;
|
381
|
+
|
382
|
+
var listeners = this._subscribers[eventType].slice(),
|
383
|
+
listener;
|
384
|
+
|
385
|
+
for (var i = 0, n = listeners.length; i < n; i++) {
|
386
|
+
listener = listeners[i];
|
387
|
+
listener[0].apply(listener[1], args);
|
388
|
+
}
|
389
|
+
}
|
390
|
+
};
|
391
|
+
|
392
|
+
|
393
|
+
Faye.Timeouts = {
|
394
|
+
addTimeout: function(name, delay, callback, context) {
|
395
|
+
this._timeouts = this._timeouts || {};
|
396
|
+
if (this._timeouts.hasOwnProperty(name)) return;
|
397
|
+
var self = this;
|
398
|
+
this._timeouts[name] = Faye.ENV.setTimeout(function() {
|
399
|
+
delete self._timeouts[name];
|
400
|
+
callback.call(context);
|
401
|
+
}, 1000 * delay);
|
402
|
+
},
|
403
|
+
|
404
|
+
removeTimeout: function(name) {
|
405
|
+
this._timeouts = this._timeouts || {};
|
406
|
+
var timeout = this._timeouts[name];
|
407
|
+
if (!timeout) return;
|
408
|
+
clearTimeout(timeout);
|
409
|
+
delete this._timeouts[name];
|
410
|
+
}
|
411
|
+
};
|
412
|
+
|
413
|
+
|
414
|
+
Faye.Logging = {
|
415
|
+
LOG_LEVELS: {
|
416
|
+
error: 3,
|
417
|
+
warn: 2,
|
418
|
+
info: 1,
|
419
|
+
debug: 0
|
420
|
+
},
|
421
|
+
|
422
|
+
logLevel: 'error',
|
423
|
+
|
424
|
+
log: function(messageArgs, level) {
|
425
|
+
if (!Faye.logger) return;
|
426
|
+
|
427
|
+
var levels = Faye.Logging.LOG_LEVELS;
|
428
|
+
if (levels[Faye.Logging.logLevel] > levels[level]) return;
|
429
|
+
|
430
|
+
var messageArgs = Array.prototype.slice.apply(messageArgs),
|
431
|
+
banner = ' [' + level.toUpperCase() + '] [Faye',
|
432
|
+
klass = this.className,
|
433
|
+
|
434
|
+
message = messageArgs.shift().replace(/\?/g, function() {
|
435
|
+
try {
|
436
|
+
return Faye.toJSON(messageArgs.shift());
|
437
|
+
} catch (e) {
|
438
|
+
return '[Object]';
|
439
|
+
}
|
440
|
+
});
|
441
|
+
|
442
|
+
for (var key in Faye) {
|
443
|
+
if (klass) continue;
|
444
|
+
if (typeof Faye[key] !== 'function') continue;
|
445
|
+
if (this instanceof Faye[key]) klass = key;
|
446
|
+
}
|
447
|
+
if (klass) banner += '.' + klass;
|
448
|
+
banner += '] ';
|
449
|
+
|
450
|
+
Faye.logger(Faye.timestamp() + banner + message);
|
451
|
+
}
|
452
|
+
};
|
453
|
+
|
454
|
+
(function() {
|
455
|
+
for (var key in Faye.Logging.LOG_LEVELS)
|
456
|
+
(function(level, value) {
|
457
|
+
Faye.Logging[level] = function() {
|
458
|
+
this.log(arguments, level);
|
459
|
+
};
|
460
|
+
})(key, Faye.Logging.LOG_LEVELS[key]);
|
461
|
+
})();
|
462
|
+
|
463
|
+
|
464
|
+
Faye.Grammar = {
|
465
|
+
|
466
|
+
LOWALPHA: /^[a-z]$/,
|
467
|
+
|
468
|
+
UPALPHA: /^[A-Z]$/,
|
469
|
+
|
470
|
+
ALPHA: /^([a-z]|[A-Z])$/,
|
471
|
+
|
472
|
+
DIGIT: /^[0-9]$/,
|
473
|
+
|
474
|
+
ALPHANUM: /^(([a-z]|[A-Z])|[0-9])$/,
|
475
|
+
|
476
|
+
MARK: /^(\-|\_|\!|\~|\(|\)|\$|\@)$/,
|
477
|
+
|
478
|
+
STRING: /^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*$/,
|
479
|
+
|
480
|
+
TOKEN: /^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+$/,
|
481
|
+
|
482
|
+
INTEGER: /^([0-9])+$/,
|
483
|
+
|
484
|
+
CHANNEL_SEGMENT: /^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+$/,
|
485
|
+
|
486
|
+
CHANNEL_SEGMENTS: /^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/,
|
487
|
+
|
488
|
+
CHANNEL_NAME: /^\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/,
|
489
|
+
|
490
|
+
WILD_CARD: /^\*{1,2}$/,
|
491
|
+
|
492
|
+
CHANNEL_PATTERN: /^(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*\/\*{1,2}$/,
|
493
|
+
|
494
|
+
VERSION_ELEMENT: /^(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\-|\_))*$/,
|
495
|
+
|
496
|
+
VERSION: /^([0-9])+(\.(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\-|\_))*)*$/,
|
497
|
+
|
498
|
+
CLIENT_ID: /^((([a-z]|[A-Z])|[0-9]))+$/,
|
499
|
+
|
500
|
+
ID: /^((([a-z]|[A-Z])|[0-9]))+$/,
|
501
|
+
|
502
|
+
ERROR_MESSAGE: /^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*$/,
|
503
|
+
|
504
|
+
ERROR_ARGS: /^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*(,(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)*$/,
|
505
|
+
|
506
|
+
ERROR_CODE: /^[0-9][0-9][0-9]$/,
|
507
|
+
|
508
|
+
ERROR: /^([0-9][0-9][0-9]:(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*(,(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)*:(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*|[0-9][0-9][0-9]::(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)$/
|
509
|
+
|
510
|
+
};
|
511
|
+
|
512
|
+
|
513
|
+
Faye.Extensible = {
|
514
|
+
addExtension: function(extension) {
|
515
|
+
this._extensions = this._extensions || [];
|
516
|
+
this._extensions.push(extension);
|
517
|
+
if (extension.added) extension.added(this);
|
518
|
+
},
|
519
|
+
|
520
|
+
removeExtension: function(extension) {
|
521
|
+
if (!this._extensions) return;
|
522
|
+
var i = this._extensions.length;
|
523
|
+
while (i--) {
|
524
|
+
if (this._extensions[i] !== extension) continue;
|
525
|
+
this._extensions.splice(i,1);
|
526
|
+
if (extension.removed) extension.removed(this);
|
527
|
+
}
|
528
|
+
},
|
529
|
+
|
530
|
+
pipeThroughExtensions: function(stage, message, callback, context) {
|
531
|
+
this.debug('Passing through ? extensions: ?', stage, message);
|
532
|
+
|
533
|
+
if (!this._extensions) return callback.call(context, message);
|
534
|
+
var extensions = this._extensions.slice();
|
535
|
+
|
536
|
+
var pipe = function(message) {
|
537
|
+
if (!message) return callback.call(context, message);
|
538
|
+
|
539
|
+
var extension = extensions.shift();
|
540
|
+
if (!extension) return callback.call(context, message);
|
541
|
+
|
542
|
+
if (extension[stage]) extension[stage](message, pipe);
|
543
|
+
else pipe(message);
|
544
|
+
};
|
545
|
+
pipe(message);
|
546
|
+
}
|
547
|
+
};
|
548
|
+
|
549
|
+
Faye.extend(Faye.Extensible, Faye.Logging);
|
550
|
+
|
551
|
+
Faye.Channel = Faye.Class({
|
552
|
+
initialize: function(name) {
|
553
|
+
this.id = this.name = name;
|
554
|
+
},
|
555
|
+
|
556
|
+
push: function(message) {
|
557
|
+
this.trigger('message', message);
|
558
|
+
},
|
559
|
+
|
560
|
+
isUnused: function() {
|
561
|
+
return this.countListeners('message') === 0;
|
562
|
+
}
|
563
|
+
});
|
564
|
+
|
565
|
+
Faye.extend(Faye.Channel.prototype, Faye.Publisher);
|
566
|
+
|
567
|
+
Faye.extend(Faye.Channel, {
|
568
|
+
HANDSHAKE: '/meta/handshake',
|
569
|
+
CONNECT: '/meta/connect',
|
570
|
+
SUBSCRIBE: '/meta/subscribe',
|
571
|
+
UNSUBSCRIBE: '/meta/unsubscribe',
|
572
|
+
DISCONNECT: '/meta/disconnect',
|
573
|
+
|
574
|
+
META: 'meta',
|
575
|
+
SERVICE: 'service',
|
576
|
+
|
577
|
+
expand: function(name) {
|
578
|
+
var segments = this.parse(name),
|
579
|
+
channels = ['/**', name];
|
580
|
+
|
581
|
+
var copy = segments.slice();
|
582
|
+
copy[copy.length - 1] = '*';
|
583
|
+
channels.push(this.unparse(copy));
|
584
|
+
|
585
|
+
for (var i = 1, n = segments.length; i < n; i++) {
|
586
|
+
copy = segments.slice(0, i);
|
587
|
+
copy.push('**');
|
588
|
+
channels.push(this.unparse(copy));
|
589
|
+
}
|
590
|
+
|
591
|
+
return channels;
|
592
|
+
},
|
593
|
+
|
594
|
+
isValid: function(name) {
|
595
|
+
return Faye.Grammar.CHANNEL_NAME.test(name) ||
|
596
|
+
Faye.Grammar.CHANNEL_PATTERN.test(name);
|
597
|
+
},
|
598
|
+
|
599
|
+
parse: function(name) {
|
600
|
+
if (!this.isValid(name)) return null;
|
601
|
+
return name.split('/').slice(1);
|
602
|
+
},
|
603
|
+
|
604
|
+
unparse: function(segments) {
|
605
|
+
return '/' + segments.join('/');
|
606
|
+
},
|
607
|
+
|
608
|
+
isMeta: function(name) {
|
609
|
+
var segments = this.parse(name);
|
610
|
+
return segments ? (segments[0] === this.META) : null;
|
611
|
+
},
|
612
|
+
|
613
|
+
isService: function(name) {
|
614
|
+
var segments = this.parse(name);
|
615
|
+
return segments ? (segments[0] === this.SERVICE) : null;
|
616
|
+
},
|
617
|
+
|
618
|
+
isSubscribable: function(name) {
|
619
|
+
if (!this.isValid(name)) return null;
|
620
|
+
return !this.isMeta(name) && !this.isService(name);
|
621
|
+
},
|
622
|
+
|
623
|
+
Set: Faye.Class({
|
624
|
+
initialize: function() {
|
625
|
+
this._channels = {};
|
626
|
+
},
|
627
|
+
|
628
|
+
getKeys: function() {
|
629
|
+
var keys = [];
|
630
|
+
for (var key in this._channels) keys.push(key);
|
631
|
+
return keys;
|
632
|
+
},
|
633
|
+
|
634
|
+
remove: function(name) {
|
635
|
+
delete this._channels[name];
|
636
|
+
},
|
637
|
+
|
638
|
+
hasSubscription: function(name) {
|
639
|
+
return this._channels.hasOwnProperty(name);
|
640
|
+
},
|
641
|
+
|
642
|
+
subscribe: function(names, callback, context) {
|
643
|
+
if (!callback) return;
|
644
|
+
var name;
|
645
|
+
for (var i = 0, n = names.length; i < n; i++) {
|
646
|
+
name = names[i];
|
647
|
+
var channel = this._channels[name] = this._channels[name] || new Faye.Channel(name);
|
648
|
+
channel.bind('message', callback, context);
|
649
|
+
}
|
650
|
+
},
|
651
|
+
|
652
|
+
unsubscribe: function(name, callback, context) {
|
653
|
+
var channel = this._channels[name];
|
654
|
+
if (!channel) return false;
|
655
|
+
channel.unbind('message', callback, context);
|
656
|
+
|
657
|
+
if (channel.isUnused()) {
|
658
|
+
this.remove(name);
|
659
|
+
return true;
|
660
|
+
} else {
|
661
|
+
return false;
|
662
|
+
}
|
663
|
+
},
|
664
|
+
|
665
|
+
distributeMessage: function(message) {
|
666
|
+
var channels = Faye.Channel.expand(message.channel);
|
667
|
+
|
668
|
+
for (var i = 0, n = channels.length; i < n; i++) {
|
669
|
+
var channel = this._channels[channels[i]];
|
670
|
+
if (channel) channel.trigger('message', message.data);
|
671
|
+
}
|
672
|
+
}
|
673
|
+
})
|
674
|
+
});
|
675
|
+
|
676
|
+
|
677
|
+
Faye.Publication = Faye.Class(Faye.Deferrable);
|
678
|
+
|
679
|
+
|
680
|
+
Faye.Subscription = Faye.Class({
|
681
|
+
initialize: function(client, channels, callback, context) {
|
682
|
+
this._client = client;
|
683
|
+
this._channels = channels;
|
684
|
+
this._callback = callback;
|
685
|
+
this._context = context;
|
686
|
+
this._cancelled = false;
|
687
|
+
},
|
688
|
+
|
689
|
+
cancel: function() {
|
690
|
+
if (this._cancelled) return;
|
691
|
+
this._client.unsubscribe(this._channels, this._callback, this._context);
|
692
|
+
this._cancelled = true;
|
693
|
+
},
|
694
|
+
|
695
|
+
unsubscribe: function() {
|
696
|
+
this.cancel();
|
697
|
+
}
|
698
|
+
});
|
699
|
+
|
700
|
+
Faye.extend(Faye.Subscription.prototype, Faye.Deferrable);
|
701
|
+
|
702
|
+
|
703
|
+
Faye.Client = Faye.Class({
|
704
|
+
UNCONNECTED: 1,
|
705
|
+
CONNECTING: 2,
|
706
|
+
CONNECTED: 3,
|
707
|
+
DISCONNECTED: 4,
|
708
|
+
|
709
|
+
HANDSHAKE: 'handshake',
|
710
|
+
RETRY: 'retry',
|
711
|
+
NONE: 'none',
|
712
|
+
|
713
|
+
CONNECTION_TIMEOUT: 60.0,
|
714
|
+
DEFAULT_RETRY: 5.0,
|
715
|
+
|
716
|
+
DEFAULT_ENDPOINT: '/bayeux',
|
717
|
+
INTERVAL: 0.0,
|
718
|
+
|
719
|
+
initialize: function(endpoint, options) {
|
720
|
+
this.info('New client created for ?', endpoint);
|
721
|
+
|
722
|
+
this._options = options || {};
|
723
|
+
this.endpoint = endpoint || this.DEFAULT_ENDPOINT;
|
724
|
+
this.endpoints = this._options.endpoints || {};
|
725
|
+
this.transports = {};
|
726
|
+
this._cookies = Faye.CookieJar && new Faye.CookieJar();
|
727
|
+
this._headers = {};
|
728
|
+
this._disabled = [];
|
729
|
+
this.retry = this._options.retry || this.DEFAULT_RETRY;
|
730
|
+
|
731
|
+
this._state = this.UNCONNECTED;
|
732
|
+
this._channels = new Faye.Channel.Set();
|
733
|
+
this._messageId = 0;
|
734
|
+
|
735
|
+
this._responseCallbacks = {};
|
736
|
+
|
737
|
+
this._advice = {
|
738
|
+
reconnect: this.RETRY,
|
739
|
+
interval: 1000 * (this._options.interval || this.INTERVAL),
|
740
|
+
timeout: 1000 * (this._options.timeout || this.CONNECTION_TIMEOUT)
|
741
|
+
};
|
742
|
+
|
743
|
+
if (Faye.Event)
|
744
|
+
Faye.Event.on(Faye.ENV, 'beforeunload', function() {
|
745
|
+
if (Faye.indexOf(this._disabled, 'autodisconnect') < 0)
|
746
|
+
this.disconnect();
|
747
|
+
}, this);
|
748
|
+
},
|
749
|
+
|
750
|
+
disable: function(feature) {
|
751
|
+
this._disabled.push(feature);
|
752
|
+
},
|
753
|
+
|
754
|
+
setHeader: function(name, value) {
|
755
|
+
this._headers[name] = value;
|
756
|
+
},
|
757
|
+
|
758
|
+
getClientId: function() {
|
759
|
+
return this._clientId;
|
760
|
+
},
|
761
|
+
|
762
|
+
getState: function() {
|
763
|
+
switch (this._state) {
|
764
|
+
case this.UNCONNECTED: return 'UNCONNECTED';
|
765
|
+
case this.CONNECTING: return 'CONNECTING';
|
766
|
+
case this.CONNECTED: return 'CONNECTED';
|
767
|
+
case this.DISCONNECTED: return 'DISCONNECTED';
|
768
|
+
}
|
769
|
+
},
|
770
|
+
|
771
|
+
// Request
|
772
|
+
// MUST include: * channel
|
773
|
+
// * version
|
774
|
+
// * supportedConnectionTypes
|
775
|
+
// MAY include: * minimumVersion
|
776
|
+
// * ext
|
777
|
+
// * id
|
778
|
+
//
|
779
|
+
// Success Response Failed Response
|
780
|
+
// MUST include: * channel MUST include: * channel
|
781
|
+
// * version * successful
|
782
|
+
// * supportedConnectionTypes * error
|
783
|
+
// * clientId MAY include: * supportedConnectionTypes
|
784
|
+
// * successful * advice
|
785
|
+
// MAY include: * minimumVersion * version
|
786
|
+
// * advice * minimumVersion
|
787
|
+
// * ext * ext
|
788
|
+
// * id * id
|
789
|
+
// * authSuccessful
|
790
|
+
handshake: function(callback, context) {
|
791
|
+
if (this._advice.reconnect === this.NONE) return;
|
792
|
+
if (this._state !== this.UNCONNECTED) return;
|
793
|
+
|
794
|
+
this._state = this.CONNECTING;
|
795
|
+
var self = this;
|
796
|
+
|
797
|
+
this.info('Initiating handshake with ?', this.endpoint);
|
798
|
+
this._selectTransport(Faye.MANDATORY_CONNECTION_TYPES);
|
799
|
+
|
800
|
+
this._send({
|
801
|
+
channel: Faye.Channel.HANDSHAKE,
|
802
|
+
version: Faye.BAYEUX_VERSION,
|
803
|
+
supportedConnectionTypes: [this._transport.connectionType]
|
804
|
+
|
805
|
+
}, function(response) {
|
806
|
+
|
807
|
+
if (response.successful) {
|
808
|
+
this._state = this.CONNECTED;
|
809
|
+
this._clientId = response.clientId;
|
810
|
+
|
811
|
+
this._selectTransport(response.supportedConnectionTypes);
|
812
|
+
|
813
|
+
this.info('Handshake successful: ?', this._clientId);
|
814
|
+
|
815
|
+
this.subscribe(this._channels.getKeys(), true);
|
816
|
+
if (callback) callback.call(context);
|
817
|
+
|
818
|
+
} else {
|
819
|
+
this.info('Handshake unsuccessful');
|
820
|
+
Faye.ENV.setTimeout(function() { self.handshake(callback, context) }, this._advice.interval);
|
821
|
+
this._state = this.UNCONNECTED;
|
822
|
+
}
|
823
|
+
}, this);
|
824
|
+
},
|
825
|
+
|
826
|
+
// Request Response
|
827
|
+
// MUST include: * channel MUST include: * channel
|
828
|
+
// * clientId * successful
|
829
|
+
// * connectionType * clientId
|
830
|
+
// MAY include: * ext MAY include: * error
|
831
|
+
// * id * advice
|
832
|
+
// * ext
|
833
|
+
// * id
|
834
|
+
// * timestamp
|
835
|
+
connect: function(callback, context) {
|
836
|
+
if (this._advice.reconnect === this.NONE) return;
|
837
|
+
if (this._state === this.DISCONNECTED) return;
|
838
|
+
|
839
|
+
if (this._state === this.UNCONNECTED)
|
840
|
+
return this.handshake(function() { this.connect(callback, context) }, this);
|
841
|
+
|
842
|
+
this.callback(callback, context);
|
843
|
+
if (this._state !== this.CONNECTED) return;
|
844
|
+
|
845
|
+
this.info('Calling deferred actions for ?', this._clientId);
|
846
|
+
this.setDeferredStatus('succeeded');
|
847
|
+
this.setDeferredStatus('deferred');
|
848
|
+
|
849
|
+
if (this._connectRequest) return;
|
850
|
+
this._connectRequest = true;
|
851
|
+
|
852
|
+
this.info('Initiating connection for ?', this._clientId);
|
853
|
+
|
854
|
+
this._send({
|
855
|
+
channel: Faye.Channel.CONNECT,
|
856
|
+
clientId: this._clientId,
|
857
|
+
connectionType: this._transport.connectionType
|
858
|
+
|
859
|
+
}, this._cycleConnection, this);
|
860
|
+
},
|
861
|
+
|
862
|
+
// Request Response
|
863
|
+
// MUST include: * channel MUST include: * channel
|
864
|
+
// * clientId * successful
|
865
|
+
// MAY include: * ext * clientId
|
866
|
+
// * id MAY include: * error
|
867
|
+
// * ext
|
868
|
+
// * id
|
869
|
+
disconnect: function() {
|
870
|
+
if (this._state !== this.CONNECTED) return;
|
871
|
+
this._state = this.DISCONNECTED;
|
872
|
+
|
873
|
+
this.info('Disconnecting ?', this._clientId);
|
874
|
+
|
875
|
+
this._send({
|
876
|
+
channel: Faye.Channel.DISCONNECT,
|
877
|
+
clientId: this._clientId
|
878
|
+
|
879
|
+
}, function(response) {
|
880
|
+
if (response.successful) this._transport.close();
|
881
|
+
}, this);
|
882
|
+
|
883
|
+
this.info('Clearing channel listeners for ?', this._clientId);
|
884
|
+
this._channels = new Faye.Channel.Set();
|
885
|
+
},
|
886
|
+
|
887
|
+
// Request Response
|
888
|
+
// MUST include: * channel MUST include: * channel
|
889
|
+
// * clientId * successful
|
890
|
+
// * subscription * clientId
|
891
|
+
// MAY include: * ext * subscription
|
892
|
+
// * id MAY include: * error
|
893
|
+
// * advice
|
894
|
+
// * ext
|
895
|
+
// * id
|
896
|
+
// * timestamp
|
897
|
+
subscribe: function(channel, callback, context) {
|
898
|
+
if (channel instanceof Array)
|
899
|
+
return Faye.map(channel, function(c) {
|
900
|
+
return this.subscribe(c, callback, context);
|
901
|
+
}, this);
|
902
|
+
|
903
|
+
var subscription = new Faye.Subscription(this, channel, callback, context),
|
904
|
+
force = (callback === true),
|
905
|
+
hasSubscribe = this._channels.hasSubscription(channel);
|
906
|
+
|
907
|
+
if (hasSubscribe && !force) {
|
908
|
+
this._channels.subscribe([channel], callback, context);
|
909
|
+
subscription.setDeferredStatus('succeeded');
|
910
|
+
return subscription;
|
911
|
+
}
|
912
|
+
|
913
|
+
this.connect(function() {
|
914
|
+
this.info('Client ? attempting to subscribe to ?', this._clientId, channel);
|
915
|
+
if (!force) this._channels.subscribe([channel], callback, context);
|
916
|
+
|
917
|
+
this._send({
|
918
|
+
channel: Faye.Channel.SUBSCRIBE,
|
919
|
+
clientId: this._clientId,
|
920
|
+
subscription: channel
|
921
|
+
|
922
|
+
}, function(response) {
|
923
|
+
if (!response.successful) {
|
924
|
+
subscription.setDeferredStatus('failed', Faye.Error.parse(response.error));
|
925
|
+
return this._channels.unsubscribe(channel, callback, context);
|
926
|
+
}
|
927
|
+
|
928
|
+
var channels = [].concat(response.subscription);
|
929
|
+
this.info('Subscription acknowledged for ? to ?', this._clientId, channels);
|
930
|
+
subscription.setDeferredStatus('succeeded');
|
931
|
+
}, this);
|
932
|
+
}, this);
|
933
|
+
|
934
|
+
return subscription;
|
935
|
+
},
|
936
|
+
|
937
|
+
// Request Response
|
938
|
+
// MUST include: * channel MUST include: * channel
|
939
|
+
// * clientId * successful
|
940
|
+
// * subscription * clientId
|
941
|
+
// MAY include: * ext * subscription
|
942
|
+
// * id MAY include: * error
|
943
|
+
// * advice
|
944
|
+
// * ext
|
945
|
+
// * id
|
946
|
+
// * timestamp
|
947
|
+
unsubscribe: function(channel, callback, context) {
|
948
|
+
if (channel instanceof Array)
|
949
|
+
return Faye.map(channel, function(c) {
|
950
|
+
return this.unsubscribe(c, callback, context);
|
951
|
+
}, this);
|
952
|
+
|
953
|
+
var dead = this._channels.unsubscribe(channel, callback, context);
|
954
|
+
if (!dead) return;
|
955
|
+
|
956
|
+
this.connect(function() {
|
957
|
+
this.info('Client ? attempting to unsubscribe from ?', this._clientId, channel);
|
958
|
+
|
959
|
+
this._send({
|
960
|
+
channel: Faye.Channel.UNSUBSCRIBE,
|
961
|
+
clientId: this._clientId,
|
962
|
+
subscription: channel
|
963
|
+
|
964
|
+
}, function(response) {
|
965
|
+
if (!response.successful) return;
|
966
|
+
|
967
|
+
var channels = [].concat(response.subscription);
|
968
|
+
this.info('Unsubscription acknowledged for ? from ?', this._clientId, channels);
|
969
|
+
}, this);
|
970
|
+
}, this);
|
971
|
+
},
|
972
|
+
|
973
|
+
// Request Response
|
974
|
+
// MUST include: * channel MUST include: * channel
|
975
|
+
// * data * successful
|
976
|
+
// MAY include: * clientId MAY include: * id
|
977
|
+
// * id * error
|
978
|
+
// * ext * ext
|
979
|
+
publish: function(channel, data) {
|
980
|
+
var publication = new Faye.Publication();
|
981
|
+
|
982
|
+
this.connect(function() {
|
983
|
+
this.info('Client ? queueing published message to ?: ?', this._clientId, channel, data);
|
984
|
+
|
985
|
+
this._send({
|
986
|
+
channel: channel,
|
987
|
+
data: data,
|
988
|
+
clientId: this._clientId
|
989
|
+
}, function(response) {
|
990
|
+
if (response.successful)
|
991
|
+
publication.setDeferredStatus('succeeded');
|
992
|
+
else
|
993
|
+
publication.setDeferredStatus('failed', Faye.Error.parse(response.error));
|
994
|
+
}, this);
|
995
|
+
}, this);
|
996
|
+
|
997
|
+
return publication;
|
998
|
+
},
|
999
|
+
|
1000
|
+
receiveMessage: function(message) {
|
1001
|
+
this.pipeThroughExtensions('incoming', message, function(message) {
|
1002
|
+
if (!message) return;
|
1003
|
+
|
1004
|
+
if (message.advice) this._handleAdvice(message.advice);
|
1005
|
+
this._deliverMessage(message);
|
1006
|
+
|
1007
|
+
if (message.successful === undefined) return;
|
1008
|
+
|
1009
|
+
var callback = this._responseCallbacks[message.id];
|
1010
|
+
if (!callback) return;
|
1011
|
+
|
1012
|
+
delete this._responseCallbacks[message.id];
|
1013
|
+
callback[0].call(callback[1], message);
|
1014
|
+
}, this);
|
1015
|
+
},
|
1016
|
+
|
1017
|
+
_selectTransport: function(transportTypes) {
|
1018
|
+
Faye.Transport.get(this, transportTypes, this._disabled, function(transport) {
|
1019
|
+
this.debug('Selected ? transport for ?', transport.connectionType, transport.endpoint);
|
1020
|
+
|
1021
|
+
if (transport === this._transport) return;
|
1022
|
+
if (this._transport) this._transport.close();
|
1023
|
+
|
1024
|
+
this._transport = transport;
|
1025
|
+
this._transport.cookies = this._cookies;
|
1026
|
+
this._transport.headers = this._headers;
|
1027
|
+
|
1028
|
+
transport.bind('down', function() {
|
1029
|
+
if (this._transportUp !== undefined && !this._transportUp) return;
|
1030
|
+
this._transportUp = false;
|
1031
|
+
this.trigger('transport:down');
|
1032
|
+
}, this);
|
1033
|
+
|
1034
|
+
transport.bind('up', function() {
|
1035
|
+
if (this._transportUp !== undefined && this._transportUp) return;
|
1036
|
+
this._transportUp = true;
|
1037
|
+
this.trigger('transport:up');
|
1038
|
+
}, this);
|
1039
|
+
}, this);
|
1040
|
+
},
|
1041
|
+
|
1042
|
+
_send: function(message, callback, context) {
|
1043
|
+
message.id = this._generateMessageId();
|
1044
|
+
if (callback) this._responseCallbacks[message.id] = [callback, context];
|
1045
|
+
|
1046
|
+
this.pipeThroughExtensions('outgoing', message, function(message) {
|
1047
|
+
if (!message) return;
|
1048
|
+
this._transport.send(message, this._advice.timeout / 1000);
|
1049
|
+
}, this);
|
1050
|
+
},
|
1051
|
+
|
1052
|
+
_generateMessageId: function() {
|
1053
|
+
this._messageId += 1;
|
1054
|
+
if (this._messageId >= Math.pow(2,32)) this._messageId = 0;
|
1055
|
+
return this._messageId.toString(36);
|
1056
|
+
},
|
1057
|
+
|
1058
|
+
_handleAdvice: function(advice) {
|
1059
|
+
Faye.extend(this._advice, advice);
|
1060
|
+
|
1061
|
+
if (this._advice.reconnect === this.HANDSHAKE && this._state !== this.DISCONNECTED) {
|
1062
|
+
this._state = this.UNCONNECTED;
|
1063
|
+
this._clientId = null;
|
1064
|
+
this._cycleConnection();
|
1065
|
+
}
|
1066
|
+
},
|
1067
|
+
|
1068
|
+
_deliverMessage: function(message) {
|
1069
|
+
if (!message.channel || message.data === undefined) return;
|
1070
|
+
this.info('Client ? calling listeners for ? with ?', this._clientId, message.channel, message.data);
|
1071
|
+
this._channels.distributeMessage(message);
|
1072
|
+
},
|
1073
|
+
|
1074
|
+
_teardownConnection: function() {
|
1075
|
+
if (!this._connectRequest) return;
|
1076
|
+
this._connectRequest = null;
|
1077
|
+
this.info('Closed connection for ?', this._clientId);
|
1078
|
+
},
|
1079
|
+
|
1080
|
+
_cycleConnection: function() {
|
1081
|
+
this._teardownConnection();
|
1082
|
+
var self = this;
|
1083
|
+
Faye.ENV.setTimeout(function() { self.connect() }, this._advice.interval);
|
1084
|
+
}
|
1085
|
+
});
|
1086
|
+
|
1087
|
+
Faye.extend(Faye.Client.prototype, Faye.Deferrable);
|
1088
|
+
Faye.extend(Faye.Client.prototype, Faye.Publisher);
|
1089
|
+
Faye.extend(Faye.Client.prototype, Faye.Logging);
|
1090
|
+
Faye.extend(Faye.Client.prototype, Faye.Extensible);
|
1091
|
+
|
1092
|
+
|
1093
|
+
Faye.Transport = Faye.extend(Faye.Class({
|
1094
|
+
MAX_DELAY: 0.0,
|
1095
|
+
batching: true,
|
1096
|
+
|
1097
|
+
initialize: function(client, endpoint) {
|
1098
|
+
this._client = client;
|
1099
|
+
this.endpoint = endpoint;
|
1100
|
+
this._outbox = [];
|
1101
|
+
},
|
1102
|
+
|
1103
|
+
close: function() {},
|
1104
|
+
|
1105
|
+
send: function(message, timeout) {
|
1106
|
+
this.debug('Client ? sending message to ?: ?',
|
1107
|
+
this._client._clientId, this.endpoint, message);
|
1108
|
+
|
1109
|
+
if (!this.batching) return this.request([message], timeout);
|
1110
|
+
|
1111
|
+
this._outbox.push(message);
|
1112
|
+
this._timeout = timeout;
|
1113
|
+
|
1114
|
+
if (message.channel === Faye.Channel.HANDSHAKE)
|
1115
|
+
return this.addTimeout('publish', 0.01, this.flush, this);
|
1116
|
+
|
1117
|
+
if (message.channel === Faye.Channel.CONNECT)
|
1118
|
+
this._connectMessage = message;
|
1119
|
+
|
1120
|
+
if (this.shouldFlush && this.shouldFlush(this._outbox))
|
1121
|
+
return this.flush();
|
1122
|
+
|
1123
|
+
this.addTimeout('publish', this.MAX_DELAY, this.flush, this);
|
1124
|
+
},
|
1125
|
+
|
1126
|
+
flush: function() {
|
1127
|
+
this.removeTimeout('publish');
|
1128
|
+
|
1129
|
+
if (this._outbox.length > 1 && this._connectMessage)
|
1130
|
+
this._connectMessage.advice = {timeout: 0};
|
1131
|
+
|
1132
|
+
this.request(this._outbox, this._timeout);
|
1133
|
+
|
1134
|
+
this._connectMessage = null;
|
1135
|
+
this._outbox = [];
|
1136
|
+
},
|
1137
|
+
|
1138
|
+
receive: function(responses) {
|
1139
|
+
this.debug('Client ? received from ?: ?',
|
1140
|
+
this._client._clientId, this.endpoint, responses);
|
1141
|
+
|
1142
|
+
for (var i = 0, n = responses.length; i < n; i++) {
|
1143
|
+
this._client.receiveMessage(responses[i]);
|
1144
|
+
}
|
1145
|
+
},
|
1146
|
+
|
1147
|
+
retry: function(message, timeout) {
|
1148
|
+
var called = false,
|
1149
|
+
retry = this._client.retry * 1000,
|
1150
|
+
self = this;
|
1151
|
+
|
1152
|
+
return function() {
|
1153
|
+
if (called) return;
|
1154
|
+
called = true;
|
1155
|
+
Faye.ENV.setTimeout(function() { self.request(message, timeout) }, retry);
|
1156
|
+
};
|
1157
|
+
}
|
1158
|
+
|
1159
|
+
}), {
|
1160
|
+
MAX_URL_LENGTH: 2048,
|
1161
|
+
|
1162
|
+
get: function(client, allowed, disabled, callback, context) {
|
1163
|
+
var endpoint = client.endpoint;
|
1164
|
+
|
1165
|
+
Faye.asyncEach(this._transports, function(pair, resume) {
|
1166
|
+
var connType = pair[0], klass = pair[1],
|
1167
|
+
connEndpoint = client.endpoints[connType] || endpoint;
|
1168
|
+
|
1169
|
+
if (Faye.indexOf(disabled, connType) >= 0)
|
1170
|
+
return resume();
|
1171
|
+
|
1172
|
+
if (Faye.indexOf(allowed, connType) < 0) {
|
1173
|
+
klass.isUsable(client, connEndpoint, function() {});
|
1174
|
+
return resume();
|
1175
|
+
}
|
1176
|
+
|
1177
|
+
klass.isUsable(client, connEndpoint, function(isUsable) {
|
1178
|
+
if (!isUsable) return resume();
|
1179
|
+
var transport = klass.hasOwnProperty('create') ? klass.create(client, connEndpoint) : new klass(client, connEndpoint);
|
1180
|
+
callback.call(context, transport);
|
1181
|
+
});
|
1182
|
+
}, function() {
|
1183
|
+
throw new Error('Could not find a usable connection type for ' + endpoint);
|
1184
|
+
});
|
1185
|
+
},
|
1186
|
+
|
1187
|
+
register: function(type, klass) {
|
1188
|
+
this._transports.push([type, klass]);
|
1189
|
+
klass.prototype.connectionType = type;
|
1190
|
+
},
|
1191
|
+
|
1192
|
+
_transports: []
|
1193
|
+
});
|
1194
|
+
|
1195
|
+
Faye.extend(Faye.Transport.prototype, Faye.Logging);
|
1196
|
+
Faye.extend(Faye.Transport.prototype, Faye.Publisher);
|
1197
|
+
Faye.extend(Faye.Transport.prototype, Faye.Timeouts);
|
1198
|
+
|
1199
|
+
|
1200
|
+
Faye.Event = {
|
1201
|
+
_registry: [],
|
1202
|
+
|
1203
|
+
on: function(element, eventName, callback, context) {
|
1204
|
+
var wrapped = function() { callback.call(context) };
|
1205
|
+
|
1206
|
+
if (element.addEventListener)
|
1207
|
+
element.addEventListener(eventName, wrapped, false);
|
1208
|
+
else
|
1209
|
+
element.attachEvent('on' + eventName, wrapped);
|
1210
|
+
|
1211
|
+
this._registry.push({
|
1212
|
+
_element: element,
|
1213
|
+
_type: eventName,
|
1214
|
+
_callback: callback,
|
1215
|
+
_context: context,
|
1216
|
+
_handler: wrapped
|
1217
|
+
});
|
1218
|
+
},
|
1219
|
+
|
1220
|
+
detach: function(element, eventName, callback, context) {
|
1221
|
+
var i = this._registry.length, register;
|
1222
|
+
while (i--) {
|
1223
|
+
register = this._registry[i];
|
1224
|
+
|
1225
|
+
if ((element && element !== register._element) ||
|
1226
|
+
(eventName && eventName !== register._type) ||
|
1227
|
+
(callback && callback !== register._callback) ||
|
1228
|
+
(context && context !== register._context))
|
1229
|
+
continue;
|
1230
|
+
|
1231
|
+
if (register._element.removeEventListener)
|
1232
|
+
register._element.removeEventListener(register._type, register._handler, false);
|
1233
|
+
else
|
1234
|
+
register._element.detachEvent('on' + register._type, register._handler);
|
1235
|
+
|
1236
|
+
this._registry.splice(i,1);
|
1237
|
+
register = null;
|
1238
|
+
}
|
1239
|
+
}
|
1240
|
+
};
|
1241
|
+
|
1242
|
+
Faye.Event.on(Faye.ENV, 'unload', Faye.Event.detach, Faye.Event);
|
1243
|
+
|
1244
|
+
|
1245
|
+
Faye.URI = Faye.extend(Faye.Class({
|
1246
|
+
queryString: function() {
|
1247
|
+
var pairs = [];
|
1248
|
+
for (var key in this.params) {
|
1249
|
+
if (!this.params.hasOwnProperty(key)) continue;
|
1250
|
+
pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(this.params[key]));
|
1251
|
+
}
|
1252
|
+
return pairs.join('&');
|
1253
|
+
},
|
1254
|
+
|
1255
|
+
isSameOrigin: function() {
|
1256
|
+
var host = Faye.URI.parse(Faye.ENV.location.href, false);
|
1257
|
+
|
1258
|
+
var external = (host.hostname !== this.hostname) ||
|
1259
|
+
(host.port !== this.port) ||
|
1260
|
+
(host.protocol !== this.protocol);
|
1261
|
+
|
1262
|
+
return !external;
|
1263
|
+
},
|
1264
|
+
|
1265
|
+
toURL: function() {
|
1266
|
+
var query = this.queryString();
|
1267
|
+
return this.protocol + '//' + this.hostname + (this.port ? ':' + this.port : '') +
|
1268
|
+
this.pathname + (query ? '?' + query : '') + this.hash;
|
1269
|
+
}
|
1270
|
+
}), {
|
1271
|
+
parse: function(url, params) {
|
1272
|
+
if (typeof url !== 'string') return url;
|
1273
|
+
var uri = new this(), parts;
|
1274
|
+
|
1275
|
+
var consume = function(name, pattern, infer) {
|
1276
|
+
url = url.replace(pattern, function(match) {
|
1277
|
+
uri[name] = match;
|
1278
|
+
return '';
|
1279
|
+
});
|
1280
|
+
if (uri[name] === undefined)
|
1281
|
+
uri[name] = infer ? Faye.ENV.location[name] : '';
|
1282
|
+
};
|
1283
|
+
|
1284
|
+
consume('protocol', /^https?\:/, true);
|
1285
|
+
consume('host', /^\/\/[^\/]+/, true);
|
1286
|
+
|
1287
|
+
if (!/^\//.test(url)) url = Faye.ENV.location.pathname.replace(/[^\/]*$/, '') + url;
|
1288
|
+
consume('pathname', /^\/[^\?#]*/);
|
1289
|
+
consume('search', /^\?[^#]*/);
|
1290
|
+
consume('hash', /^#.*/);
|
1291
|
+
|
1292
|
+
if (/^\/\//.test(uri.host)) {
|
1293
|
+
uri.host = uri.host.substr(2);
|
1294
|
+
parts = uri.host.split(':');
|
1295
|
+
uri.hostname = parts[0];
|
1296
|
+
uri.port = parts[1] || '';
|
1297
|
+
} else {
|
1298
|
+
uri.hostname = Faye.ENV.location.hostname;
|
1299
|
+
uri.port = Faye.ENV.location.port;
|
1300
|
+
}
|
1301
|
+
|
1302
|
+
if (params === false) {
|
1303
|
+
uri.params = {};
|
1304
|
+
} else {
|
1305
|
+
var query = uri.search.replace(/^\?/, ''),
|
1306
|
+
pairs = query ? query.split('&') : [],
|
1307
|
+
n = pairs.length,
|
1308
|
+
data = {};
|
1309
|
+
|
1310
|
+
while (n--) {
|
1311
|
+
parts = pairs[n].split('=');
|
1312
|
+
data[decodeURIComponent(parts[0] || '')] = decodeURIComponent(parts[1] || '');
|
1313
|
+
}
|
1314
|
+
if (typeof params === 'object') Faye.extend(data, params);
|
1315
|
+
|
1316
|
+
uri.params = data;
|
1317
|
+
}
|
1318
|
+
|
1319
|
+
return uri;
|
1320
|
+
}
|
1321
|
+
});
|
1322
|
+
|
1323
|
+
|
1324
|
+
/*
|
1325
|
+
http://www.JSON.org/json2.js
|
1326
|
+
2009-04-16
|
1327
|
+
|
1328
|
+
Public Domain.
|
1329
|
+
|
1330
|
+
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
1331
|
+
|
1332
|
+
See http://www.JSON.org/js.html
|
1333
|
+
|
1334
|
+
This file creates a global JSON object containing two methods: stringify
|
1335
|
+
and parse.
|
1336
|
+
|
1337
|
+
JSON.stringify(value, replacer, space)
|
1338
|
+
value any JavaScript value, usually an object or array.
|
1339
|
+
|
1340
|
+
replacer an optional parameter that determines how object
|
1341
|
+
values are stringified for objects. It can be a
|
1342
|
+
function or an array of strings.
|
1343
|
+
|
1344
|
+
space an optional parameter that specifies the indentation
|
1345
|
+
of nested structures. If it is omitted, the text will
|
1346
|
+
be packed without extra whitespace. If it is a number,
|
1347
|
+
it will specify the number of spaces to indent at each
|
1348
|
+
level. If it is a string (such as '\t' or ' '),
|
1349
|
+
it contains the characters used to indent at each level.
|
1350
|
+
|
1351
|
+
This method produces a JSON text from a JavaScript value.
|
1352
|
+
|
1353
|
+
When an object value is found, if the object contains a toJSON
|
1354
|
+
method, its toJSON method will be called and the result will be
|
1355
|
+
stringified. A toJSON method does not serialize: it returns the
|
1356
|
+
value represented by the name/value pair that should be serialized,
|
1357
|
+
or undefined if nothing should be serialized. The toJSON method
|
1358
|
+
will be passed the key associated with the value, and this will be
|
1359
|
+
bound to the object holding the key.
|
1360
|
+
|
1361
|
+
For example, this would serialize Dates as ISO strings.
|
1362
|
+
|
1363
|
+
Date.prototype.toJSON = function (key) {
|
1364
|
+
function f(n) {
|
1365
|
+
// Format integers to have at least two digits.
|
1366
|
+
return n < 10 ? '0' + n : n;
|
1367
|
+
}
|
1368
|
+
|
1369
|
+
return this.getUTCFullYear() + '-' +
|
1370
|
+
f(this.getUTCMonth() + 1) + '-' +
|
1371
|
+
f(this.getUTCDate()) + 'T' +
|
1372
|
+
f(this.getUTCHours()) + ':' +
|
1373
|
+
f(this.getUTCMinutes()) + ':' +
|
1374
|
+
f(this.getUTCSeconds()) + 'Z';
|
1375
|
+
};
|
1376
|
+
|
1377
|
+
You can provide an optional replacer method. It will be passed the
|
1378
|
+
key and value of each member, with this bound to the containing
|
1379
|
+
object. The value that is returned from your method will be
|
1380
|
+
serialized. If your method returns undefined, then the member will
|
1381
|
+
be excluded from the serialization.
|
1382
|
+
|
1383
|
+
If the replacer parameter is an array of strings, then it will be
|
1384
|
+
used to select the members to be serialized. It filters the results
|
1385
|
+
such that only members with keys listed in the replacer array are
|
1386
|
+
stringified.
|
1387
|
+
|
1388
|
+
Values that do not have JSON representations, such as undefined or
|
1389
|
+
functions, will not be serialized. Such values in objects will be
|
1390
|
+
dropped; in arrays they will be replaced with null. You can use
|
1391
|
+
a replacer function to replace those with JSON values.
|
1392
|
+
JSON.stringify(undefined) returns undefined.
|
1393
|
+
|
1394
|
+
The optional space parameter produces a stringification of the
|
1395
|
+
value that is filled with line breaks and indentation to make it
|
1396
|
+
easier to read.
|
1397
|
+
|
1398
|
+
If the space parameter is a non-empty string, then that string will
|
1399
|
+
be used for indentation. If the space parameter is a number, then
|
1400
|
+
the indentation will be that many spaces.
|
1401
|
+
|
1402
|
+
Example:
|
1403
|
+
|
1404
|
+
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
1405
|
+
// text is '["e",{"pluribus":"unum"}]'
|
1406
|
+
|
1407
|
+
|
1408
|
+
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
1409
|
+
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
1410
|
+
|
1411
|
+
text = JSON.stringify([new Date()], function (key, value) {
|
1412
|
+
return this[key] instanceof Date ?
|
1413
|
+
'Date(' + this[key] + ')' : value;
|
1414
|
+
});
|
1415
|
+
// text is '["Date(---current time---)"]'
|
1416
|
+
|
1417
|
+
|
1418
|
+
JSON.parse(text, reviver)
|
1419
|
+
This method parses a JSON text to produce an object or array.
|
1420
|
+
It can throw a SyntaxError exception.
|
1421
|
+
|
1422
|
+
The optional reviver parameter is a function that can filter and
|
1423
|
+
transform the results. It receives each of the keys and values,
|
1424
|
+
and its return value is used instead of the original value.
|
1425
|
+
If it returns what it received, then the structure is not modified.
|
1426
|
+
If it returns undefined then the member is deleted.
|
1427
|
+
|
1428
|
+
Example:
|
1429
|
+
|
1430
|
+
// Parse the text. Values that look like ISO date strings will
|
1431
|
+
// be converted to Date objects.
|
1432
|
+
|
1433
|
+
myData = JSON.parse(text, function (key, value) {
|
1434
|
+
var a;
|
1435
|
+
if (typeof value === 'string') {
|
1436
|
+
a =
|
1437
|
+
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
1438
|
+
if (a) {
|
1439
|
+
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
1440
|
+
+a[5], +a[6]));
|
1441
|
+
}
|
1442
|
+
}
|
1443
|
+
return value;
|
1444
|
+
});
|
1445
|
+
|
1446
|
+
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
1447
|
+
var d;
|
1448
|
+
if (typeof value === 'string' &&
|
1449
|
+
value.slice(0, 5) === 'Date(' &&
|
1450
|
+
value.slice(-1) === ')') {
|
1451
|
+
d = new Date(value.slice(5, -1));
|
1452
|
+
if (d) {
|
1453
|
+
return d;
|
1454
|
+
}
|
1455
|
+
}
|
1456
|
+
return value;
|
1457
|
+
});
|
1458
|
+
|
1459
|
+
|
1460
|
+
This is a reference implementation. You are free to copy, modify, or
|
1461
|
+
redistribute.
|
1462
|
+
|
1463
|
+
This code should be minified before deployment.
|
1464
|
+
See http://javascript.crockford.com/jsmin.html
|
1465
|
+
|
1466
|
+
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
1467
|
+
NOT CONTROL.
|
1468
|
+
*/
|
1469
|
+
|
1470
|
+
/*jslint evil: true */
|
1471
|
+
|
1472
|
+
/*global JSON */
|
1473
|
+
|
1474
|
+
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
1475
|
+
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
1476
|
+
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
1477
|
+
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
1478
|
+
test, toJSON, toString, valueOf
|
1479
|
+
*/
|
1480
|
+
|
1481
|
+
// Create a JSON object only if one does not already exist. We create the
|
1482
|
+
// methods in a closure to avoid creating global variables.
|
1483
|
+
|
1484
|
+
if (!this.JSON) {
|
1485
|
+
JSON = {};
|
1486
|
+
}
|
1487
|
+
(function () {
|
1488
|
+
|
1489
|
+
function f(n) {
|
1490
|
+
// Format integers to have at least two digits.
|
1491
|
+
return n < 10 ? '0' + n : n;
|
1492
|
+
}
|
1493
|
+
|
1494
|
+
if (typeof Date.prototype.toJSON !== 'function') {
|
1495
|
+
|
1496
|
+
Date.prototype.toJSON = function (key) {
|
1497
|
+
|
1498
|
+
return this.getUTCFullYear() + '-' +
|
1499
|
+
f(this.getUTCMonth() + 1) + '-' +
|
1500
|
+
f(this.getUTCDate()) + 'T' +
|
1501
|
+
f(this.getUTCHours()) + ':' +
|
1502
|
+
f(this.getUTCMinutes()) + ':' +
|
1503
|
+
f(this.getUTCSeconds()) + 'Z';
|
1504
|
+
};
|
1505
|
+
|
1506
|
+
String.prototype.toJSON =
|
1507
|
+
Number.prototype.toJSON =
|
1508
|
+
Boolean.prototype.toJSON = function (key) {
|
1509
|
+
return this.valueOf();
|
1510
|
+
};
|
1511
|
+
}
|
1512
|
+
|
1513
|
+
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
1514
|
+
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
1515
|
+
gap,
|
1516
|
+
indent,
|
1517
|
+
meta = { // table of character substitutions
|
1518
|
+
'\b': '\\b',
|
1519
|
+
'\t': '\\t',
|
1520
|
+
'\n': '\\n',
|
1521
|
+
'\f': '\\f',
|
1522
|
+
'\r': '\\r',
|
1523
|
+
'"' : '\\"',
|
1524
|
+
'\\': '\\\\'
|
1525
|
+
},
|
1526
|
+
rep;
|
1527
|
+
|
1528
|
+
|
1529
|
+
function quote(string) {
|
1530
|
+
|
1531
|
+
// If the string contains no control characters, no quote characters, and no
|
1532
|
+
// backslash characters, then we can safely slap some quotes around it.
|
1533
|
+
// Otherwise we must also replace the offending characters with safe escape
|
1534
|
+
// sequences.
|
1535
|
+
|
1536
|
+
escapable.lastIndex = 0;
|
1537
|
+
return escapable.test(string) ?
|
1538
|
+
'"' + string.replace(escapable, function (a) {
|
1539
|
+
var c = meta[a];
|
1540
|
+
return typeof c === 'string' ? c :
|
1541
|
+
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
1542
|
+
}) + '"' :
|
1543
|
+
'"' + string + '"';
|
1544
|
+
}
|
1545
|
+
|
1546
|
+
|
1547
|
+
function str(key, holder) {
|
1548
|
+
|
1549
|
+
// Produce a string from holder[key].
|
1550
|
+
|
1551
|
+
var i, // The loop counter.
|
1552
|
+
k, // The member key.
|
1553
|
+
v, // The member value.
|
1554
|
+
length,
|
1555
|
+
mind = gap,
|
1556
|
+
partial,
|
1557
|
+
value = holder[key];
|
1558
|
+
|
1559
|
+
// If the value has a toJSON method, call it to obtain a replacement value.
|
1560
|
+
|
1561
|
+
if (value && typeof value === 'object' &&
|
1562
|
+
typeof value.toJSON === 'function') {
|
1563
|
+
value = value.toJSON(key);
|
1564
|
+
}
|
1565
|
+
|
1566
|
+
// If we were called with a replacer function, then call the replacer to
|
1567
|
+
// obtain a replacement value.
|
1568
|
+
|
1569
|
+
if (typeof rep === 'function') {
|
1570
|
+
value = rep.call(holder, key, value);
|
1571
|
+
}
|
1572
|
+
|
1573
|
+
// What happens next depends on the value's type.
|
1574
|
+
|
1575
|
+
switch (typeof value) {
|
1576
|
+
case 'string':
|
1577
|
+
return quote(value);
|
1578
|
+
|
1579
|
+
case 'number':
|
1580
|
+
|
1581
|
+
// JSON numbers must be finite. Encode non-finite numbers as null.
|
1582
|
+
|
1583
|
+
return isFinite(value) ? String(value) : 'null';
|
1584
|
+
|
1585
|
+
case 'boolean':
|
1586
|
+
case 'null':
|
1587
|
+
|
1588
|
+
// If the value is a boolean or null, convert it to a string. Note:
|
1589
|
+
// typeof null does not produce 'null'. The case is included here in
|
1590
|
+
// the remote chance that this gets fixed someday.
|
1591
|
+
|
1592
|
+
return String(value);
|
1593
|
+
|
1594
|
+
// If the type is 'object', we might be dealing with an object or an array or
|
1595
|
+
// null.
|
1596
|
+
|
1597
|
+
case 'object':
|
1598
|
+
|
1599
|
+
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
1600
|
+
// so watch out for that case.
|
1601
|
+
|
1602
|
+
if (!value) {
|
1603
|
+
return 'null';
|
1604
|
+
}
|
1605
|
+
|
1606
|
+
// Make an array to hold the partial results of stringifying this object value.
|
1607
|
+
|
1608
|
+
gap += indent;
|
1609
|
+
partial = [];
|
1610
|
+
|
1611
|
+
// Is the value an array?
|
1612
|
+
|
1613
|
+
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
1614
|
+
|
1615
|
+
// The value is an array. Stringify every element. Use null as a placeholder
|
1616
|
+
// for non-JSON values.
|
1617
|
+
|
1618
|
+
length = value.length;
|
1619
|
+
for (i = 0; i < length; i += 1) {
|
1620
|
+
partial[i] = str(i, value) || 'null';
|
1621
|
+
}
|
1622
|
+
|
1623
|
+
// Join all of the elements together, separated with commas, and wrap them in
|
1624
|
+
// brackets.
|
1625
|
+
|
1626
|
+
v = partial.length === 0 ? '[]' :
|
1627
|
+
gap ? '[\n' + gap +
|
1628
|
+
partial.join(',\n' + gap) + '\n' +
|
1629
|
+
mind + ']' :
|
1630
|
+
'[' + partial.join(',') + ']';
|
1631
|
+
gap = mind;
|
1632
|
+
return v;
|
1633
|
+
}
|
1634
|
+
|
1635
|
+
// If the replacer is an array, use it to select the members to be stringified.
|
1636
|
+
|
1637
|
+
if (rep && typeof rep === 'object') {
|
1638
|
+
length = rep.length;
|
1639
|
+
for (i = 0; i < length; i += 1) {
|
1640
|
+
k = rep[i];
|
1641
|
+
if (typeof k === 'string') {
|
1642
|
+
v = str(k, value);
|
1643
|
+
if (v) {
|
1644
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
1645
|
+
}
|
1646
|
+
}
|
1647
|
+
}
|
1648
|
+
} else {
|
1649
|
+
|
1650
|
+
// Otherwise, iterate through all of the keys in the object.
|
1651
|
+
|
1652
|
+
for (k in value) {
|
1653
|
+
if (Object.hasOwnProperty.call(value, k)) {
|
1654
|
+
v = str(k, value);
|
1655
|
+
if (v) {
|
1656
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
1657
|
+
}
|
1658
|
+
}
|
1659
|
+
}
|
1660
|
+
}
|
1661
|
+
|
1662
|
+
// Join all of the member texts together, separated with commas,
|
1663
|
+
// and wrap them in braces.
|
1664
|
+
|
1665
|
+
v = partial.length === 0 ? '{}' :
|
1666
|
+
gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
|
1667
|
+
mind + '}' : '{' + partial.join(',') + '}';
|
1668
|
+
gap = mind;
|
1669
|
+
return v;
|
1670
|
+
}
|
1671
|
+
}
|
1672
|
+
|
1673
|
+
// If the JSON object does not yet have a stringify method, give it one.
|
1674
|
+
|
1675
|
+
// NOTE we've hacked this to expose this method to Faye. We need to use this
|
1676
|
+
// to avoid problems with buggy Firefox version and bad #toJSON implementations
|
1677
|
+
|
1678
|
+
Faye.stringify = function (value, replacer, space) {
|
1679
|
+
|
1680
|
+
// The stringify method takes a value and an optional replacer, and an optional
|
1681
|
+
// space parameter, and returns a JSON text. The replacer can be a function
|
1682
|
+
// that can replace values, or an array of strings that will select the keys.
|
1683
|
+
// A default replacer method can be provided. Use of the space parameter can
|
1684
|
+
// produce text that is more easily readable.
|
1685
|
+
|
1686
|
+
var i;
|
1687
|
+
gap = '';
|
1688
|
+
indent = '';
|
1689
|
+
|
1690
|
+
// If the space parameter is a number, make an indent string containing that
|
1691
|
+
// many spaces.
|
1692
|
+
|
1693
|
+
if (typeof space === 'number') {
|
1694
|
+
for (i = 0; i < space; i += 1) {
|
1695
|
+
indent += ' ';
|
1696
|
+
}
|
1697
|
+
|
1698
|
+
// If the space parameter is a string, it will be used as the indent string.
|
1699
|
+
|
1700
|
+
} else if (typeof space === 'string') {
|
1701
|
+
indent = space;
|
1702
|
+
}
|
1703
|
+
|
1704
|
+
// If there is a replacer, it must be a function or an array.
|
1705
|
+
// Otherwise, throw an error.
|
1706
|
+
|
1707
|
+
rep = replacer;
|
1708
|
+
if (replacer && typeof replacer !== 'function' &&
|
1709
|
+
(typeof replacer !== 'object' ||
|
1710
|
+
typeof replacer.length !== 'number')) {
|
1711
|
+
throw new Error('JSON.stringify');
|
1712
|
+
}
|
1713
|
+
|
1714
|
+
// Make a fake root object containing our value under the key of ''.
|
1715
|
+
// Return the result of stringifying the value.
|
1716
|
+
|
1717
|
+
return str('', {'': value});
|
1718
|
+
};
|
1719
|
+
|
1720
|
+
if (typeof JSON.stringify !== 'function') {
|
1721
|
+
JSON.stringify = Faye.stringify;
|
1722
|
+
}
|
1723
|
+
|
1724
|
+
|
1725
|
+
// If the JSON object does not yet have a parse method, give it one.
|
1726
|
+
|
1727
|
+
if (typeof JSON.parse !== 'function') {
|
1728
|
+
JSON.parse = function (text, reviver) {
|
1729
|
+
|
1730
|
+
// The parse method takes a text and an optional reviver function, and returns
|
1731
|
+
// a JavaScript value if the text is a valid JSON text.
|
1732
|
+
|
1733
|
+
var j;
|
1734
|
+
|
1735
|
+
function walk(holder, key) {
|
1736
|
+
|
1737
|
+
// The walk method is used to recursively walk the resulting structure so
|
1738
|
+
// that modifications can be made.
|
1739
|
+
|
1740
|
+
var k, v, value = holder[key];
|
1741
|
+
if (value && typeof value === 'object') {
|
1742
|
+
for (k in value) {
|
1743
|
+
if (Object.hasOwnProperty.call(value, k)) {
|
1744
|
+
v = walk(value, k);
|
1745
|
+
if (v !== undefined) {
|
1746
|
+
value[k] = v;
|
1747
|
+
} else {
|
1748
|
+
delete value[k];
|
1749
|
+
}
|
1750
|
+
}
|
1751
|
+
}
|
1752
|
+
}
|
1753
|
+
return reviver.call(holder, key, value);
|
1754
|
+
}
|
1755
|
+
|
1756
|
+
|
1757
|
+
// Parsing happens in four stages. In the first stage, we replace certain
|
1758
|
+
// Unicode characters with escape sequences. JavaScript handles many characters
|
1759
|
+
// incorrectly, either silently deleting them, or treating them as line endings.
|
1760
|
+
|
1761
|
+
cx.lastIndex = 0;
|
1762
|
+
if (cx.test(text)) {
|
1763
|
+
text = text.replace(cx, function (a) {
|
1764
|
+
return '\\u' +
|
1765
|
+
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
1766
|
+
});
|
1767
|
+
}
|
1768
|
+
|
1769
|
+
// In the second stage, we run the text against regular expressions that look
|
1770
|
+
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
1771
|
+
// because they can cause invocation, and '=' because it can cause mutation.
|
1772
|
+
// But just to be safe, we want to reject all unexpected forms.
|
1773
|
+
|
1774
|
+
// We split the second stage into 4 regexp operations in order to work around
|
1775
|
+
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
1776
|
+
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
1777
|
+
// replace all simple value tokens with ']' characters. Third, we delete all
|
1778
|
+
// open brackets that follow a colon or comma or that begin the text. Finally,
|
1779
|
+
// we look to see that the remaining characters are only whitespace or ']' or
|
1780
|
+
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
1781
|
+
|
1782
|
+
if (/^[\],:{}\s]*$/.
|
1783
|
+
test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
|
1784
|
+
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
|
1785
|
+
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
1786
|
+
|
1787
|
+
// In the third stage we use the eval function to compile the text into a
|
1788
|
+
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
1789
|
+
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
1790
|
+
// in parens to eliminate the ambiguity.
|
1791
|
+
|
1792
|
+
j = eval('(' + text + ')');
|
1793
|
+
|
1794
|
+
// In the optional fourth stage, we recursively walk the new structure, passing
|
1795
|
+
// each name/value pair to a reviver function for possible transformation.
|
1796
|
+
|
1797
|
+
return typeof reviver === 'function' ?
|
1798
|
+
walk({'': j}, '') : j;
|
1799
|
+
}
|
1800
|
+
|
1801
|
+
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
1802
|
+
|
1803
|
+
throw new SyntaxError('JSON.parse');
|
1804
|
+
};
|
1805
|
+
}
|
1806
|
+
}());
|
1807
|
+
|
1808
|
+
|
1809
|
+
Faye.Transport.WebSocket = Faye.extend(Faye.Class(Faye.Transport, {
|
1810
|
+
UNCONNECTED: 1,
|
1811
|
+
CONNECTING: 2,
|
1812
|
+
CONNECTED: 3,
|
1813
|
+
|
1814
|
+
batching: false,
|
1815
|
+
|
1816
|
+
isUsable: function(callback, context) {
|
1817
|
+
this.callback(function() { callback.call(context, true) });
|
1818
|
+
this.errback(function() { callback.call(context, false) });
|
1819
|
+
this.connect();
|
1820
|
+
},
|
1821
|
+
|
1822
|
+
request: function(messages, timeout) {
|
1823
|
+
if (messages.length === 0) return;
|
1824
|
+
this._messages = this._messages || {};
|
1825
|
+
|
1826
|
+
for (var i = 0, n = messages.length; i < n; i++) {
|
1827
|
+
this._messages[messages[i].id] = messages[i];
|
1828
|
+
}
|
1829
|
+
this.callback(function(socket) { socket.send(Faye.toJSON(messages)) });
|
1830
|
+
this.connect();
|
1831
|
+
},
|
1832
|
+
|
1833
|
+
close: function() {
|
1834
|
+
if (!this._socket) return;
|
1835
|
+
this._socket.onclose = this._socket.onerror = null;
|
1836
|
+
this._socket.close();
|
1837
|
+
delete this._socket;
|
1838
|
+
this.setDeferredStatus('deferred');
|
1839
|
+
this._state = this.UNCONNECTED;
|
1840
|
+
},
|
1841
|
+
|
1842
|
+
connect: function() {
|
1843
|
+
if (Faye.Transport.WebSocket._unloaded) return;
|
1844
|
+
|
1845
|
+
this._state = this._state || this.UNCONNECTED;
|
1846
|
+
if (this._state !== this.UNCONNECTED) return;
|
1847
|
+
|
1848
|
+
this._state = this.CONNECTING;
|
1849
|
+
|
1850
|
+
var ws = Faye.Transport.WebSocket.getClass();
|
1851
|
+
if (!ws) return this.setDeferredStatus('failed');
|
1852
|
+
|
1853
|
+
this._socket = new ws(Faye.Transport.WebSocket.getSocketUrl(this.endpoint));
|
1854
|
+
var self = this;
|
1855
|
+
|
1856
|
+
this._socket.onopen = function() {
|
1857
|
+
self._state = self.CONNECTED;
|
1858
|
+
self._everConnected = true;
|
1859
|
+
self.setDeferredStatus('succeeded', self._socket);
|
1860
|
+
self.trigger('up');
|
1861
|
+
};
|
1862
|
+
|
1863
|
+
this._socket.onmessage = function(event) {
|
1864
|
+
var messages = JSON.parse(event.data);
|
1865
|
+
if (!messages) return;
|
1866
|
+
messages = [].concat(messages);
|
1867
|
+
|
1868
|
+
for (var i = 0, n = messages.length; i < n; i++) {
|
1869
|
+
delete self._messages[messages[i].id];
|
1870
|
+
}
|
1871
|
+
self.receive(messages);
|
1872
|
+
};
|
1873
|
+
|
1874
|
+
this._socket.onclose = this._socket.onerror = function() {
|
1875
|
+
var wasConnected = (self._state === self.CONNECTED);
|
1876
|
+
self.setDeferredStatus('deferred');
|
1877
|
+
self._state = self.UNCONNECTED;
|
1878
|
+
|
1879
|
+
self.close();
|
1880
|
+
|
1881
|
+
if (wasConnected) return self.resend();
|
1882
|
+
if (!self._everConnected) return self.setDeferredStatus('failed');
|
1883
|
+
|
1884
|
+
var retry = self._client.retry * 1000;
|
1885
|
+
Faye.ENV.setTimeout(function() { self.connect() }, retry);
|
1886
|
+
self.trigger('down');
|
1887
|
+
};
|
1888
|
+
},
|
1889
|
+
|
1890
|
+
resend: function() {
|
1891
|
+
if (!this._messages) return;
|
1892
|
+
var messages = Faye.map(this._messages, function(id, msg) { return msg });
|
1893
|
+
this.request(messages);
|
1894
|
+
}
|
1895
|
+
}), {
|
1896
|
+
getSocketUrl: function(endpoint) {
|
1897
|
+
if (Faye.URI) endpoint = Faye.URI.parse(endpoint).toURL();
|
1898
|
+
return endpoint.replace(/^http(s?):/ig, 'ws$1:');
|
1899
|
+
},
|
1900
|
+
|
1901
|
+
getClass: function() {
|
1902
|
+
return (Faye.WebSocket && Faye.WebSocket.Client) ||
|
1903
|
+
Faye.ENV.WebSocket ||
|
1904
|
+
Faye.ENV.MozWebSocket;
|
1905
|
+
},
|
1906
|
+
|
1907
|
+
isUsable: function(client, endpoint, callback, context) {
|
1908
|
+
this.create(client, endpoint).isUsable(callback, context);
|
1909
|
+
},
|
1910
|
+
|
1911
|
+
create: function(client, endpoint) {
|
1912
|
+
var sockets = client.transports.websocket = client.transports.websocket || {};
|
1913
|
+
sockets[endpoint] = sockets[endpoint] || new this(client, endpoint);
|
1914
|
+
return sockets[endpoint];
|
1915
|
+
}
|
1916
|
+
});
|
1917
|
+
|
1918
|
+
Faye.extend(Faye.Transport.WebSocket.prototype, Faye.Deferrable);
|
1919
|
+
Faye.Transport.register('websocket', Faye.Transport.WebSocket);
|
1920
|
+
|
1921
|
+
if (Faye.Event)
|
1922
|
+
Faye.Event.on(Faye.ENV, 'beforeunload', function() {
|
1923
|
+
Faye.Transport.WebSocket._unloaded = true;
|
1924
|
+
});
|
1925
|
+
|
1926
|
+
|
1927
|
+
Faye.Transport.EventSource = Faye.extend(Faye.Class(Faye.Transport, {
|
1928
|
+
initialize: function(client, endpoint) {
|
1929
|
+
Faye.Transport.prototype.initialize.call(this, client, endpoint);
|
1930
|
+
if (!Faye.ENV.EventSource) return this.setDeferredStatus('failed');
|
1931
|
+
|
1932
|
+
this._xhr = new Faye.Transport.XHR(client, endpoint);
|
1933
|
+
|
1934
|
+
var socket = new EventSource(endpoint + '/' + client.getClientId()),
|
1935
|
+
self = this;
|
1936
|
+
|
1937
|
+
socket.onopen = function() {
|
1938
|
+
self._everConnected = true;
|
1939
|
+
self.setDeferredStatus('succeeded');
|
1940
|
+
self.trigger('up');
|
1941
|
+
};
|
1942
|
+
|
1943
|
+
socket.onerror = function() {
|
1944
|
+
if (self._everConnected) {
|
1945
|
+
self.trigger('down');
|
1946
|
+
} else {
|
1947
|
+
self.setDeferredStatus('failed');
|
1948
|
+
socket.close();
|
1949
|
+
}
|
1950
|
+
};
|
1951
|
+
|
1952
|
+
socket.onmessage = function(event) {
|
1953
|
+
self.receive(JSON.parse(event.data));
|
1954
|
+
self.trigger('up');
|
1955
|
+
};
|
1956
|
+
|
1957
|
+
this._socket = socket;
|
1958
|
+
},
|
1959
|
+
|
1960
|
+
isUsable: function(callback, context) {
|
1961
|
+
this.callback(function() { callback.call(context, true) });
|
1962
|
+
this.errback(function() { callback.call(context, false) });
|
1963
|
+
},
|
1964
|
+
|
1965
|
+
request: function(message, timeout) {
|
1966
|
+
this._xhr.request(message, timeout);
|
1967
|
+
},
|
1968
|
+
|
1969
|
+
close: function() {
|
1970
|
+
if (!this._socket) return;
|
1971
|
+
this._socket.onerror = null;
|
1972
|
+
this._socket.close();
|
1973
|
+
delete this._socket;
|
1974
|
+
}
|
1975
|
+
}), {
|
1976
|
+
isUsable: function(client, endpoint, callback, context) {
|
1977
|
+
var id = client.getClientId();
|
1978
|
+
if (!id) return callback.call(context, false);
|
1979
|
+
|
1980
|
+
Faye.Transport.XHR.isUsable(client, endpoint, function(usable) {
|
1981
|
+
if (!usable) return callback.call(context, false);
|
1982
|
+
this.create(client, endpoint).isUsable(callback, context);
|
1983
|
+
}, this);
|
1984
|
+
},
|
1985
|
+
|
1986
|
+
create: function(client, endpoint) {
|
1987
|
+
var sockets = client.transports.eventsource = client.transports.eventsource || {},
|
1988
|
+
id = client.getClientId(),
|
1989
|
+
endpoint = endpoint + '/' + (id || '');
|
1990
|
+
|
1991
|
+
sockets[endpoint] = sockets[endpoint] || new this(client, endpoint);
|
1992
|
+
return sockets[endpoint];
|
1993
|
+
}
|
1994
|
+
});
|
1995
|
+
|
1996
|
+
Faye.extend(Faye.Transport.EventSource.prototype, Faye.Deferrable);
|
1997
|
+
Faye.Transport.register('eventsource', Faye.Transport.EventSource);
|
1998
|
+
|
1999
|
+
|
2000
|
+
Faye.Transport.XHR = Faye.extend(Faye.Class(Faye.Transport, {
|
2001
|
+
request: function(message, timeout) {
|
2002
|
+
var retry = this.retry(message, timeout),
|
2003
|
+
path = Faye.URI.parse(this.endpoint).pathname,
|
2004
|
+
self = this,
|
2005
|
+
xhr = Faye.ENV.ActiveXObject
|
2006
|
+
? new ActiveXObject("Microsoft.XMLHTTP")
|
2007
|
+
: new XMLHttpRequest();
|
2008
|
+
|
2009
|
+
xhr.open('POST', path, true);
|
2010
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
2011
|
+
xhr.setRequestHeader('Pragma', 'no-cache');
|
2012
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
2013
|
+
|
2014
|
+
var headers = this.headers;
|
2015
|
+
for (var key in headers) {
|
2016
|
+
if (!headers.hasOwnProperty(key)) continue;
|
2017
|
+
xhr.setRequestHeader(key, headers[key]);
|
2018
|
+
}
|
2019
|
+
|
2020
|
+
var abort = function() { xhr.abort() };
|
2021
|
+
Faye.Event.on(Faye.ENV, 'beforeunload', abort);
|
2022
|
+
|
2023
|
+
var cleanUp = function() {
|
2024
|
+
Faye.Event.detach(Faye.ENV, 'beforeunload', abort);
|
2025
|
+
xhr.onreadystatechange = function() {};
|
2026
|
+
xhr = null;
|
2027
|
+
};
|
2028
|
+
|
2029
|
+
xhr.onreadystatechange = function() {
|
2030
|
+
if (xhr.readyState !== 4) return;
|
2031
|
+
|
2032
|
+
var parsedMessage = null,
|
2033
|
+
status = xhr.status,
|
2034
|
+
successful = ((status >= 200 && status < 300) ||
|
2035
|
+
status === 304 ||
|
2036
|
+
status === 1223);
|
2037
|
+
|
2038
|
+
if (!successful) {
|
2039
|
+
cleanUp();
|
2040
|
+
retry();
|
2041
|
+
return self.trigger('down');
|
2042
|
+
}
|
2043
|
+
|
2044
|
+
try {
|
2045
|
+
parsedMessage = JSON.parse(xhr.responseText);
|
2046
|
+
} catch (e) {}
|
2047
|
+
|
2048
|
+
cleanUp();
|
2049
|
+
|
2050
|
+
if (parsedMessage) {
|
2051
|
+
self.receive(parsedMessage);
|
2052
|
+
self.trigger('up');
|
2053
|
+
} else {
|
2054
|
+
retry();
|
2055
|
+
self.trigger('down');
|
2056
|
+
}
|
2057
|
+
};
|
2058
|
+
|
2059
|
+
xhr.send(Faye.toJSON(message));
|
2060
|
+
}
|
2061
|
+
}), {
|
2062
|
+
isUsable: function(client, endpoint, callback, context) {
|
2063
|
+
callback.call(context, Faye.URI.parse(endpoint).isSameOrigin());
|
2064
|
+
}
|
2065
|
+
});
|
2066
|
+
|
2067
|
+
Faye.Transport.register('long-polling', Faye.Transport.XHR);
|
2068
|
+
|
2069
|
+
Faye.Transport.CORS = Faye.extend(Faye.Class(Faye.Transport, {
|
2070
|
+
request: function(message, timeout) {
|
2071
|
+
var xhrClass = Faye.ENV.XDomainRequest ? XDomainRequest : XMLHttpRequest,
|
2072
|
+
xhr = new xhrClass(),
|
2073
|
+
retry = this.retry(message, timeout),
|
2074
|
+
self = this;
|
2075
|
+
|
2076
|
+
xhr.open('POST', this.endpoint, true);
|
2077
|
+
if (xhr.setRequestHeader) xhr.setRequestHeader('Pragma', 'no-cache');
|
2078
|
+
|
2079
|
+
var cleanUp = function() {
|
2080
|
+
if (!xhr) return false;
|
2081
|
+
xhr.onload = xhr.onerror = xhr.ontimeout = xhr.onprogress = null;
|
2082
|
+
xhr = null;
|
2083
|
+
Faye.ENV.clearTimeout(timer);
|
2084
|
+
return true;
|
2085
|
+
};
|
2086
|
+
|
2087
|
+
xhr.onload = function() {
|
2088
|
+
var parsedMessage = null;
|
2089
|
+
try {
|
2090
|
+
parsedMessage = JSON.parse(xhr.responseText);
|
2091
|
+
} catch (e) {}
|
2092
|
+
|
2093
|
+
cleanUp();
|
2094
|
+
|
2095
|
+
if (parsedMessage) {
|
2096
|
+
self.receive(parsedMessage);
|
2097
|
+
self.trigger('up');
|
2098
|
+
} else {
|
2099
|
+
retry();
|
2100
|
+
self.trigger('down');
|
2101
|
+
}
|
2102
|
+
};
|
2103
|
+
|
2104
|
+
var onerror = function() {
|
2105
|
+
cleanUp();
|
2106
|
+
retry();
|
2107
|
+
self.trigger('down');
|
2108
|
+
};
|
2109
|
+
var timer = Faye.ENV.setTimeout(onerror, 1.5 * 1000 * timeout);
|
2110
|
+
xhr.onerror = onerror;
|
2111
|
+
xhr.ontimeout = onerror;
|
2112
|
+
|
2113
|
+
xhr.onprogress = function() {};
|
2114
|
+
xhr.send('message=' + encodeURIComponent(Faye.toJSON(message)));
|
2115
|
+
}
|
2116
|
+
}), {
|
2117
|
+
isUsable: function(client, endpoint, callback, context) {
|
2118
|
+
if (Faye.URI.parse(endpoint).isSameOrigin())
|
2119
|
+
return callback.call(context, false);
|
2120
|
+
|
2121
|
+
if (Faye.ENV.XDomainRequest)
|
2122
|
+
return callback.call(context, Faye.URI.parse(endpoint).protocol ===
|
2123
|
+
Faye.URI.parse(Faye.ENV.location).protocol);
|
2124
|
+
|
2125
|
+
if (Faye.ENV.XMLHttpRequest) {
|
2126
|
+
var xhr = new Faye.ENV.XMLHttpRequest();
|
2127
|
+
return callback.call(context, xhr.withCredentials !== undefined);
|
2128
|
+
}
|
2129
|
+
return callback.call(context, false);
|
2130
|
+
}
|
2131
|
+
});
|
2132
|
+
|
2133
|
+
Faye.Transport.register('cross-origin-long-polling', Faye.Transport.CORS);
|
2134
|
+
|
2135
|
+
|
2136
|
+
Faye.Transport.JSONP = Faye.extend(Faye.Class(Faye.Transport, {
|
2137
|
+
shouldFlush: function(messages) {
|
2138
|
+
var params = {
|
2139
|
+
message: Faye.toJSON(messages),
|
2140
|
+
jsonp: '__jsonp' + Faye.Transport.JSONP._cbCount + '__'
|
2141
|
+
};
|
2142
|
+
var location = Faye.URI.parse(this.endpoint, params).toURL();
|
2143
|
+
return location.length >= Faye.Transport.MAX_URL_LENGTH;
|
2144
|
+
},
|
2145
|
+
|
2146
|
+
request: function(messages, timeout) {
|
2147
|
+
var params = {message: Faye.toJSON(messages)},
|
2148
|
+
head = document.getElementsByTagName('head')[0],
|
2149
|
+
script = document.createElement('script'),
|
2150
|
+
callbackName = Faye.Transport.JSONP.getCallbackName(),
|
2151
|
+
location = Faye.URI.parse(this.endpoint, params),
|
2152
|
+
retry = this.retry(messages, timeout),
|
2153
|
+
self = this;
|
2154
|
+
|
2155
|
+
Faye.ENV[callbackName] = function(data) {
|
2156
|
+
cleanUp();
|
2157
|
+
self.receive(data);
|
2158
|
+
self.trigger('up');
|
2159
|
+
};
|
2160
|
+
|
2161
|
+
var timer = Faye.ENV.setTimeout(function() {
|
2162
|
+
cleanUp();
|
2163
|
+
retry();
|
2164
|
+
self.trigger('down');
|
2165
|
+
}, 1.5 * 1000 * timeout);
|
2166
|
+
|
2167
|
+
var cleanUp = function() {
|
2168
|
+
if (!Faye.ENV[callbackName]) return false;
|
2169
|
+
Faye.ENV[callbackName] = undefined;
|
2170
|
+
try { delete Faye.ENV[callbackName] } catch (e) {}
|
2171
|
+
Faye.ENV.clearTimeout(timer);
|
2172
|
+
script.parentNode.removeChild(script);
|
2173
|
+
return true;
|
2174
|
+
};
|
2175
|
+
|
2176
|
+
location.params.jsonp = callbackName;
|
2177
|
+
script.type = 'text/javascript';
|
2178
|
+
script.src = location.toURL();
|
2179
|
+
head.appendChild(script);
|
2180
|
+
}
|
2181
|
+
}), {
|
2182
|
+
_cbCount: 0,
|
2183
|
+
|
2184
|
+
getCallbackName: function() {
|
2185
|
+
this._cbCount += 1;
|
2186
|
+
return '__jsonp' + this._cbCount + '__';
|
2187
|
+
},
|
2188
|
+
|
2189
|
+
isUsable: function(client, endpoint, callback, context) {
|
2190
|
+
callback.call(context, true);
|
2191
|
+
}
|
2192
|
+
});
|
2193
|
+
|
2194
|
+
Faye.Transport.register('callback-polling', Faye.Transport.JSONP);
|