cable_room 0.4.2 → 0.4.4
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/lib/cable_room/room/base.rb +3 -0
- data/lib/cable_room/room/input_handling.rb +9 -0
- data/lib/cable_room/room/port_management.rb +11 -3
- data/lib/cable_room/room/port_policies.rb +0 -6
- data/lib/cable_room/room/user_management.rb +4 -2
- data/lib/cable_room/room_member.rb +14 -5
- data/lib/cable_room/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 928184ed2b2f5a529bb24cccde6e0048f9c9f5a7ce2b60b62779bc8f06a998ca
|
|
4
|
+
data.tar.gz: 440782d877fbdc28948fe8499de860bb0d99c4bcde01b1abb933a23f20a14074
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 95047199ea82748e023d3ca246ba942cc4e5845613bd7f76f18c2700e027027f60277f904bc9f3cc5514f808ae7ca4d9305d051fdf40b00d6c280a5fc4e8aba0
|
|
7
|
+
data.tar.gz: 5e4e966735dffddf5c074776ea44702dd52b6cd5559a5b814f7d87a03c3fb58e7acfb3b0b7401452b67e9444d7e67d29352ae726c8ab4ba35353e5390495685b
|
data/lib/cable_room/room/base.rb
CHANGED
|
@@ -28,11 +28,20 @@ module CableRoom
|
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
|
+
|
|
32
|
+
# Prevent certain message types being forwarded from clients
|
|
33
|
+
def system_message_types(*types)
|
|
34
|
+
([self] + ActiveSupport::DescendantsTracker.descendants(self)).reverse_each do |target|
|
|
35
|
+
target._system_message_types = target._system_message_types | Set.new(types.map(&:to_sym))
|
|
36
|
+
end
|
|
37
|
+
end
|
|
31
38
|
end
|
|
32
39
|
|
|
33
40
|
included do
|
|
34
41
|
define_callbacks :receive_message
|
|
35
42
|
|
|
43
|
+
class_attribute :_system_message_types, instance_writer: false, default: Set.new
|
|
44
|
+
|
|
36
45
|
set_callback(:receive_message, :before) do
|
|
37
46
|
logger.debug "Received message: #{message.inspect}"
|
|
38
47
|
end
|
|
@@ -3,9 +3,6 @@ module CableRoom
|
|
|
3
3
|
module PortManagement
|
|
4
4
|
extend ActiveSupport::Concern
|
|
5
5
|
|
|
6
|
-
require_relative 'port_policies'
|
|
7
|
-
include PortPolicies
|
|
8
|
-
|
|
9
6
|
PORT_TIMEOUT = 30.seconds
|
|
10
7
|
|
|
11
8
|
class_methods do
|
|
@@ -38,6 +35,17 @@ module CableRoom
|
|
|
38
35
|
@current_message_origin = previous_mtok
|
|
39
36
|
end
|
|
40
37
|
end
|
|
38
|
+
|
|
39
|
+
system_message_types(:port_connected, :port_disconnected, :port_ping)
|
|
40
|
+
|
|
41
|
+
require_relative 'port_policies'
|
|
42
|
+
include PortPolicies
|
|
43
|
+
|
|
44
|
+
PortPolicies::TagPolicy.define_tag_alias :connect, [:port_connected, :port_ping, :port_disconnected]
|
|
45
|
+
|
|
46
|
+
inbound_tag_policy(priority: -10) do
|
|
47
|
+
allow :*, :connect
|
|
48
|
+
end
|
|
41
49
|
end
|
|
42
50
|
|
|
43
51
|
def initialize(...)
|
|
@@ -36,10 +36,6 @@ module CableRoom
|
|
|
36
36
|
next true if %i[port_connected port_disconnected].include?(msg_type)
|
|
37
37
|
policy_allows?(msg_type)
|
|
38
38
|
end
|
|
39
|
-
|
|
40
|
-
inbound_tag_policy(priority: -10) do
|
|
41
|
-
allow :*, :connect
|
|
42
|
-
end
|
|
43
39
|
end
|
|
44
40
|
|
|
45
41
|
protected
|
|
@@ -58,8 +54,6 @@ module CableRoom
|
|
|
58
54
|
end
|
|
59
55
|
end
|
|
60
56
|
|
|
61
|
-
define_tag_alias :connect, [:port_connected, :port_ping, :port_disconnected]
|
|
62
|
-
|
|
63
57
|
def initialize()
|
|
64
58
|
@policy_rules = []
|
|
65
59
|
@fallback_rule = { action: :allow, priority: -100, tag: :*, methods: :* }
|
|
@@ -25,11 +25,13 @@ module CableRoom
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
system_message_types(:user_joined, :user_left)
|
|
29
|
+
|
|
30
|
+
PortPolicies::TagPolicy.define_tag_alias :join, [:connect, :user_joined, :user_left]
|
|
31
|
+
|
|
28
32
|
inbound_tag_policy(priority: -10) do
|
|
29
33
|
allow :*, :join
|
|
30
34
|
end
|
|
31
|
-
|
|
32
|
-
PortPolicies::TagPolicy.define_tag_alias :join, [:connect, :user_joined, :user_left]
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
def initialize(...)
|
|
@@ -120,7 +120,7 @@ module CableRoom
|
|
|
120
120
|
def ping!
|
|
121
121
|
return if left?
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
port_transmit(room_class::ROOM_IN_CHANNEL, { type: 'port_ping' }, secure_context: true)
|
|
124
124
|
maybe_provision_room
|
|
125
125
|
end
|
|
126
126
|
|
|
@@ -129,7 +129,7 @@ module CableRoom
|
|
|
129
129
|
|
|
130
130
|
close_streamed_ports!
|
|
131
131
|
@cable_channel._room_memberships.delete(self)
|
|
132
|
-
|
|
132
|
+
port_transmit(room_class::ROOM_IN_CHANNEL, { type: 'port_disconnected' }, secure_context: true)
|
|
133
133
|
@has_left = true
|
|
134
134
|
@on_closed&.call(self)
|
|
135
135
|
end
|
|
@@ -138,9 +138,18 @@ module CableRoom
|
|
|
138
138
|
|
|
139
139
|
protected
|
|
140
140
|
|
|
141
|
-
def port_transmit(port, data)
|
|
141
|
+
def port_transmit(port, data, secure_context: false)
|
|
142
142
|
data[:mtok] = @token
|
|
143
|
-
|
|
143
|
+
|
|
144
|
+
unless secure_context
|
|
145
|
+
t = (data[:type] || data['type']).to_sym
|
|
146
|
+
if room_class._system_message_types.include?(t)
|
|
147
|
+
logger.warn "Dropping attempt to send system message type: #{t.inspect}"
|
|
148
|
+
return
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
super(port, data)
|
|
144
153
|
end
|
|
145
154
|
|
|
146
155
|
def room_port_key(port)
|
|
@@ -172,7 +181,7 @@ module CableRoom
|
|
|
172
181
|
tags: @tags,
|
|
173
182
|
}
|
|
174
183
|
msg[:extra] = ::ActiveJob::Arguments.serialize([@extra]) if @extra
|
|
175
|
-
|
|
184
|
+
port_transmit(room_class::ROOM_IN_CHANNEL, msg, secure_context: true)
|
|
176
185
|
end
|
|
177
186
|
|
|
178
187
|
def maybe_provision_room
|
data/lib/cable_room/version.rb
CHANGED