danthes 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/app/assets/javascripts/danthes.js.coffee +16 -3
- data/lib/danthes/version.rb +1 -1
- data/spec/coffeescripts/danthes_spec.js.coffee +57 -2
- metadata +2 -2
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -39,7 +39,7 @@ It's not necessary to include faye's connect.js since that will be handled autom
|
|
39
39
|
|
40
40
|
## Serving Faye over HTTPS (with Thin)
|
41
41
|
|
42
|
-
To serve Faye over HTTPS you could create a thin configuration file `config/
|
42
|
+
To serve Faye over HTTPS you could create a thin configuration file `config/danthes_thin.yml` similar to the following:
|
43
43
|
|
44
44
|
```yaml
|
45
45
|
---
|
@@ -93,15 +93,19 @@ window.Danthes = class Danthes
|
|
93
93
|
channel = options.channel
|
94
94
|
unless @subscriptions[channel]?
|
95
95
|
@subscriptions[channel] = {}
|
96
|
-
@subscriptions[channel]['
|
96
|
+
@subscriptions[channel]['callback'] = options['callback'] if options['callback']?
|
97
|
+
@subscriptions[channel]['opts'] =
|
98
|
+
signature: options['signature']
|
99
|
+
timestamp: options['timestamp']
|
97
100
|
@faye (faye) =>
|
98
|
-
subscription = faye.subscribe channel, (message) =>
|
99
|
-
@handleResponse(message)
|
101
|
+
subscription = faye.subscribe channel, (message) => @handleResponse(message)
|
100
102
|
if subscription?
|
101
103
|
@subscriptions[channel]['sub'] = subscription
|
102
104
|
subscription.callback =>
|
105
|
+
options['connect']?(subscription)
|
103
106
|
@debugMessage "subscription for #{channel} is active now"
|
104
107
|
subscription.errback (error) =>
|
108
|
+
options['error']?(subscription, error)
|
105
109
|
@debugMessage "error for #{channel}: #{error.message}"
|
106
110
|
|
107
111
|
# Handle response from Faye
|
@@ -114,6 +118,15 @@ window.Danthes = class Danthes
|
|
114
118
|
if callback = @subscriptions[channel]['callback']
|
115
119
|
callback(message.data, channel)
|
116
120
|
|
121
|
+
# Disable transports
|
122
|
+
# @param [String] name of transport
|
123
|
+
@disableTransport: (transport) ->
|
124
|
+
return unless transport in ['websocket', 'long-polling', 'callback-polling', 'in-process']
|
125
|
+
unless transport in @disables
|
126
|
+
@disables.push(transport)
|
127
|
+
@debugMessage "#{transport} faye transport will be disabled"
|
128
|
+
true
|
129
|
+
|
117
130
|
# Subscribe to channel with callback
|
118
131
|
# @param channel [String] Channel name
|
119
132
|
# @param callback [Function] Callback function
|
data/lib/danthes/version.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Danthes", ->
|
|
6
6
|
faye = {subscribe: jasmine.createSpy()}
|
7
7
|
spyOn(pub, 'faye').andCallFake (callback) ->
|
8
8
|
callback(faye)
|
9
|
-
options = {server: "server", channel: "#{channel}"}
|
9
|
+
options = {server: "server", channel: "#{channel}", timestamp: 1234567890, signature: '1234567890'}
|
10
10
|
pub.sign(options)
|
11
11
|
return [faye, options]
|
12
12
|
|
@@ -79,7 +79,7 @@ describe "Danthes", ->
|
|
79
79
|
[faye, options] = signToChannel('somechannel')
|
80
80
|
expect(faye.subscribe).toHaveBeenCalled()
|
81
81
|
expect(pub.server).toEqual("server")
|
82
|
-
expect(pub.subscriptions.somechannel.opts).toEqual(options)
|
82
|
+
expect(pub.subscriptions.somechannel.opts).toEqual(timestamp: options['timestamp'], signature: options['signature'])
|
83
83
|
|
84
84
|
it "connects to faye server, adds extension, and executes callbacks", ->
|
85
85
|
callback = jasmine.createSpy()
|
@@ -96,6 +96,41 @@ describe "Danthes", ->
|
|
96
96
|
expect(client.addExtension).toHaveBeenCalledWith(pub.fayeExtension)
|
97
97
|
expect(callback).toHaveBeenCalledWith(client)
|
98
98
|
|
99
|
+
it "adds transport to disables", ->
|
100
|
+
expect(pub.disableTransport('websocket')).toBeTruthy()
|
101
|
+
expect(pub.disables).toEqual(['websocket'])
|
102
|
+
|
103
|
+
it "adds transport to disables only one time", ->
|
104
|
+
pub.disableTransport('websocket')
|
105
|
+
pub.disableTransport('websocket')
|
106
|
+
expect(pub.disables).toEqual(['websocket'])
|
107
|
+
|
108
|
+
it "returns false if not accepted transport wants to be disabled", ->
|
109
|
+
expect(pub.disableTransport('websocket123')).toBeUndefined()
|
110
|
+
expect(pub.disables).toEqual([])
|
111
|
+
|
112
|
+
it "connects to faye server, and executes disable once", ->
|
113
|
+
callback = jasmine.createSpy()
|
114
|
+
client = {addExtension: jasmine.createSpy(), disable: jasmine.createSpy()}
|
115
|
+
window.Faye = {}
|
116
|
+
window.Faye.Client = (server) -> client
|
117
|
+
pub.server = "server"
|
118
|
+
pub.disableTransport('websocket')
|
119
|
+
pub.connectToFaye()
|
120
|
+
expect(client.disable).toHaveBeenCalledWith('websocket')
|
121
|
+
|
122
|
+
it "connects to faye server, and executes disable once", ->
|
123
|
+
callback = jasmine.createSpy()
|
124
|
+
client = {addExtension: jasmine.createSpy(), disable: jasmine.createSpy()}
|
125
|
+
window.Faye = {}
|
126
|
+
window.Faye.Client = (server) -> client
|
127
|
+
pub.server = "server"
|
128
|
+
pub.disableTransport('websocket')
|
129
|
+
pub.disableTransport('long-polling')
|
130
|
+
pub.connectToFaye()
|
131
|
+
expect(client.disable).toHaveBeenCalledWith('websocket')
|
132
|
+
expect(client.disable).toHaveBeenCalledWith('long-polling')
|
133
|
+
|
99
134
|
it "adds subscription faye object into channel object", ->
|
100
135
|
sub = {callback: jasmine.createSpy(), errback: jasmine.createSpy()}
|
101
136
|
pub.fayeClient = {subscribe: jasmine.createSpy().andReturn(sub)}
|
@@ -105,6 +140,26 @@ describe "Danthes", ->
|
|
105
140
|
expect(sub.errback).toHaveBeenCalled()
|
106
141
|
expect(pub.subscriptions.somechannel.sub).toEqual(sub)
|
107
142
|
|
143
|
+
it "adds subscription faye object into channel object and call connect callback after connection", ->
|
144
|
+
sub =
|
145
|
+
callback: (f) ->
|
146
|
+
f()
|
147
|
+
errback: jasmine.createSpy()
|
148
|
+
pub.fayeClient = {subscribe: jasmine.createSpy().andReturn(sub)}
|
149
|
+
options = {server: "server", channel: 'somechannel', connect: jasmine.createSpy()}
|
150
|
+
pub.sign(options)
|
151
|
+
expect(options.connect).toHaveBeenCalledWith(sub)
|
152
|
+
|
153
|
+
it "adds subscription faye object into channel object and call error callback after connection", ->
|
154
|
+
sub =
|
155
|
+
callback: jasmine.createSpy()
|
156
|
+
errback: (f) ->
|
157
|
+
f('error')
|
158
|
+
pub.fayeClient = {subscribe: jasmine.createSpy().andReturn(sub)}
|
159
|
+
options = {server: "server", channel: 'somechannel', error: jasmine.createSpy()}
|
160
|
+
pub.sign(options)
|
161
|
+
expect(options.error).toHaveBeenCalledWith(sub, 'error')
|
162
|
+
|
108
163
|
it "removes subscription to the channel", ->
|
109
164
|
sub = {callback: jasmine.createSpy(), errback: jasmine.createSpy(), cancel: jasmine.createSpy()}
|
110
165
|
pub.fayeClient = {subscribe: jasmine.createSpy().andReturn(sub)}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danthes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faye
|