se-realtime 0.0.0.beta2 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8be232d89599d222902c7b5a6abe0373883d2c1c4de86bb845716da814f0008d
4
- data.tar.gz: 810386b632a4015837af3cc003437c1eb2ab97ca1a39216f9b7e0278f867465d
3
+ metadata.gz: df6fdee6c38b71e56a2aabc911c610f18e1d6da92770d8a3fc2190eb35e1a4a6
4
+ data.tar.gz: 29bd4cd03a4fd5c6c06eca9855c039b392308a8ad2f516d8b8d0073713bda294
5
5
  SHA512:
6
- metadata.gz: 83758de91c6098a3ebfee3b3dd0afd318706d6e058d8f7fb5fc85e8873b5470950d3fc3a4d17b7868b08b066b31546871e57eeed5a16cf0b11c41118b2071501
7
- data.tar.gz: c2dee666b75a47a25401822cec95875f43dc5c23eaf55bd62cf1abe51620a1e078639c2e7d89ac84498303d605ee12a86a67bd55a5a0572e98c3d573fb44749c
6
+ metadata.gz: c884b402278a17f3712839fb130e29cb5a1d7d26ac1f94e1a250a616bf349775209887ae3e604beb93a0282dbeb1c54e03a9376e0c804456407df3e6d6d8d877
7
+ data.tar.gz: 62fba0dba0aa3c9b9d0a43bae3f01d92afaa21911d2b8ed00f11cb047c374e4bc569b4c4f91d450d8d1c133ea287b39f9152622c368c3f7ad0c6e700aa03a260
@@ -4,6 +4,7 @@ PATH
4
4
  se-realtime (0.0.0.beta2)
5
5
  mechanize (~> 2.7)
6
6
  nokogiri (~> 1.8)
7
+ openssl (~> 2.1)
7
8
  permessage_deflate (~> 0.1)
8
9
  websocket-driver (~> 0.6)
9
10
 
@@ -30,14 +31,15 @@ GEM
30
31
  minitest (5.10.3)
31
32
  net-http-digest_auth (1.4.1)
32
33
  net-http-persistent (2.9.4)
33
- nokogiri (1.8.1)
34
+ nokogiri (1.8.2)
34
35
  mini_portile2 (~> 2.3.0)
35
36
  ntlm-http (0.1.1)
37
+ openssl (2.1.0)
36
38
  permessage_deflate (0.1.4)
37
39
  rake (10.5.0)
38
40
  unf (0.1.4)
39
41
  unf_ext
40
- unf_ext (0.0.7.4)
42
+ unf_ext (0.0.7.5)
41
43
  webrobots (0.1.2)
42
44
  websocket-driver (0.7.0)
43
45
  websocket-extensions (>= 0.1.0)
@@ -1,5 +1,5 @@
1
1
  module SE
2
2
  module Realtime
3
- VERSION = "0.0.0.beta2".freeze
3
+ VERSION = "0.0.1".freeze
4
4
  end
5
5
  end
@@ -4,6 +4,7 @@ require "websocket/driver"
4
4
  require "json"
5
5
  require "permessage_deflate"
6
6
  require "open-uri"
7
+ require 'openssl'
7
8
 
8
9
  module SE
9
10
  module Realtime
@@ -11,14 +12,28 @@ module SE
11
12
  attr_reader :url, :thread, :driver
12
13
  attr_accessor :handler
13
14
 
15
+ # If you're looking back it this, look at super_logger (ws_super_logger, panic switch logging) and logger (realtime, messages (and some warnings))
16
+
14
17
  def initialize(url, cookies, &handler)
18
+ @super_logger = Logger.new('ws_super_logger.log')
19
+
15
20
  @uri = URI.parse(url)
16
21
  @url = "ws#{@uri.scheme.split("")[4]}://#{@uri.host}"
17
22
  @driver = WebSocket::Driver.client(self)
