libwebsocket 0.1.6.1 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/libwebsocket.rb +2 -1
- data/lib/libwebsocket/opening_handshake/client.rb +7 -1
- data/lib/libwebsocket/url.rb +68 -0
- data/lib/libwebsocket/version.rb +1 -1
- data/libwebsocket.gemspec +1 -0
- metadata +19 -8
data/CHANGELOG.md
CHANGED
data/lib/libwebsocket.rb
CHANGED
@@ -4,7 +4,8 @@ require 'websocket'
|
|
4
4
|
# or clients to provide WebSocket support.
|
5
5
|
module LibWebSocket
|
6
6
|
|
7
|
-
autoload :Frame,
|
7
|
+
autoload :Frame, "#{File.dirname(__FILE__)}/libwebsocket/frame"
|
8
8
|
autoload :OpeningHandshake, "#{File.dirname(__FILE__)}/libwebsocket/opening_handshake"
|
9
|
+
autoload :URL, "#{File.dirname(__FILE__)}/libwebsocket/url"
|
9
10
|
|
10
11
|
end
|
@@ -34,12 +34,18 @@ module LibWebSocket
|
|
34
34
|
# h.done? # Returns true
|
35
35
|
class Client < OpeningHandshake
|
36
36
|
|
37
|
-
def_delegator :controller, :uri
|
37
|
+
def_delegator :controller, :uri
|
38
38
|
|
39
39
|
def initialize(hash = {})
|
40
40
|
@controller = ::WebSocket::Handshake::Client.new({:version => 76}.merge(hash))
|
41
41
|
end
|
42
42
|
|
43
|
+
def url
|
44
|
+
lws_url = LibWebSocket::URL.new
|
45
|
+
lws_url.parse(uri)
|
46
|
+
lws_url
|
47
|
+
end
|
48
|
+
|
43
49
|
end
|
44
50
|
end
|
45
51
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
|
3
|
+
module LibWebSocket
|
4
|
+
# Construct or parse a WebSocket URL.
|
5
|
+
class URL
|
6
|
+
|
7
|
+
attr_accessor :secure, :host, :port, :resource_name
|
8
|
+
|
9
|
+
def initialize(hash = {})
|
10
|
+
hash.each do |k,v|
|
11
|
+
instance_variable_set("@#{k}",v)
|
12
|
+
end
|
13
|
+
|
14
|
+
@secure ||= false
|
15
|
+
end
|
16
|
+
|
17
|
+
# Parse a WebSocket URL.
|
18
|
+
# @example Parse
|
19
|
+
# url = LibWebSocket::URL.new
|
20
|
+
# url.parse('wss://example.com:3000')
|
21
|
+
# url.host # => example.com
|
22
|
+
# url.port # => 3000
|
23
|
+
# url.secure # => true
|
24
|
+
def parse(string)
|
25
|
+
return nil unless string.is_a?(String)
|
26
|
+
|
27
|
+
uri = Addressable::URI.parse(string)
|
28
|
+
|
29
|
+
scheme = uri.scheme
|
30
|
+
return nil unless scheme
|
31
|
+
|
32
|
+
self.secure = true if scheme.match(/ss\Z/m)
|
33
|
+
|
34
|
+
host = uri.host
|
35
|
+
host = '/' unless host && host != ''
|
36
|
+
self.host = host
|
37
|
+
self.port = uri.port.to_s if uri.port
|
38
|
+
|
39
|
+
request_uri = uri.path
|
40
|
+
request_uri = '/' unless request_uri && request_uri != ''
|
41
|
+
request_uri += "?" + uri.query if uri.query
|
42
|
+
self.resource_name = request_uri
|
43
|
+
|
44
|
+
return self
|
45
|
+
end
|
46
|
+
|
47
|
+
# Construct a WebSocket URL.
|
48
|
+
# @example Construct
|
49
|
+
# url = LibWebSocket::URL.new
|
50
|
+
# url.host = 'example.com'
|
51
|
+
# url.port = '3000'
|
52
|
+
# url.secure = true
|
53
|
+
# url.to_s # => 'wss://example.com:3000'
|
54
|
+
def to_s
|
55
|
+
string = ''
|
56
|
+
|
57
|
+
string += 'ws'
|
58
|
+
string += 's' if self.secure
|
59
|
+
string += '://'
|
60
|
+
string += self.host
|
61
|
+
string += ':' + self.port.to_s if self.port
|
62
|
+
string += self.resource_name || '/'
|
63
|
+
|
64
|
+
return string
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
data/lib/libwebsocket/version.rb
CHANGED
data/libwebsocket.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libwebsocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
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-11-
|
12
|
+
date: 2012-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: websocket
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: addressable
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rake
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,6 +79,7 @@ files:
|
|
63
79
|
- lib/libwebsocket/opening_handshake.rb
|
64
80
|
- lib/libwebsocket/opening_handshake/client.rb
|
65
81
|
- lib/libwebsocket/opening_handshake/server.rb
|
82
|
+
- lib/libwebsocket/url.rb
|
66
83
|
- lib/libwebsocket/version.rb
|
67
84
|
- libwebsocket.gemspec
|
68
85
|
- test/libwebsocket/opening_handshake/test_client.rb
|
@@ -81,18 +98,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
98
|
- - ! '>='
|
82
99
|
- !ruby/object:Gem::Version
|
83
100
|
version: '0'
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
hash: -2175210411594514962
|
87
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
102
|
none: false
|
89
103
|
requirements:
|
90
104
|
- - ! '>='
|
91
105
|
- !ruby/object:Gem::Version
|
92
106
|
version: '0'
|
93
|
-
segments:
|
94
|
-
- 0
|
95
|
-
hash: -2175210411594514962
|
96
107
|
requirements: []
|
97
108
|
rubyforge_project:
|
98
109
|
rubygems_version: 1.8.24
|