47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/hyper-operation/transport/client_drivers.rb', line 47
def self.connect_to(channel_name, id = nil)
channel_string = add_connection(channel_name, id)
if ClientDrivers.opts[:transport] == :pusher
channel = "#{ClientDrivers.opts[:channel]}-#{channel_string}"
%x{
var channel = #{ClientDrivers.opts[:pusher_api]}.subscribe(#{channel.gsub('::', '==')});
channel.bind('dispatch', #{ClientDrivers.opts[:dispatch]})
channel.bind('pusher:subscription_succeeded', #{lambda {ClientDrivers.get_queued_data("connect-to-transport", channel_string)}})
}
elsif ClientDrivers.opts[:transport] == :action_cable
channel = "#{ClientDrivers.opts[:channel]}-#{channel_string}"
HTTP.post(ClientDrivers.polling_path('action-cable-auth', channel)).then do |response|
%x{
#{Hyperloop.action_cable_consumer}.subscriptions.create(
{
channel: "Hyperloop::ActionCableChannel",
client_id: #{ClientDrivers.opts[:id]},
hyperloop_channel: #{channel_string},
authorization: #{response.json[:authorization]},
salt: #{response.json[:salt]}
},
{
connected: function() {
#{ClientDrivers.get_queued_data("connect-to-transport", channel_string)}
},
received: function(data) {
#{ClientDrivers.sync_dispatch(JSON.parse(`JSON.stringify(data)`)['data'])}
}
}
)
}
end
else
HTTP.get(ClientDrivers.polling_path(:subscribe, channel_string))
end
end
|