18
- @socket = TCPSocket.new(@uri.host, 80)
23
+ if @uri.scheme.split("")[4] == 's'
24
+ @socket = TCPSocket.new(@uri.host, 443)
25
+ @super_logger.info "Opened TCP socket for (port 443) #{@uri} (#{@socket})"
26
+ @socket = OpenSSL::SSL::SSLSocket.new(@socket)
27
+ @socket.connect
28
+ @super_logger.info "Upgrade TCP socket to SSL socket socket for #{@uri} (#{@socket})"
29
+ else
30
+ @socket = TCPSocket.new(@uri.host, 80)
31
+ @super_logger.info "Opened TCP socket for (port 80) #{@uri} (#{@socket})"
32
+ end
19
33
  @handler = handler
20
34
  @logger = Logger.new "realtime.log"
21
35
  @restart = true
36
+ @super_logger.info "Set @restart to #{@restart}"
22
37
 
23
38
  @driver.add_extension PermessageDeflate
24
39
  @driver.set_header "Cookies", cookies if cookies
@@ -28,6 +43,7 @@ module SE
28
43
 
29
44
  @driver.on :open, ->(_e) do
30
45
  send "155-questions-active"
46
+ @super_logger.info "Socket open. Subscribed to 155-questions-active"
31
47
  @logger.info "WebSocket is open!"
32
48
  end
33
49
 
@@ -43,8 +59,10 @@ module SE
43
59
 
44
60
  @driver.on :close, ->(_e) do
45
61
  @logger.info "Realtime WebSocket is closing."
62
+ @super_logger.info "Socket was closed. @restart == #{@restart}"
46
63
  if @restart
47
64
  @logger.info "Attempting to reopen websocket..."
65
+ @super_logger.info "Attempting to reopen socket"
48
66
  @driver.start
49
67
  end
50
68
  end
@@ -56,16 +74,19 @@ module SE
56
74
  @thread = Thread.new do
57
75
  trap("SIGINT") do
58
76
  @restart = false
77
+ @super_logger.info "Got SIGINT. Dying."
59
78
  close
60
79
  Thread.exit
61
80
  end
62
81
  loop do
63
82
  begin
64
- @driver.parse(@socket.recv(1))
83
+ @driver.parse(@socket.is_a?(TCPSocket) ? @socket.recv(1) : @socket.sysread(1))
65
84
  rescue IOError, SystemCallError => e
85
+ @super_logger.warn "Got some kind of interrupt in the thread. Panic."
66
86
  @logger.warn "Recieved #{e} closing TCP socket. You shouldn't be worried :)"
67
87
  end
68
88
  end
89
+ @super_logger.warn "Left TCPSocket.recv loop. If you're reading this, panic."
69
90
  end
70
91
 
71
92
  at_exit { @thread.join }
@@ -82,8 +103,9 @@ module SE
82
103
  end
83
104
 
84
105
  def close
106
+ @super_logger.warn "Was told to close. Was sad."
85
107
  @driver.close
86
- @socket.shutdown
108
+ @socket.is_a?(TCPSocket) ? @socket.shutdown : @socket.sysclose
87
109
  rescue IOError, Errno::ENOTCONN => e
88
110
  @logger.error "Recieved #{e.class} trying to close websocket. Ignoring..."
89
111
  end
@@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
38
38
  ["nokogiri", "~> 1.8"],
39
39
  ["permessage_deflate", "~> 0.1"],
40
40
  ["websocket-driver", "~> 0.6"],
41
+ ["openssl", "~> 2.1"]
41
42
  ].each do |g, v|
42
43
  spec.add_runtime_dependency g, v
43
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: se-realtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.beta2
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thesecretmaster
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-25 00:00:00.000000000 Z
11
+ date: 2018-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: openssl
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.1'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.1'
111
125
  description:
112
126
  email:
113
127
  - thesecretmaster@developingtechnician.com
@@ -144,9 +158,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
158
  version: '0'
145
159
  required_rubygems_version: !ruby/object:Gem::Requirement
146
160
  requirements:
147
- - - ">"
161
+ - - ">="
148
162
  - !ruby/object:Gem::Version
149
- version: 1.3.1
163
+ version: '0'
150
164
  requirements: []
151
165
  rubyforge_project:
152
166
  rubygems_version: 2.7.3