weblink 1.1.2 → 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: 13496b146b017e1d415d1fb4ee27b36deb894f158882dc376490be51a6920184
4
- data.tar.gz: cf4643c4a79bb42f8f2b79e05197915e866d90d54be68689aa3df628f237385e
3
+ metadata.gz: b4a93ba7190197aa4341d503368788b21e1830a74e6742b7a11bcd9d9c476081
4
+ data.tar.gz: e391b3eb02aca0480107e6b5dee359ada21cdf90d03ea9764d68c7714cb07b7d
5
5
  SHA512:
6
- metadata.gz: 11b4b83e40f513ef9b4cbeb3ae532dc5c794da491e0adc06b69fa9c3736c80148998d26c1cf0eef78ff1cced9bfea691806bfebf7fb1bbd6ec720f453936d695
7
- data.tar.gz: d2083018ee29d25126c5379524bd59af249e55ac8b3b5030517b7ba905a2d122a5851a9fcb43611b215799acaeefbed3a88e4163946ef68c8426b01d2ff9ed8b
6
+ metadata.gz: 854a0d477c54eddc352f22cf02c8c6a428c1378b07fdf788d988aa03effdb9b7aed989ce9a3c48e655e72b0c8be137b051f9693ea9fd19b335a6ccc453aaebb2
7
+ data.tar.gz: 73b5b1d25d472437858b3a09cb4e9071a6731f1ef507c66bf9098b4629a658809ac286606bd91e3e3ae7e5ccec6f2f6268fa5301d407b25983f5244939cf8e69
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 1.2.0
2
+
3
+ * Prevent screen from sleeping (@zakir8)
4
+ * Send pings to keep websockets alive
5
+
1
6
  1.1.2
2
7
 
3
8
  * Add webrick as a runtime dependency
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.2.0
data/lib/weblink.rb CHANGED
@@ -19,12 +19,14 @@ class Weblink
19
19
  ip = Socket.getifaddrs.find { |ifa| ifa.addr&.ipv4_private? }
20
20
  if ip
21
21
  public = File.expand_path('../public', __dir__)
22
+ # TODO: check if the process failed
23
+ # TODO: don't suppress errors
22
24
  spawn('ruby', '-run', '-ehttpd', '--', public, err: IO::NULL)
23
25
  puts "Open http://#{ip.addr.ip_address}:8080/ on your other device."
24
26
  else
25
27
  abort(
26
28
  "Could not find an interface to listen on. " \
27
- "Make sure that you are connected to your device."
29
+ "Make sure that you are connected to your other device."
28
30
  )
29
31
  end
30
32
  end
@@ -59,11 +61,11 @@ class Weblink
59
61
  private
60
62
 
61
63
  def start_client(control_ws, min_ws_num: 3)
62
- host, port = @opts.values_at(:proxy_host, :proxy_port)
63
- 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|
64
66
  # Dogpile effect
65
- control_ws.send_text(@opts[:proxy_type]) if @websockets.size < min_ws_num
66
- @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) }
67
69
  end
68
70
  control_ws.onclose { EventMachine.stop_server(sig) }
69
71
  end
@@ -75,8 +77,13 @@ class Weblink
75
77
  end
76
78
  xff = handshake.headers_downcased['x-forwarded-for']
77
79
  with_retry(timeout: 3) do
78
- EventMachine.connect(socket, Relay, 'server', xff) do |rel|
79
- rel.start(ws)
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 }
80
87
  end
81
88
  end
82
89
  end
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,39 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weblink
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
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
- MIIEDjCCAvagAwIBAgIBATANBgkqhkiG9w0BAQsFADB3MRgwFgYDVQQDDA8xNTkz
14
- ODYwX3NveWxlbnQxFTATBgoJkiaJk/IsZAEZFgV1c2VyczEXMBUGCgmSJomT8ixk
15
- ARkWB25vcmVwbHkxFjAUBgoJkiaJk/IsZAEZFgZnaXRodWIxEzARBgoJkiaJk/Is
16
- ZAEZFgNjb20wHhcNMjIwMTI3MDIzMTQwWhcNMjMwMTI3MDIzMTQwWjB3MRgwFgYD
17
- VQQDDA8xNTkzODYwX3NveWxlbnQxFTATBgoJkiaJk/IsZAEZFgV1c2VyczEXMBUG
18
- CgmSJomT8ixkARkWB25vcm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pIqrph
34
- XjC/3xZEDxBLYSjeFIgUMN6+/XGduQANkZ6167QsVu/yPg==
35
- -----END CERTIFICATE-----
36
- date: 2022-03-05 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2022-06-10 00:00:00.000000000 Z
37
12
  dependencies:
38
13
  - !ruby/object:Gem::Dependency
39
14
  name: em-websocket
@@ -63,8 +38,8 @@ dependencies:
63
38
  - - "~>"
64
39
  - !ruby/object:Gem::Version
65
40
  version: '1.7'
66
- description:
67
- email:
41
+ description:
42
+ email:
68
43
  executables:
69
44
  - weblink
70
45
  extensions: []
@@ -82,12 +57,13 @@ files:
82
57
  - public/favicon-32x32.png
83
58
  - public/favicon.ico
84
59
  - public/index.html
60
+ - public/index.js
85
61
  - public/weblink.js
86
62
  - public/weblink.webmanifest
87
63
  homepage: https://github.com/soylent/weblink
88
64
  licenses: []
89
65
  metadata: {}
90
- post_install_message:
66
+ post_install_message:
91
67
  rdoc_options: []
92
68
  require_paths:
93
69
  - lib
@@ -102,8 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
78
  - !ruby/object:Gem::Version
103
79
  version: '0'
104
80
  requirements: []
105
- rubygems_version: 3.3.4
106
- signing_key:
81
+ rubygems_version: 3.0.3.1
82
+ signing_key:
107
83
  specification_version: 4
108
84
  summary: Web browser gateway
109
85
  test_files: []
checksums.yaml.gz.sig DELETED
Binary file
data.tar.gz.sig DELETED
@@ -1,2 +0,0 @@
1
- 4�G��>DG+�����b��»1 ����~ɖ]/_�i��x�;u�,w���cXkw���|����2�F7�k`د�=�\����GQ�(N�߅L�X(h���&���9�X"������~���3?HP�؂��
2
- #8��;�d�X ���l}�(R��W^�����=*�4�OyU����T��M/U��B"��')���[Q^���6ss��&��W�w_�iߔ�&{�Lv���-��Wt��~<�.���0��$�;���
metadata.gz.sig DELETED
Binary file