weblink 1.1.0 → 1.2.0

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: d385e7232ce9202ce7b88e2ff864541243694f1b0a81fd40a8bb02b3ec0cc616
4
- data.tar.gz: ae5d4588789bad44e61d29094cf9aa73c1e230bee61b32df9fa70e2a074fc3dd
3
+ metadata.gz: b4a93ba7190197aa4341d503368788b21e1830a74e6742b7a11bcd9d9c476081
4
+ data.tar.gz: e391b3eb02aca0480107e6b5dee359ada21cdf90d03ea9764d68c7714cb07b7d
5
5
  SHA512:
6
- metadata.gz: 6a29a327435407af014c9bb887f4289536f5a28d6b1495dfd00e2892ee1396339efff8ae4b71b074ad256bab80808e22f41f1f9fa7857937a8fd61e08eabb3ad
7
- data.tar.gz: 8d358c66cc2a55d79988f34b7e9997209e978e4d0828fa5ff3aa39a86f5c85be39fc9ff000c81ee900b009d0fda1118b46170b4c19ad03cdb3a404f90dc3738f
6
+ metadata.gz: 854a0d477c54eddc352f22cf02c8c6a428c1378b07fdf788d988aa03effdb9b7aed989ce9a3c48e655e72b0c8be137b051f9693ea9fd19b335a6ccc453aaebb2
7
+ data.tar.gz: 73b5b1d25d472437858b3a09cb4e9071a6731f1ef507c66bf9098b4629a658809ac286606bd91e3e3ae7e5ccec6f2f6268fa5301d407b25983f5244939cf8e69
data/CHANGELOG CHANGED
@@ -1,3 +1,16 @@
1
+ 1.2.0
2
+
3
+ * Prevent screen from sleeping (@zakir8)
4
+ * Send pings to keep websockets alive
5
+
6
+ 1.1.2
7
+
8
+ * Add webrick as a runtime dependency
9
+
10
+ 1.1.1
11
+
12
+ * Ignore interfaces with nil addresses
13
+
1
14
  1.1.0
2
15
 
3
16
  * Works on Windows
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
data/lib/relay.rb CHANGED
@@ -32,6 +32,7 @@ class Relay < EventMachine::Connection
32
32
 
33
33
  def unbind
34
34
  log('close')
35
+ # Status code 1000 indicates indicates a normal closure.
35
36
  @websocket&.close(1000) if @websocket&.state == :connected
36
37
  end
37
38
 
data/lib/weblink.rb CHANGED
@@ -16,11 +16,19 @@ class Weblink
16
16
  trap(:EXIT) { Process.waitall }
17
17
 
18
18
  if @opts[:client]
19
- public = File.expand_path('../public', __dir__)
20
- spawn('ruby', '-run', '-ehttpd', '--', public, err: IO::NULL)
21
-
22
- ip = Socket.getifaddrs.find { |ifa| ifa.addr.ipv4_private? }
23
- puts "Open http://#{ip.addr.ip_address}:8080/ on your other device." if ip
19
+ ip = Socket.getifaddrs.find { |ifa| ifa.addr&.ipv4_private? }
20
+ if ip
21
+ public = File.expand_path('../public', __dir__)
22
+ # TODO: check if the process failed
23
+ # TODO: don't suppress errors
24
+ spawn('ruby', '-run', '-ehttpd', '--', public, err: IO::NULL)
25
+ puts "Open http://#{ip.addr.ip_address}:8080/ on your other device."
26
+ else
27
+ abort(
28
+ "Could not find an interface to listen on. " \
29
+ "Make sure that you are connected to your other device."
30
+ )
31
+ end
24
32
  end
25
33
 
26
34
  if @opts[:server]
@@ -53,11 +61,11 @@ class Weblink
53
61
  private
54
62
 
55
63
  def start_client(control_ws, min_ws_num: 3)
56
- host, port = @opts.values_at(:proxy_host, :proxy_port)
57
- sig = EventMachine.start_server(host, port, Relay, 'client') do |rel|
64
+ type, host, port = @opts.values_at(:proxy_type, :proxy_host, :proxy_port)
65
+ sig = EventMachine.start_server(host, port, Relay, 'client') do |relay|
58
66
  # Dogpile effect
59
- control_ws.send_text(@opts[:proxy_type]) if @websockets.size < min_ws_num
60
- @websockets.pop { |ws| rel.start(ws) }
67
+ control_ws.send_text(type) if @websockets.size < min_ws_num
68
+ @websockets.pop { |ws| relay.start(ws) }
61
69
  end
62
70
  control_ws.onclose { EventMachine.stop_server(sig) }
63
71
  end
