Class: OpenC3::ScriptWebSocketApi

Inherits:
WebSocketApi show all
Defined in:
lib/openc3/script/web_socket_api.rb

Overview

Base class for script-runner-api websockets - Do not use directly

Constant Summary

Constants inherited from WebSocketApi

WebSocketApi::USER_AGENT

Instance Method Summary collapse

Methods inherited from WebSocketApi

#connect, #connected?, #disconnect, #generate_auth, #read, #read_message, #subscribe, #unsubscribe, #write, #write_action

Constructor Details

#initialize(url: nil, write_timeout: 10.0, read_timeout: 10.0, connect_timeout: 5.0, authentication: nil, scope: $openc3_scope) ⇒ ScriptWebSocketApi

Returns a new instance of ScriptWebSocketApi.



193
194
195
196
# File 'lib/openc3/script/web_socket_api.rb', line 193

def initialize(url: nil, write_timeout: 10.0, read_timeout: 10.0, connect_timeout: 5.0, authentication: nil, scope: $openc3_scope)
  url = generate_url() unless url
  super(url: url, write_timeout: write_timeout, read_timeout: read_timeout, connect_timeout: connect_timeout, authentication: authentication, scope: scope)
end

Instance Method Details

#generate_urlObject



198
199
200
201
202
203
204
# File 'lib/openc3/script/web_socket_api.rb', line 198

def generate_url
  schema = ENV['OPENC3_SCRIPT_API_SCHEMA'] || 'http'
  hostname = ENV['OPENC3_SCRIPT_API_HOSTNAME'] || (ENV['OPENC3_DEVEL'] ? '127.0.0.1' : 'openc3-cosmos-script-runner-api')
  port = ENV['OPENC3_SCRIPT_API_PORT'] || '2902'
  port = port.to_i
  return "#{schema}://#{hostname}:#{port}/script-api/cable"
end