-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
120 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require './lib/em/pusher/client' | ||
|
||
pusher_key = 'pusher_key' | ||
channel = 'private-channel' | ||
pusher_secret = 'pusher_secret' | ||
|
||
EM.run do | ||
opts = { | ||
key: pusher_key, | ||
cluster: 'us2', | ||
port: 80, | ||
scheme: 'ws', | ||
} | ||
EM::Pusher::Client.connect(opts) do |conn| | ||
conn.connected do | ||
puts 'connected' | ||
end | ||
|
||
conn.connection_established do |socket_id| | ||
puts 'callback' | ||
auth = EM::Pusher::Client.build_auth(pusher_secret, pusher_key, socket_id, channel) | ||
msg = { | ||
event: 'pusher:subscribe', | ||
data: { | ||
channel: channel, | ||
auth: auth, | ||
}, | ||
} | ||
conn.send_msg(msg) | ||
end | ||
|
||
conn.errback do |e| | ||
puts "Got error: #{e}" | ||
end | ||
|
||
conn.stream do |msg| | ||
case msg.event | ||
when 'pusher:connection_established' | ||
puts 'Connection Established' | ||
when 'pusher_internal:subscription_succeeded' | ||
puts "Subscribed to #{msg.json['channel']}" | ||
when 'someevent' | ||
puts "#{msg.type}: #{msg.event} >> #{msg.data}" | ||
else | ||
puts "unexpected event (#{msg.type}): <#{msg}>" | ||
end | ||
# conn.close_connection if closed? | ||
end | ||
|
||
conn.disconnect do | ||
puts 'gone' | ||
EM.stop_event_loop | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
module Em | ||
module Pusher | ||
module Client | ||
VERSION = '0.1.1' | ||
VERSION = '0.1.2' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters