crimson 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -4
- data/example/{example.rb → config.ru} +3 -3
- data/lib/crimson/adapters/faye.rb +16 -0
- data/lib/crimson/client.rb +3 -6
- data/lib/crimson/server.rb +59 -32
- data/lib/crimson/version.rb +1 -1
- data/lib/javascript/ServerInteractor.js +18 -6
- metadata +4 -7
- data/.github/workflows/gempush.yml +0 -44
- data/.vscode/launch.json +0 -14
- data/example/ets.rb +0 -22
- data/lib/crimson/webserver.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0089dfdf0858ceff35c98db0799998355463be523a13420425294bee18c4a46
|
4
|
+
data.tar.gz: 681a505d387641e482379284548cd6a5055017347792112f179a4c28a0637b8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40046a67b7b174c74d585715271278dae16ce786e3ed92c8458cb60ea4c05012cca716f18acf7998ced6a6b1d09ab25810e5747b5f6f95e495f371eb5cbbc8b6
|
7
|
+
data.tar.gz: '0253249eeb2d990a0d88d154647566e4b69b480a8ca77bc37701f889ab9b7edf1b6be5f9c6a363ea64e6d034cae12ff4a587b4bbdef55f3fc21214dce7216e3d'
|
data/Gemfile
CHANGED
@@ -6,8 +6,6 @@ require 'crimson/widgets/window'
|
|
6
6
|
require 'crimson/widgets/form'
|
7
7
|
require 'crimson/widgets/input'
|
8
8
|
|
9
|
-
server = Crimson::Server.new
|
10
|
-
|
11
9
|
desktop = Crimson::Desktop.new
|
12
10
|
desktop.style.backgroundColor = "white"
|
13
11
|
|
@@ -53,6 +51,8 @@ login.content = form
|
|
53
51
|
|
54
52
|
desktop.commit_tree!
|
55
53
|
|
54
|
+
server = Crimson::Server.new
|
55
|
+
|
56
56
|
server.on_connect do |client|
|
57
57
|
puts "#{client.id} connected"
|
58
58
|
|
@@ -63,4 +63,4 @@ server.on_disconnect do |client|
|
|
63
63
|
puts "#{client.id} disconnected"
|
64
64
|
end
|
65
65
|
|
66
|
-
server
|
66
|
+
run server
|
data/lib/crimson/client.rb
CHANGED
@@ -9,15 +9,12 @@ module Crimson
|
|
9
9
|
|
10
10
|
def initialize(id, connection)
|
11
11
|
@id = id
|
12
|
-
|
13
12
|
@connection = connection
|
14
|
-
@connection.onmessage(&method(:on_message))
|
15
|
-
|
16
13
|
@notification_bus = NotificationBus.new
|
17
14
|
end
|
18
15
|
|
19
|
-
def on_message(message
|
20
|
-
message = Hashie::Mash.new(
|
16
|
+
def on_message(message)
|
17
|
+
message = Hashie::Mash.new(message)
|
21
18
|
|
22
19
|
begin
|
23
20
|
case message.action
|
@@ -30,7 +27,7 @@ module Crimson
|
|
30
27
|
end
|
31
28
|
|
32
29
|
def write(message = {})
|
33
|
-
connection.
|
30
|
+
connection.write(message)
|
34
31
|
end
|
35
32
|
|
36
33
|
def on_commit(object, changes)
|
data/lib/crimson/server.rb
CHANGED
@@ -1,24 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
|
3
|
+
require 'async/websocket/adapters/rack'
|
4
|
+
require_relative 'adapters/faye'
|
5
5
|
require_relative 'client'
|
6
|
-
require_relative 'webserver'
|
7
6
|
require_relative 'utilities'
|
8
7
|
|
9
8
|
module Crimson
|
10
9
|
class Server
|
11
10
|
attr_reader :clients
|
12
11
|
|
13
|
-
def initialize
|
14
|
-
@opts = opts || {}
|
12
|
+
def initialize
|
15
13
|
@clients = {}
|
16
14
|
end
|
17
15
|
|
18
|
-
def host
|
19
|
-
@opts[:host] || '0.0.0.0'
|
20
|
-
end
|
21
|
-
|
22
16
|
def on_connect(&block)
|
23
17
|
@on_connect = block if block_given?
|
24
18
|
end
|
@@ -27,43 +21,76 @@ module Crimson
|
|
27
21
|
@on_disconnect = block if block_given?
|
28
22
|
end
|
29
23
|
|
30
|
-
def
|
31
|
-
|
24
|
+
def self.template_html_path
|
25
|
+
File.expand_path("#{__dir__}/../html/template.html")
|
32
26
|
end
|
33
27
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
def self.static
|
29
|
+
{ :urls => [File.expand_path("#{__dir__}/.."), File.expand_path("#{__dir__}/../javascript")] }
|
30
|
+
end
|
31
|
+
|
32
|
+
def content(port, path = Server.template_html_path)
|
33
|
+
template = File.read(path)
|
34
|
+
template.sub!("{PORT}", port)
|
35
|
+
|
36
|
+
[template]
|
39
37
|
end
|
40
38
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
39
|
+
def call(env)
|
40
|
+
call_async(env) or call_faye(env) or serve_template(env)
|
41
|
+
end
|
42
|
+
|
43
|
+
def call_async(env)
|
44
|
+
Async::WebSocket::Adapters::Rack.open(env, protocols: ['ws']) do |connection|
|
45
|
+
id = :"client_#{Utilities.generate_id}"
|
46
|
+
client = Client.new(id, connection)
|
47
|
+
clients[connection] = client
|
48
|
+
|
49
|
+
@on_connect&.call(client)
|
44
50
|
|
45
|
-
|
51
|
+
begin
|
52
|
+
while message = connection.read
|
53
|
+
client.on_message(message)
|
54
|
+
end
|
55
|
+
rescue Protocol::WebSocket::ClosedError
|
56
|
+
|
57
|
+
end
|
58
|
+
ensure
|
59
|
+
@on_disconnect&.call(client)
|
60
|
+
clients.delete(connection)
|
61
|
+
connection.close
|
62
|
+
end
|
46
63
|
end
|
47
64
|
|
48
|
-
def
|
49
|
-
WebSocket
|
65
|
+
def call_faye(env)
|
66
|
+
if Faye::WebSocket.websocket?(env)
|
67
|
+
connection = Crimson::Adapters::Faye.new(Faye::WebSocket.new(env))
|
50
68
|
id = :"client_#{Utilities.generate_id}"
|
51
|
-
client = Client.new(id,
|
69
|
+
client = Client.new(id, connection)
|
70
|
+
clients[id] = client
|
52
71
|
|
53
|
-
|
54
|
-
clients[id] = client
|
55
|
-
@on_connect.call(client)
|
56
|
-
}
|
72
|
+
@on_connect&.call(client)
|
57
73
|
|
58
|
-
|
59
|
-
|
74
|
+
connection.on :message do |event|
|
75
|
+
client.on_message(JSON.parse(event.data))
|
76
|
+
end
|
77
|
+
|
78
|
+
connection.on :close do |event|
|
79
|
+
@on_disconnect&.call(client)
|
60
80
|
clients.delete(id)
|
61
|
-
|
81
|
+
connection = nil
|
82
|
+
end
|
83
|
+
|
84
|
+
return connection.rack_response
|
62
85
|
end
|
63
86
|
end
|
64
87
|
|
65
|
-
def
|
66
|
-
|
88
|
+
def serve_template(env)
|
89
|
+
if env['REQUEST_PATH'] != '/'
|
90
|
+
return Rack::Directory.new(File.expand_path("#{__dir__}/..")).call(env)
|
91
|
+
else
|
92
|
+
return [200, {"Content-Type" => "text/html"}, content(env['SERVER_PORT'])]
|
93
|
+
end
|
67
94
|
end
|
68
95
|
end
|
69
96
|
end
|
data/lib/crimson/version.rb
CHANGED
@@ -2,12 +2,17 @@ import MessageHandler from './MessageHandler.js'
|
|
2
2
|
|
3
3
|
export default class ServerInteractor {
|
4
4
|
constructor(uri, objectManager, logger) {
|
5
|
-
|
5
|
+
this.uri = uri;
|
6
|
+
this.messageHandler = new MessageHandler(this, objectManager, logger);
|
7
|
+
this.logger = logger;
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
this.connect();
|
10
|
+
}
|
11
|
+
|
12
|
+
connect() {
|
13
|
+
const me = this;
|
9
14
|
|
10
|
-
me.socket = new WebSocket("ws://" + uri);
|
15
|
+
me.socket = new WebSocket("ws://" + me.uri);
|
11
16
|
me.socket.onopen = function (event) { me.onOpen(event); };
|
12
17
|
me.socket.onmessage = function (event) { me.onMessage(event); };
|
13
18
|
me.socket.onclose = function (event) { me.onClose(event); };
|
@@ -29,11 +34,18 @@ export default class ServerInteractor {
|
|
29
34
|
}
|
30
35
|
|
31
36
|
onClose(event) {
|
37
|
+
const me = this;
|
38
|
+
|
32
39
|
if (event.wasClean) {
|
33
|
-
|
40
|
+
me.logger.log(`[ServerInteractor] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
|
34
41
|
} else {
|
35
|
-
|
42
|
+
me.logger.log("[ServerInteractor] Connection died.");
|
36
43
|
}
|
44
|
+
|
45
|
+
me.logger.log("[ServerInteractor] Attempting to reestablish connection...")
|
46
|
+
setTimeout(function() {
|
47
|
+
me.connect();
|
48
|
+
}, 5000);
|
37
49
|
}
|
38
50
|
|
39
51
|
onError(error) {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crimson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rizwan Qureshi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,10 +59,8 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- ".github/workflows/gempush.yml"
|
63
62
|
- ".gitignore"
|
64
63
|
- ".travis.yml"
|
65
|
-
- ".vscode/launch.json"
|
66
64
|
- CODE_OF_CONDUCT.md
|
67
65
|
- Gemfile
|
68
66
|
- LICENSE.txt
|
@@ -73,10 +71,10 @@ files:
|
|
73
71
|
- crimson.gemspec
|
74
72
|
- doc/images/prelim-ruby-js-comms.png
|
75
73
|
- doc/images/temperature-readme-example.PNG
|
76
|
-
- example/
|
77
|
-
- example/example.rb
|
74
|
+
- example/config.ru
|
78
75
|
- lib/crimson.js
|
79
76
|
- lib/crimson.rb
|
77
|
+
- lib/crimson/adapters/faye.rb
|
80
78
|
- lib/crimson/client.rb
|
81
79
|
- lib/crimson/icons/close.png
|
82
80
|
- lib/crimson/icons/hide.png
|
@@ -89,7 +87,6 @@ files:
|
|
89
87
|
- lib/crimson/server.rb
|
90
88
|
- lib/crimson/utilities.rb
|
91
89
|
- lib/crimson/version.rb
|
92
|
-
- lib/crimson/webserver.rb
|
93
90
|
- lib/crimson/widgets/bottom_resizer.rb
|
94
91
|
- lib/crimson/widgets/desktop.rb
|
95
92
|
- lib/crimson/widgets/form.rb
|
@@ -1,44 +0,0 @@
|
|
1
|
-
name: Ruby Gem
|
2
|
-
|
3
|
-
on:
|
4
|
-
pull_request:
|
5
|
-
branches:
|
6
|
-
- master
|
7
|
-
push:
|
8
|
-
branches:
|
9
|
-
- master
|
10
|
-
|
11
|
-
jobs:
|
12
|
-
build:
|
13
|
-
name: Build + Publish
|
14
|
-
runs-on: ubuntu-latest
|
15
|
-
|
16
|
-
steps:
|
17
|
-
- uses: actions/checkout@master
|
18
|
-
- name: Set up Ruby 2.6
|
19
|
-
uses: actions/setup-ruby@v1
|
20
|
-
with:
|
21
|
-
version: 2.6.x
|
22
|
-
|
23
|
-
- name: Publish to GPR
|
24
|
-
run: |
|
25
|
-
mkdir -p $HOME/.gem
|
26
|
-
touch $HOME/.gem/credentials
|
27
|
-
chmod 0600 $HOME/.gem/credentials
|
28
|
-
printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
29
|
-
gem build *.gemspec
|
30
|
-
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
31
|
-
env:
|
32
|
-
GEM_HOST_API_KEY: ${{secrets.GPR_AUTH_TOKEN}}
|
33
|
-
OWNER: username
|
34
|
-
|
35
|
-
- name: Publish to RubyGems
|
36
|
-
run: |
|
37
|
-
mkdir -p $HOME/.gem
|
38
|
-
touch $HOME/.gem/credentials
|
39
|
-
chmod 0600 $HOME/.gem/credentials
|
40
|
-
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
41
|
-
gem build *.gemspec
|
42
|
-
gem push *.gem
|
43
|
-
env:
|
44
|
-
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
data/.vscode/launch.json
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
{
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
3
|
-
// Hover to view descriptions of existing attributes.
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
5
|
-
"version": "0.2.0",
|
6
|
-
"configurations": [
|
7
|
-
{
|
8
|
-
"name": "Debug Local File",
|
9
|
-
"type": "Ruby",
|
10
|
-
"request": "launch",
|
11
|
-
"program": "${workspaceRoot}/example/ets.rb"
|
12
|
-
}
|
13
|
-
]
|
14
|
-
}
|
data/example/ets.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../crimson'
|
4
|
-
require_relative '../lib/ruby/widgets/desktop'
|
5
|
-
|
6
|
-
# server = Crimson::Server.new
|
7
|
-
|
8
|
-
# desktop = Crimson::Desktop.new
|
9
|
-
# desktop.style.backgroundColor = 'black'
|
10
|
-
# desktop.commit_tree!
|
11
|
-
|
12
|
-
# server.on_connect do |client|
|
13
|
-
# puts "#{client.id} connected"
|
14
|
-
|
15
|
-
# client.observe(desktop)
|
16
|
-
# end
|
17
|
-
|
18
|
-
# server.on_disconnect do |client|
|
19
|
-
# puts "#{client.id} disconnected"
|
20
|
-
# end
|
21
|
-
|
22
|
-
# server.run
|
data/lib/crimson/webserver.rb
DELETED