Class: OpenC3::RunningScriptWebSocketApi
- Inherits:
-
ScriptWebSocketApi
- Object
- WebSocketApi
- ScriptWebSocketApi
- OpenC3::RunningScriptWebSocketApi
- Defined in:
- lib/openc3/script/web_socket_api.rb
Overview
Running Script WebSocket
Constant Summary
Constants inherited from WebSocketApi
WebSocketApi::DEFAULT_OPTIONS, WebSocketApi::USER_AGENT
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
-
#initialize(id:, **options) ⇒ RunningScriptWebSocketApi
constructor
A new instance of RunningScriptWebSocketApi.
-
#read(ignore_protocol_messages: true, timeout: nil) ⇒ Object
RunningScriptChannel batches events to reduce ActionCable frame and client-dispatch overhead.
-
#subscribe ⇒ Object
The backlog of script events is transmitted with the subscription confirmation, but LIVE events only flow once the client reports that it is ready to stream events (see RunningScriptChannel#ready) -- a broadcast sent before the gateway has registered this subscription's stream would be silently dropped.
- #unsubscribe ⇒ Object
Methods inherited from ScriptWebSocketApi
Methods inherited from WebSocketApi
cable_url, #check_protocol_frame, #connected?, #generate_auth, #parse_message, #read_message, #wait_for_subscribed, #write, #write_action, #write_command
Constructor Details
#initialize(id:, **options) ⇒ RunningScriptWebSocketApi
Returns a new instance of RunningScriptWebSocketApi.
309 310 311 312 313 314 315 316 |
# File 'lib/openc3/script/web_socket_api.rb', line 309 def initialize(id:, **) @pending_events = [] @identifier = { channel: "RunningScriptChannel", id: id } super(**) end |
Instance Method Details
#connect ⇒ Object
345 346 347 348 |
# File 'lib/openc3/script/web_socket_api.rb', line 345 def connect @pending_events.clear super end |
#disconnect ⇒ Object
355 356 357 358 |
# File 'lib/openc3/script/web_socket_api.rb', line 355 def disconnect @pending_events.clear super end |
#read(ignore_protocol_messages: true, timeout: nil) ⇒ Object
RunningScriptChannel batches events to reduce ActionCable frame and client-dispatch overhead. Preserve the public API's historical contract: callers still receive one script event from each read.
333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/openc3/script/web_socket_api.rb', line 333 def read(ignore_protocol_messages: true, timeout: nil) return @pending_events.shift unless @pending_events.empty? loop do = super return unless .is_a?(Array) @pending_events.concat() return @pending_events.shift unless @pending_events.empty? end end |
#subscribe ⇒ Object
The backlog of script events is transmitted with the subscription confirmation, but LIVE events only flow once the client reports that it is ready to stream events (see RunningScriptChannel#ready) -- a broadcast sent before the gateway has registered this subscription's stream would be silently dropped. subscribe() blocks until confirm_subscription, so the 'ready' action is guaranteed to arrive after the stream is registered.
324 325 326 327 328 |
# File 'lib/openc3/script/web_socket_api.rb', line 324 def subscribe was_subscribed = @subscribed super write_action({ 'action' => 'ready' }) unless was_subscribed end |
#unsubscribe ⇒ Object
350 351 352 353 |
# File 'lib/openc3/script/web_socket_api.rb', line 350 def unsubscribe @pending_events.clear super end |