websocket-eventmachine-client 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bf7ffbade416b4c84219e2277f22ef31f0755778
4
+ data.tar.gz: 9178f2572d0b033c0d44f6f6925faf0ef07e89fa
5
+ SHA512:
6
+ metadata.gz: 7dc1c07da7158d64d095702b6f742e0f610b4eae2712445ede2346bc2f7ed1314f2dfd81999183b9d929da71d284b0a28c2f681f551fd41c02a2854b1eb1f08b
7
+ data.tar.gz: eea80e6a5c18d4064a92886259eb5a8b0ec309087da9c753199825ed0dc03fd50b01e45f7d965b3f37ddf663d15450a34114980aa98bfedee6bcdf5baab87361
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0
4
+
5
+ - ssl support
6
+
3
7
  ## 1.0.1
4
8
 
5
9
  - ensure compatibility with em-websocket
data/README.md CHANGED
@@ -32,11 +32,13 @@ EM.run do
32
32
  puts "Received message: #{msg}"
33
33
  end
34
34
 
35
- ws.onclose do
36
- puts "Disconnected"
35
+ ws.onclose do |code, reason|
36
+ puts "Disconnected with status code: #{code}"
37
37
  end
38
38
 
39
- ws.send "Hello Server!"
39
+ EventMachine.next_tick do
40
+ ws.send "Hello Server!"
41
+ end
40
42
 
41
43
  end
42
44
  ```
@@ -49,6 +51,8 @@ Following options can be passed to WebSocket::EventMachine::Client initializer:
49
51
  - `[Integer] :port` - Port of server to connect
50
52
  - `[String] :uri` - Full URI for server(optional - use instead of host/port combination)
51
53
  - `[Integer] :version` - Version of WebSocket to use. Default: 13
54
+ - `[Hash] :headers` - HTTP headers to use in the handshake. Example: `{'Cookie' => 'COOKIENAME=Value'}`
55
+ - `[Boolean] :ssl` - Force SSL/TLS regardless of URI scheme or port
52
56
 
53
57
  ## Methods
54
58
 
@@ -70,11 +74,16 @@ end
70
74
 
71
75
  Called after closing connection.
72
76
 
77
+ Parameters:
78
+
79
+ - `[Integer] code` - status code
80
+ - `[String] reason` - optional reason for closure
81
+
73
82
  Example:
74
83
 
75
84
  ```ruby
76
- ws.onclose do
77
- puts "Client disconnected"
85
+ ws.onclose do |code, reason|
86
+ puts "Client disconnected with status code: #{code} and reason: #{reason}"
78
87
  end
79
88
  ```
80
89
 
@@ -6,7 +6,7 @@ EM.epoll
6
6
  EM.run do
7
7
 
8
8
  host = 'ws://localhost:9001'
9
- agent = "WebSocket-EventMachine-Client (1.0.0)"
9
+ agent = "WebSocket-EventMachine-Client (1.0.1)"
10
10
  cases = 0
11
11
  skip = []
12
12
 
@@ -20,6 +20,8 @@ module WebSocket
20
20
  # @option args [String] :host The host IP/DNS name
21
21
  # @option args [Integer] :port The port to connect too(default = 80)
22
22
  # @option args [Integer] :version Version of protocol to use(default = 13)
23
+ # @option args [Hash] :headers HTTP headers to use in the handshake
24
+ # @option args [Boolean] :ssl Force SSL/TLS connection
23
25
  def self.connect(args = {})
24
26
  host = nil
25
27
  port = nil
@@ -27,10 +29,15 @@ module WebSocket
27
29
  uri = URI.parse(args[:uri])
28
30
  host = uri.host
29
31
  port = uri.port
32
+ args[:ssl] = true if uri.scheme == 'wss'
30
33
  end
31
34
  host = args[:host] if args[:host]
32
35
  port = args[:port] if args[:port]
33
- port ||= 80
36
+ if args[:ssl]
37
+ port ||= 443
38
+ else
39
+ port ||= 80
40
+ end
34
41
 
35
42
  ::EventMachine.connect host, port, self, args
36
43
  end
@@ -40,6 +47,8 @@ module WebSocket
40
47
  # @option args [String] :host The host IP/DNS name
41
48
  # @option args [Integer] :port The port to connect too(default = 80)
42
49
  # @option args [Integer] :version Version of protocol to use(default = 13)
50
+ # @option args [Hash] :headers HTTP headers to use in the handshake
51
+ # @option args [Boolean] :ssl Force SSL/TLS connection
43
52
  def initialize(args)
44
53
  @args = args
45
54
  end
@@ -57,10 +66,22 @@ module WebSocket
57
66
  end
58
67
 
59
68
  # Called by EventMachine after connecting.
60
- # Sends handshake to server
69
+ # Sends handshake to server or starts SSL/TLS
61
70
  # Eventmachine internal
62
71
  # @private
63
72
  def connection_completed
73
+ if @args[:ssl]
74
+ start_tls
75
+ else
76
+ send(@handshake.to_s, :type => :plain)
77
+ end
78
+ end
79
+
80
+ # Called by EventMachine after SSL/TLS handshake.
81
+ # Sends websocket handshake
82
+ # Eventmachine internal
83
+ # @private
84
+ def ssl_handshake_completed
64
85
  send(@handshake.to_s, :type => :plain)
65
86
  end
66
87
 
@@ -1,7 +1,7 @@
1
1
  module WebSocket
2
2
  module EventMachine
3
3
  class Client
4
- VERSION = '1.0.1'
4
+ VERSION = '1.1.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: websocket-eventmachine-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Bernard Potocki
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-26 00:00:00.000000000 Z
11
+ date: 2014-06-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: websocket-eventmachine-base
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.0'
30
27
  description: WebSocket client for Ruby
@@ -34,7 +31,7 @@ executables: []
34
31
  extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
- - .gitignore
34
+ - ".gitignore"
38
35
  - CHANGELOG.md
39
36
  - Gemfile
40
37
  - README.md
@@ -48,26 +45,25 @@ files:
48
45
  - websocket-eventmachine-client.gemspec
49
46
  homepage: http://github.com/imanel/websocket-eventmachine-client
50
47
  licenses: []
48
+ metadata: {}
51
49
  post_install_message:
52
50
  rdoc_options: []
53
51
  require_paths:
54
52
  - lib
55
53
  required_ruby_version: !ruby/object:Gem::Requirement
56
- none: false
57
54
  requirements:
58
- - - ! '>='
55
+ - - ">="
59
56
  - !ruby/object:Gem::Version
60
57
  version: '0'
61
58
  required_rubygems_version: !ruby/object:Gem::Requirement
62
- none: false
63
59
  requirements:
64
- - - ! '>='
60
+ - - ">="
65
61
  - !ruby/object:Gem::Version
66
62
  version: '0'
67
63
  requirements: []
68
64
  rubyforge_project:
69
- rubygems_version: 1.8.24
65
+ rubygems_version: 2.2.2
70
66
  signing_key:
71
- specification_version: 3
67
+ specification_version: 4
72
68
  summary: WebSocket client for Ruby
73
69
  test_files: []