jstp 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/jstp/api.rb +7 -3
- data/lib/jstp/version.rb +1 -1
- data/lib/writer/jstp/connector.rb +23 -5
- data/spec/jstp/api_spec.rb +8 -0
- data/spec/jstp/web_socket_spec.rb +4 -0
- metadata +2 -2
data/lib/jstp/api.rb
CHANGED
@@ -2,9 +2,13 @@
|
|
2
2
|
module JSTP
|
3
3
|
module API
|
4
4
|
def dispatch *args, &block
|
5
|
-
if args.empty?
|
6
|
-
|
7
|
-
|
5
|
+
if args.empty?
|
6
|
+
if block
|
7
|
+
Connector.instance.block = block
|
8
|
+
Connector.instance.from.send Connector.instance.strategy.inbound
|
9
|
+
else
|
10
|
+
Connector.instance
|
11
|
+
end
|
8
12
|
else
|
9
13
|
Connector.instance.to.send Connector.instance.strategy.outbound, args.first
|
10
14
|
end
|
data/lib/jstp/version.rb
CHANGED
@@ -9,11 +9,29 @@ module Writer
|
|
9
9
|
|
10
10
|
# Dispatch this applying the websocket strategy
|
11
11
|
def websocket message
|
12
|
-
|
13
|
-
.
|
14
|
-
|
15
|
-
|
16
|
-
this_client.
|
12
|
+
begin
|
13
|
+
this_client = ::JSTP::WebSocket.instance
|
14
|
+
.client message["resource"]
|
15
|
+
json = message.to_json
|
16
|
+
this_client.callback do
|
17
|
+
this_client.send_msg json
|
18
|
+
this_client.close_connection_after_writing
|
19
|
+
end
|
20
|
+
rescue RuntimeError => e
|
21
|
+
EM.run {
|
22
|
+
this_client = ::JSTP::WebSocket.instance
|
23
|
+
.client message["resource"]
|
24
|
+
json = message.to_json
|
25
|
+
|
26
|
+
this_client.callback do
|
27
|
+
this_client.send_msg json
|
28
|
+
this_client.close_connection_after_writing
|
29
|
+
end
|
30
|
+
|
31
|
+
this_client.disconnect do
|
32
|
+
EM::stop_event_loop
|
33
|
+
end
|
34
|
+
}
|
17
35
|
end
|
18
36
|
end
|
19
37
|
|
data/spec/jstp/api_spec.rb
CHANGED
@@ -53,6 +53,14 @@ describe JSTP::API do
|
|
53
53
|
o.dispatch message
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
context 'no argument, no block' do
|
58
|
+
it 'should return the JSTP::Connector.instance' do
|
59
|
+
o = Object.new
|
60
|
+
o.extend JSTP::API
|
61
|
+
o.dispatch.should == JSTP::Connector.instance
|
62
|
+
end
|
63
|
+
end
|
56
64
|
end
|
57
65
|
|
58
66
|
describe '#port' do
|
@@ -24,6 +24,8 @@ describe JSTP::WebSocket do
|
|
24
24
|
|
25
25
|
describe '#server_setup' do
|
26
26
|
it 'should set #event_on_message to onmessage' do
|
27
|
+
pending 'Outdated example'
|
28
|
+
|
27
29
|
server = stub 'server'
|
28
30
|
JSTP::WebSocket.instance.event_on_message.should_receive :call
|
29
31
|
|
@@ -36,6 +38,8 @@ describe JSTP::WebSocket do
|
|
36
38
|
|
37
39
|
describe '#event_on_message' do
|
38
40
|
it 'should call the registered block with the parsed message' do
|
41
|
+
pending 'Outdated example'
|
42
|
+
|
39
43
|
@the_proc = stub 'the proc'
|
40
44
|
@message = stub 'message'
|
41
45
|
@parsed_message = stub 'parsed message'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jstp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-01-
|
14
|
+
date: 2013-01-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: em-websocket
|