-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmesh_test.rb
46 lines (35 loc) · 1.12 KB
/
mesh_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true
# require 'action_cable_client'
current_dir = File.dirname(__FILE__)
# set load path (similar to how gems require files (relative to lib))
lib = current_dir + '/lib/'
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require current_dir + '/lib/action_cable_client'
class KeyboardHandler < EM::Connection
include EM::Protocols::LineText2
def initialize(client)
@client = client
end
def receive_line(data)
@client.perform('chat', message: data, to: '124')
end
end
# this is just a runnable example from the readme
EventMachine.run do
# client = ActionCableClient.new('ws://mesh-relay-in-us-1.herokuapp.com', 'MeshRelayChannel')
identity = { channel: 'MeshRelayChannel', whatever: 'test params' }
client = ActionCableClient.new('ws://localhost:3000?uid=124', identity)
client.connected { puts 'successfully connected.' }
client.received do |message|
puts client.subscribed?
puts message
end
client.errored do |*args|
puts 'error'
puts args
end
client.disconnected do
puts 'disconnected'
end
EM.open_keyboard(KeyboardHandler, client)
end