@@ -68,14 +76,19 @@ class Weblink
68
76
  return
69
77
  end
70
78
  xff = handshake.headers_downcased['x-forwarded-for']
71
- with_retry(3) do
72
- EventMachine.connect(socket, Relay, 'server', xff) do |rel|
73
- rel.start(ws)
79
+ with_retry(timeout: 3) do
80
+ EventMachine.connect(socket, Relay, 'server', xff) do |relay|
81
+ relay.start(ws)
82
+ # TODO: Instead of creating a timer per websocket, it might be more
83
+ # efficient to create a single timer and iterate over all open
84
+ # websockets.
85
+ timer = EventMachine.add_periodic_timer(45) { ws.ping }
86
+ ws.onclose { timer.cancel }
74
87
  end
75
88
  end
76
89
  end
77
90
 
78
- def with_retry(timeout, wait: 0.1)
91
+ def with_retry(timeout:, wait: 0.1)
79
92
  elapsed = 0
80
93
  begin
81
94
  yield
data/public/index.html CHANGED
@@ -2,35 +2,43 @@
2
2
  <html>
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
5
6
  <title>weblink</title>
6
7
  <link rel="manifest" href="/weblink.webmanifest">
7
8
  <style>
8
9
  html, body {
9
10
  height: 100%;
11
+ background-color: #3f9cff;
12
+ font-family: sans-serif;
10
13
  }
11
14
  body {
12
15
  align-items: center;
13
- background-color: #3f9cff;
14
16
  color: white;
15
17
  display: flex;
16
18
  justify-content: center;
19
+ flex-direction: column;
17
20
  }
18
21
  h1 {
19
- font-family: sans-serif;
20
- font-size: 8em;
22
+ font-size: 3rem;
21
23
  }
22
24
  </style>
23
25
  </head>
24
26
  <body>
25
27
  <h1>weblink</h1>
28
+ <div class="settings">
29
+ <input type="checkbox" id="nosleep" />
30
+ <label for="nosleep">Prevent screen from sleeping</label>
31
+ </div>
32
+
26
33
  <script>
