Class: Hyperloop::ClientDrivers
- Includes:
- React::IsomorphicHelpers
- Defined in:
- lib/hyper-operation/transport/client_drivers.rb
Class Attribute Summary collapse
-
.opts ⇒ Object
readonly
Returns the value of attribute opts.
Class Method Summary collapse
- .get_queued_data(operation, channel = nil, opts = {}) ⇒ Object
- .initialize_client_drivers_on_boot ⇒ Object
- .polling_path(to, id = nil) ⇒ Object
- .sync_dispatch(data) ⇒ Object
Class Attribute Details
.opts ⇒ Object (readonly)
Returns the value of attribute opts.
149 150 151 |
# File 'lib/hyper-operation/transport/client_drivers.rb', line 149 def opts @opts end |
Class Method Details
.get_queued_data(operation, channel = nil, opts = {}) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/hyper-operation/transport/client_drivers.rb', line 152 def self.get_queued_data(operation, channel = nil, opts = {}) HTTP.get(polling_path(operation, channel), opts).then do |response| response.json.each do |data| sync_dispatch(data[1]) end end end |
.initialize_client_drivers_on_boot ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/hyper-operation/transport/client_drivers.rb', line 160 def self.initialize_client_drivers_on_boot if @initialized # 1) skip initialization if already initialized # 2) if running action_cable make sure connection is up after pinging the server_up # action cable closes the connection if files change on the server HTTP.get("#{`window.HyperloopEnginePath`}/server_up") do `#{Hyperloop.action_cable_consumer}.connection.open()` if `#{Hyperloop.action_cable_consumer}.connection.disconnected` end if Hyperloop.action_cable_consumer return end @initialized = true if RUBY_ENGINE == 'opal' @opts = Hash.new(`window.HyperloopOpts`) end if on_opal_client? if opts[:transport] == :pusher opts[:dispatch] = lambda do |data| sync_dispatch JSON.parse(`JSON.stringify(#{data})`) end if opts[:client_logging] && `window.console && window.console.log` `Pusher.log = function(message) {window.console.log(message);}` end if opts[:pusher_fake_js] opts[:pusher_api] = `eval(#{opts[:pusher_fake_js]})` else h = nil pusher_api = nil %x{ h = { encrypted: #{opts[:encrypted]}, cluster: #{opts[:cluster]}, authEndpoint: window.HyperloopEnginePath+'/hyperloop-pusher-auth', auth: {headers: {'X-CSRF-Token': #{opts[:form_authenticity_token]}}} }; pusher_api = new Pusher(#{opts[:key]}, h) } opts[:pusher_api] = pusher_api end Hyperloop.connect(*opts[:auto_connect]) elsif opts[:transport] == :action_cable opts[:action_cable_consumer] = `ActionCable.createConsumer.apply(ActionCable, #{[*opts[:action_cable_consumer_url]]})` Hyperloop.connect(*opts[:auto_connect]) elsif opts[:transport] == :simple_poller opts[:auto_connect].each { |channel| IncomingBroadcast.add_connection(*channel) } every(opts[:seconds_between_poll]) do get_queued_data(:read, nil, headers: {'X-HYPERLOOP-SILENT-REQUEST' => true }) end end end end |
.polling_path(to, id = nil) ⇒ Object
218 219 220 221 222 |
# File 'lib/hyper-operation/transport/client_drivers.rb', line 218 def self.polling_path(to, id = nil) s = "#{`window.HyperloopEnginePath`}/hyperloop-#{to}/#{opts[:id]}" s = "#{s}/#{id}" if id s end |
.sync_dispatch(data) ⇒ Object
93 94 95 96 97 |
# File 'lib/hyper-operation/transport/client_drivers.rb', line 93 def self.sync_dispatch(data) # TODO old synchromesh double checked at this point to make sure that this client # expected to recieve from the channel the data was sent on. Was that really needed? data[:operation].constantize.dispatch_from_server(data[:params]) end |