wamp_client 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +28 -26
- data/lib/{wamp_client.rb → wamp/client.rb} +8 -8
- data/lib/{wamp_client → wamp/client}/auth.rb +13 -11
- data/lib/wamp/client/check.rb +86 -0
- data/lib/wamp/client/connection.rb +249 -0
- data/lib/{wamp_client → wamp/client}/defer.rb +29 -27
- data/lib/wamp/client/message.rb +1322 -0
- data/lib/{wamp_client → wamp/client}/serializer.rb +26 -24
- data/lib/wamp/client/session.rb +1001 -0
- data/lib/wamp/client/transport/base.rb +152 -0
- data/lib/{wamp_client → wamp/client}/transport/event_machine_base.rb +19 -17
- data/lib/wamp/client/transport/faye_web_socket.rb +85 -0
- data/lib/wamp/client/transport/web_socket_event_machine.rb +88 -0
- data/lib/{wamp_client → wamp/client}/version.rb +5 -3
- data/scripts/gen_message.rb +54 -53
- data/spec/spec_helper.rb +3 -3
- data/spec/{auth_spec.rb → wamp/client/auth_spec.rb} +2 -2
- data/spec/{check_spec.rb → wamp/client/check_spec.rb} +2 -2
- data/spec/{connection_spec.rb → wamp/client/connection_spec.rb} +7 -7
- data/spec/{message_spec.rb → wamp/client/message_spec.rb} +298 -298
- data/spec/{session_spec.rb → wamp/client/session_spec.rb} +134 -134
- data/spec/{transport_spec.rb → wamp/client/transport_spec.rb} +4 -4
- data/wamp_client.gemspec +2 -2
- metadata +50 -50
- data/lib/wamp_client/check.rb +0 -84
- data/lib/wamp_client/connection.rb +0 -247
- data/lib/wamp_client/message.rb +0 -1348
- data/lib/wamp_client/session.rb +0 -1000
- data/lib/wamp_client/transport/base.rb +0 -151
- data/lib/wamp_client/transport/faye_web_socket.rb +0 -83
- data/lib/wamp_client/transport/web_socket_event_machine.rb +0 -86
@@ -3,8 +3,8 @@ require "rspec/em"
|
|
3
3
|
require 'websocket-eventmachine-client'
|
4
4
|
require 'faye/websocket'
|
5
5
|
|
6
|
-
describe
|
7
|
-
describe
|
6
|
+
describe Wamp::Client::Transport do
|
7
|
+
describe Wamp::Client::Transport::EventMachineBase do
|
8
8
|
it '#start/stop' do
|
9
9
|
value = 0
|
10
10
|
described_class.start_event_machine do
|
@@ -65,7 +65,7 @@ describe WampClient::Transport do
|
|
65
65
|
}
|
66
66
|
}
|
67
67
|
|
68
|
-
describe
|
68
|
+
describe Wamp::Client::Transport::WebSocketEventMachine do
|
69
69
|
include RSpec::EM::FakeClock
|
70
70
|
before { clock.stub }
|
71
71
|
after { clock.reset }
|
@@ -131,7 +131,7 @@ describe WampClient::Transport do
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
describe
|
134
|
+
describe Wamp::Client::Transport::FayeWebSocket do
|
135
135
|
include RSpec::EM::FakeClock
|
136
136
|
before { clock.stub }
|
137
137
|
after { clock.reset }
|
data/wamp_client.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'wamp/client/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'wamp_client'
|
8
|
-
spec.version =
|
8
|
+
spec.version = Wamp::Client::VERSION
|
9
9
|
spec.authors = ['Eric Chapman']
|
10
10
|
spec.email = ['eric.chappy@gmail.com']
|
11
11
|
spec.summary = %q{Web Application Messaging Protocol Client}
|
metadata
CHANGED
@@ -1,139 +1,139 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wamp_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Chapman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 3.5.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.5.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec-eventmachine
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.2.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.2.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: codecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: faye-websocket
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: 0.10.4
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 0.10.4
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: websocket-eventmachine-client
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: 1.1.0
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 1.1.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: json
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - '>='
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - '>='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
description: An implementation of The Web Application Messaging Protocol (WAMP)
|
@@ -143,34 +143,34 @@ executables: []
|
|
143
143
|
extensions: []
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
|
-
-
|
147
|
-
-
|
146
|
+
- .gitignore
|
147
|
+
- .ruby-version
|
148
148
|
- Gemfile
|
149
149
|
- LICENSE.txt
|
150
150
|
- README.md
|
151
151
|
- Rakefile
|
152
152
|
- circle.yml
|
153
|
-
- lib/
|
154
|
-
- lib/
|
155
|
-
- lib/
|
156
|
-
- lib/
|
157
|
-
- lib/
|
158
|
-
- lib/
|
159
|
-
- lib/
|
160
|
-
- lib/
|
161
|
-
- lib/
|
162
|
-
- lib/
|
163
|
-
- lib/
|
164
|
-
- lib/
|
165
|
-
- lib/
|
153
|
+
- lib/wamp/client.rb
|
154
|
+
- lib/wamp/client/auth.rb
|
155
|
+
- lib/wamp/client/check.rb
|
156
|
+
- lib/wamp/client/connection.rb
|
157
|
+
- lib/wamp/client/defer.rb
|
158
|
+
- lib/wamp/client/message.rb
|
159
|
+
- lib/wamp/client/serializer.rb
|
160
|
+
- lib/wamp/client/session.rb
|
161
|
+
- lib/wamp/client/transport/base.rb
|
162
|
+
- lib/wamp/client/transport/event_machine_base.rb
|
163
|
+
- lib/wamp/client/transport/faye_web_socket.rb
|
164
|
+
- lib/wamp/client/transport/web_socket_event_machine.rb
|
165
|
+
- lib/wamp/client/version.rb
|
166
166
|
- scripts/gen_message.rb
|
167
|
-
- spec/auth_spec.rb
|
168
|
-
- spec/check_spec.rb
|
169
|
-
- spec/connection_spec.rb
|
170
|
-
- spec/message_spec.rb
|
171
|
-
- spec/session_spec.rb
|
172
167
|
- spec/spec_helper.rb
|
173
|
-
- spec/
|
168
|
+
- spec/wamp/client/auth_spec.rb
|
169
|
+
- spec/wamp/client/check_spec.rb
|
170
|
+
- spec/wamp/client/connection_spec.rb
|
171
|
+
- spec/wamp/client/message_spec.rb
|
172
|
+
- spec/wamp/client/session_spec.rb
|
173
|
+
- spec/wamp/client/transport_spec.rb
|
174
174
|
- tasks/rspec.rake
|
175
175
|
- wamp_client.gemspec
|
176
176
|
homepage: https://github.com/ericchapman/ruby_wamp_client
|
@@ -183,25 +183,25 @@ require_paths:
|
|
183
183
|
- lib
|
184
184
|
required_ruby_version: !ruby/object:Gem::Requirement
|
185
185
|
requirements:
|
186
|
-
- -
|
186
|
+
- - '>='
|
187
187
|
- !ruby/object:Gem::Version
|
188
188
|
version: '2.0'
|
189
189
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
190
|
requirements:
|
191
|
-
- -
|
191
|
+
- - '>='
|
192
192
|
- !ruby/object:Gem::Version
|
193
193
|
version: '0'
|
194
194
|
requirements: []
|
195
195
|
rubyforge_project:
|
196
|
-
rubygems_version: 2.
|
196
|
+
rubygems_version: 2.4.8
|
197
197
|
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Web Application Messaging Protocol Client
|
200
200
|
test_files:
|
201
|
-
- spec/auth_spec.rb
|
202
|
-
- spec/check_spec.rb
|
203
|
-
- spec/connection_spec.rb
|
204
|
-
- spec/message_spec.rb
|
205
|
-
- spec/session_spec.rb
|
206
201
|
- spec/spec_helper.rb
|
207
|
-
- spec/
|
202
|
+
- spec/wamp/client/auth_spec.rb
|
203
|
+
- spec/wamp/client/check_spec.rb
|
204
|
+
- spec/wamp/client/connection_spec.rb
|
205
|
+
- spec/wamp/client/message_spec.rb
|
206
|
+
- spec/wamp/client/session_spec.rb
|
207
|
+
- spec/wamp/client/transport_spec.rb
|
data/lib/wamp_client/check.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
|
3
|
-
Copyright (c) 2016 Eric Chapman
|
4
|
-
|
5
|
-
MIT License
|
6
|
-
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
8
|
-
a copy of this software and associated documentation files (the
|
9
|
-
"Software"), to deal in the Software without restriction, including
|
10
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
11
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
-
permit persons to whom the Software is furnished to do so, subject to
|
13
|
-
the following conditions:
|
14
|
-
|
15
|
-
The above copyright notice and this permission notice shall be
|
16
|
-
included in all copies or substantial portions of the Software.
|
17
|
-
|
18
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
-
|
26
|
-
=end
|
27
|
-
|
28
|
-
module WampClient
|
29
|
-
module Check
|
30
|
-
|
31
|
-
def self.included(base)
|
32
|
-
base.extend(ClassMethods)
|
33
|
-
end
|
34
|
-
|
35
|
-
module ClassMethods
|
36
|
-
|
37
|
-
def check_equal(name, expected, value)
|
38
|
-
raise ArgumentError, "The '#{name}' argument must have the value '#{expected}'. Instead the value was '#{value}'" unless value == expected
|
39
|
-
end
|
40
|
-
|
41
|
-
def check_gte(name, expected, value)
|
42
|
-
raise ArgumentError, "The '#{name}' argument must be greater than or equal to '#{expected}'. Instead the value was '#{value}'" unless value >= expected
|
43
|
-
end
|
44
|
-
|
45
|
-
def check_nil(name, param, nil_allowed)
|
46
|
-
raise ArgumentError, "The '#{name}' argument cannot be nil" if param.nil? and not nil_allowed
|
47
|
-
end
|
48
|
-
|
49
|
-
def check_int(name, param, nil_allowed=false)
|
50
|
-
check_nil(name, param, nil_allowed)
|
51
|
-
raise ArgumentError, "The '#{name}' argument must be an integer" unless param.nil? or param.is_a? Integer
|
52
|
-
end
|
53
|
-
|
54
|
-
def check_string(name, param, nil_allowed=false)
|
55
|
-
check_nil(name, param, nil_allowed)
|
56
|
-
raise ArgumentError, "The '#{name}' argument must be a string" unless param.nil? or param.is_a? String
|
57
|
-
end
|
58
|
-
|
59
|
-
def check_bool(name, param, nil_allowed=false)
|
60
|
-
check_nil(name, param, nil_allowed)
|
61
|
-
raise ArgumentError, "The '#{name}' argument must be a boolean" unless param.nil? or !!param == param
|
62
|
-
end
|
63
|
-
|
64
|
-
def check_dict(name, param, nil_allowed=false)
|
65
|
-
check_nil(name, param, nil_allowed)
|
66
|
-
raise ArgumentError, "The '#{name}' argument must be a hash" unless param.nil? or param.is_a? Hash
|
67
|
-
end
|
68
|
-
|
69
|
-
def check_list(name, param, nil_allowed=false)
|
70
|
-
check_nil(name, param, nil_allowed)
|
71
|
-
raise ArgumentError, "The '#{name}' argument must be an array" unless param.nil? or param.is_a? Array
|
72
|
-
end
|
73
|
-
|
74
|
-
def check_uri(name, param, nil_allowed=false)
|
75
|
-
check_string(name, param, nil_allowed)
|
76
|
-
end
|
77
|
-
|
78
|
-
def check_id(name, param, nil_allowed=false)
|
79
|
-
check_int(name, param, nil_allowed)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
end
|
@@ -1,247 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
|
3
|
-
Copyright (c) 2016 Eric Chapman
|
4
|
-
|
5
|
-
MIT License
|
6
|
-
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
8
|
-
a copy of this software and associated documentation files (the
|
9
|
-
"Software"), to deal in the Software without restriction, including
|
10
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
11
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
-
permit persons to whom the Software is furnished to do so, subject to
|
13
|
-
the following conditions:
|
14
|
-
|
15
|
-
The above copyright notice and this permission notice shall be
|
16
|
-
included in all copies or substantial portions of the Software.
|
17
|
-
|
18
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
-
|
26
|
-
=end
|
27
|
-
|
28
|
-
require 'wamp_client/session'
|
29
|
-
require 'wamp_client/transport/web_socket_event_machine'
|
30
|
-
require 'wamp_client/transport/faye_web_socket'
|
31
|
-
|
32
|
-
module WampClient
|
33
|
-
class Connection
|
34
|
-
attr_accessor :options, :transport_class, :transport, :session, :verbose
|
35
|
-
|
36
|
-
@reconnect = true
|
37
|
-
|
38
|
-
@open = false
|
39
|
-
def is_open?
|
40
|
-
@open
|
41
|
-
end
|
42
|
-
|
43
|
-
# Called when the connection is established
|
44
|
-
@on_connect
|
45
|
-
def on_connect(&on_connect)
|
46
|
-
@on_connect = on_connect
|
47
|
-
end
|
48
|
-
|
49
|
-
# Called when the WAMP session is established
|
50
|
-
# @param session [WampClient::Session]
|
51
|
-
# @param details [Hash]
|
52
|
-
@on_join
|
53
|
-
def on_join(&on_join)
|
54
|
-
@on_join = on_join
|
55
|
-
end
|
56
|
-
|
57
|
-
# Called when the WAMP session presents a challenge
|
58
|
-
# @param authmethod [String]
|
59
|
-
# @param extra [Hash]
|
60
|
-
@on_challenge
|
61
|
-
def on_challenge(&on_challenge)
|
62
|
-
@on_challenge = on_challenge
|
63
|
-
end
|
64
|
-
|
65
|
-
# Called when the WAMP session is terminated
|
66
|
-
# @param reason [String] The reason the session left the router
|
67
|
-
# @param details [Hash] Object containing information about the left session
|
68
|
-
@on_leave
|
69
|
-
def on_leave(&on_leave)
|
70
|
-
@on_leave = on_leave
|
71
|
-
end
|
72
|
-
|
73
|
-
# Called when the connection is terminated
|
74
|
-
# @param reason [String] The reason the transport was disconnected
|
75
|
-
@on_disconnect
|
76
|
-
def on_disconnect(&on_disconnect)
|
77
|
-
@on_disconnect = on_disconnect
|
78
|
-
end
|
79
|
-
|
80
|
-
# Simple setter for callbacks
|
81
|
-
def on(event, &callback)
|
82
|
-
case event
|
83
|
-
when :connect
|
84
|
-
self.on_connect(&callback)
|
85
|
-
when :join
|
86
|
-
self.on_join(&callback)
|
87
|
-
when :challenge
|
88
|
-
self.on_challenge(&callback)
|
89
|
-
when :leave
|
90
|
-
self.on_leave(&callback)
|
91
|
-
when :disconnect
|
92
|
-
self.on_disconnect(&callback)
|
93
|
-
else
|
94
|
-
raise RuntimeError, "Unknown on(event) '#{event}'"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# @param options [Hash] The different options to pass to the connection
|
99
|
-
# @option options [String] :uri The uri of the WAMP router to connect to
|
100
|
-
# @option options [String] :proxy The proxy to get to the router
|
101
|
-
# @option options [String] :realm The realm to connect to
|
102
|
-
# @option options [String,nil] :protocol The protocol (default if wamp.2.json)
|
103
|
-
# @option options [String,nil] :authid The id to authenticate with
|
104
|
-
# @option options [Array, nil] :authmethods The different auth methods that the client supports
|
105
|
-
# @option options [Hash] :headers Custom headers to include during the connection
|
106
|
-
# @option options [WampClient::Serializer::Base] :serializer The serializer to use (default is json)
|
107
|
-
def initialize(options)
|
108
|
-
self.transport_class = options.delete(:transport) || WampClient::Transport::WebSocketEventMachine
|
109
|
-
self.options = options || {}
|
110
|
-
self.verbose = options[:verbose] || false
|
111
|
-
end
|
112
|
-
|
113
|
-
# Opens the connection
|
114
|
-
def open
|
115
|
-
|
116
|
-
raise RuntimeError, 'The connection is already open' if self.is_open?
|
117
|
-
|
118
|
-
@reconnect = true
|
119
|
-
@retry_timer = 1
|
120
|
-
@retrying = false
|
121
|
-
|
122
|
-
self.transport_class.start_event_machine do
|
123
|
-
# Create the transport
|
124
|
-
self._create_transport
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
# Closes the connection
|
130
|
-
def close
|
131
|
-
|
132
|
-
raise RuntimeError, 'The connection is already closed' unless self.is_open?
|
133
|
-
|
134
|
-
# Leave the session
|
135
|
-
@reconnect = false
|
136
|
-
@retrying = false
|
137
|
-
session.leave
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
def _create_session
|
142
|
-
self.session = WampClient::Session.new(self.transport, self.options)
|
143
|
-
|
144
|
-
# Setup session callbacks
|
145
|
-
self.session.on(:challenge) do |authmethod, extra|
|
146
|
-
self._finish_retry
|
147
|
-
@on_challenge.call(authmethod, extra) if @on_challenge
|
148
|
-
end
|
149
|
-
|
150
|
-
self.session.on(:join) do |details|
|
151
|
-
self._finish_retry
|
152
|
-
@on_join.call(self.session, details) if @on_join
|
153
|
-
end
|
154
|
-
|
155
|
-
self.session.on(:leave) do |reason, details|
|
156
|
-
|
157
|
-
unless @retrying
|
158
|
-
@on_leave.call(reason, details) if @on_leave
|
159
|
-
end
|
160
|
-
|
161
|
-
if @reconnect
|
162
|
-
# Retry
|
163
|
-
self._retry unless @retrying
|
164
|
-
else
|
165
|
-
# Close the transport
|
166
|
-
self.transport.disconnect
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
self.session.join(self.options[:realm])
|
171
|
-
end
|
172
|
-
|
173
|
-
def _create_transport
|
174
|
-
|
175
|
-
if self.transport
|
176
|
-
self.transport.disconnect
|
177
|
-
self.transport = nil
|
178
|
-
end
|
179
|
-
|
180
|
-
# Initialize the transport
|
181
|
-
self.transport = self.transport_class.new(self.options)
|
182
|
-
|
183
|
-
# Setup transport callbacks
|
184
|
-
self.transport.on(:open) do
|
185
|
-
puts "TRANSPORT OPEN" if self.verbose
|
186
|
-
|
187
|
-
# Call the callback
|
188
|
-
@on_connect.call if @on_connect
|
189
|
-
|
190
|
-
# Create the session
|
191
|
-
self._create_session
|
192
|
-
|
193
|
-
end
|
194
|
-
|
195
|
-
self.transport.on(:close) do |reason|
|
196
|
-
puts "TRANSPORT CLOSED: #{reason}" if self.verbose
|
197
|
-
@open = false
|
198
|
-
|
199
|
-
unless @retrying
|
200
|
-
@on_disconnect.call(reason) if @on_disconnect
|
201
|
-
end
|
202
|
-
|
203
|
-
# Nil out the session since the transport closed underneath it
|
204
|
-
self.session = nil
|
205
|
-
|
206
|
-
if @reconnect
|
207
|
-
# Retry
|
208
|
-
self._retry unless @retrying
|
209
|
-
else
|
210
|
-
# Stop the Event Machine
|
211
|
-
self.transport_class.stop_event_machine
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
self.transport.on(:error) do |message|
|
216
|
-
puts "TRANSPORT ERROR: #{message}"
|
217
|
-
end
|
218
|
-
|
219
|
-
@open = true
|
220
|
-
|
221
|
-
self.transport.connect
|
222
|
-
|
223
|
-
end
|
224
|
-
|
225
|
-
def _finish_retry
|
226
|
-
@retry_timer = 1
|
227
|
-
@retrying = false
|
228
|
-
end
|
229
|
-
|
230
|
-
def _retry
|
231
|
-
|
232
|
-
if self.session == nil or not self.session.is_open?
|
233
|
-
@retry_timer = 2*@retry_timer unless @retry_timer == 32
|
234
|
-
@retrying = true
|
235
|
-
|
236
|
-
self._create_transport
|
237
|
-
|
238
|
-
puts "Attempting Reconnect... Next attempt in #{@retry_timer} seconds" if self.verbose
|
239
|
-
self.transport_class.add_timer(@retry_timer*1000) do
|
240
|
-
self._retry if @retrying
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
end
|
245
|
-
|
246
|
-
end
|
247
|
-
end
|