27
- function connect(client_addr, server_addr, proxy) {
28
- var client, server = new WebSocket(server_addr + "/proxy/" + proxy);
34
+ function connect(clientAddr, serverAddr, proxy) {
35
+ var client;
36
+ var server = new WebSocket(serverAddr + "/proxy/" + proxy);
29
37
 
30
38
  server.onerror = function(event) { console.error("server/error"); };
31
39
 
32
40
  server.onopen = function() {
33
- client = new WebSocket(client_addr + "/client");
41
+ client = new WebSocket(clientAddr + "/client");
34
42
 
35
43
  client.onerror = function(event) { console.error("client/error"); };
36
44
 
@@ -56,18 +64,24 @@
56
64
  params[key] = decodeURIComponent(value);
57
65
  });
58
66
 
59
- var client_addr = "ws://" + location.hostname + ":8000";
60
- var server_addr = params.server || "wss://weblinkapp.herokuapp.com";
61
- var batch_size = Number(params.batch) || 4;
62
- var control = new WebSocket(client_addr + "/control");
67
+ var clientAddr = "ws://" + location.hostname + ":8000";
68
+ var serverAddr = params.server || "wss://weblinkapp.herokuapp.com";
69
+ var batchSize = Number(params.batch) || 4;
70
+ var control = new WebSocket(clientAddr + "/control");
63
71
 
64
72
  control.onerror = function(event) { console.error("control/error"); };
65
73
  control.onclose = function(event) { console.log("control/close"); };
66
74
  control.onmessage = function(msg) {
67
- for (var i = 0; i < batch_size; i++) {
68
- connect(client_addr, server_addr, msg.data);
75
+ for (var i = 0; i < batchSize; i++) {
76
+ connect(clientAddr, serverAddr, msg.data);
69
77
  }
70
78
  };
71
79
  </script>
72
80
  </body>
81
+ <script
82
+ src="https://cdnjs.cloudflare.com/ajax/libs/nosleep/0.12.0/NoSleep.min.js"
83
+ type="text/javascript"
84
+ crossorigin="anonymous"
85
+ ></script>
86
+ <script src="index.js" type="text/javascript"></script>
73
87
  </html>
data/public/index.js ADDED
@@ -0,0 +1,22 @@
1
+ var noSleep = new NoSleep();
2
+ var noSleepCheckbox = document.getElementById("nosleep");
3
+
4
+ document.addEventListener("visibilitychange", function resetNoSleep(event) {
5
+ if (document.visibilityState === "visible") {
6
+ noSleep.disable();
7
+ noSleep = new NoSleep();
8
+ noSleepCheckbox.checked = false;
9
+ }
10
+ });
11
+
12
+ noSleepCheckbox.addEventListener("click", function toggleNoSleep(event) {
13
+ if (noSleep.isEnabled) {
14
+ noSleep.disable();
15
+ } else {
16
+ try {
17
+ noSleep.enable();
18
+ } catch (error) {
19
+ event.preventDefault();
20
+ }
21
+ }
22
+ });
metadata CHANGED
@@ -1,34 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weblink
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - soylent
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIDGjCCAgKgAwIBAgIBATANBgkqhkiG9w0BAQsFADAaMRgwFgYDVQQDDA9lZmly
14
- L0RDPXNveWxlbnQwHhcNMjAwMzA3MDEzNzUwWhcNMjEwMzA3MDEzNzUwWjAaMRgw
15
- FgYDVQQDDA9lZmlyL0RDPXNveWxlbnQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
16
- ggEKAoIBAQC2DMbzgA39U+3VTMjXn+0jnOQyLdmXQ5EXgSLKCgBLIcFTc9J47Th0
17
- 7Yb/f4RzWh49/EkDBiDtLqFeKBYsj3q0e8tRCAs32NtVyl/4FDyJvWsK3R2tcXOV
18
- qxs48J3CgG+rFLOcMC9YF4FPTkz4p3EYGFVjZTbiqyVVuIZzWtrwdZesBVgpBRyN
19
- 8sEyNoi8vcDiOmEwf9/TVMTDf/wu6a+i3LNVGYWlvgMJRssaAnj/IbFFtPTz30Hx
20
- eTUdfJu8YbwRspfFzcJGLf32E7vXfmHHqNzqjh4zD9sVpvTHbqLLsgVa+nYHPHAe
21
- dzSZ5gZjG1oZ7hZDCJoEPj0oCHT0qkuXAgMBAAGjazBpMAkGA1UdEwQCMAAwCwYD
22
- VR0PBAQDAgSwMB0GA1UdDgQWBBSsvp1HAfA+QTjOg/ehyhv7adp0FjAXBgNVHREE
23
- EDAOgQxlZmlyQHNveWxlbnQwFwYDVR0SBBAwDoEMZWZpckBzb3lsZW50MA0GCSqG
24
- SIb3DQEBCwUAA4IBAQBsJ7htnm3RB5xQwzC2agRAgG2ax5uaD6lCEPWshGJbfT6v
25
- jaRrwrPSbaxBTD2v8QpXJe/fALJKWHUbNZilZU2t7HyQkfSyVQyLYcjo7lWFoHA1
26
- z0YB3dCGcMkvLa7r73ynEtYbnYfesbXVlcRJG7SgJqWvZMnj1HnYfBevlcjSBFy2
27
- 5xZKSwreHM+va8McxpEZmG3ecdefRQ1u+xZabamN2hhel3nKF1BUBqgxYWXYRkZP
28
- VIAqJBK/gwFlRxVYjmi2w4Ouc4wL8HtX104yQqOuD9gVPN6PJecue66As7i2I/2q
29
- EARmnubhy24GUdxEooHV6pOs1mLLRuFepMgBnHfs
30
- -----END CERTIFICATE-----
31
- date: 2020-12-26 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2022-06-10 00:00:00.000000000 Z
32
12
  dependencies:
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: em-websocket
@@ -44,8 +24,22 @@ dependencies:
44
24
  - - "~>"
45
25
  - !ruby/object:Gem::Version
46
26
  version: '0.5'
47
- description:
48
- email:
27
+ - !ruby/object:Gem::Dependency
28
+ name: webrick
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ description:
42
+ email:
49
43
  executables:
50
44
  - weblink
51
45
  extensions: []
@@ -63,12 +57,13 @@ files:
63
57
  - public/favicon-32x32.png
64
58
  - public/favicon.ico
65
59
  - public/index.html
60
+ - public/index.js
66
61
  - public/weblink.js
67
62
  - public/weblink.webmanifest
68
63
  homepage: https://github.com/soylent/weblink
69
64
  licenses: []
70
65
  metadata: {}
71
- post_install_message:
66
+ post_install_message:
72
67
  rdoc_options: []
73
68
  require_paths:
74
69
  - lib
@@ -83,8 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
78
  - !ruby/object:Gem::Version
84
79
  version: '0'
85
80
  requirements: []
86
- rubygems_version: 3.1.4
87
- signing_key:
81
+ rubygems_version: 3.0.3.1
82
+ signing_key:
88
83
  specification_version: 4
89
84
  summary: Web browser gateway
90
85
  test_files: []
checksums.yaml.gz.sig DELETED
Binary file
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
Binary file