Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Join/leave subscribed rooms when starting/stopping server.

Fixed notification icon path.
  • Loading branch information...
commit 731b62dbf0f5cb77923fe2e02041d712cd032ddb 1 parent 07163b2
@avdi authored
View
4 bin/firetower
@@ -213,16 +213,16 @@ Main do
def run
if detach
firetower_daemon.startup
+ puts "Firetower is vigilantly scanning the treetops"
else
logger ::Logger.new($stdout)
start_server(:logger => logger)
end
- puts "Firetower is vigilantly scanning the treetops"
end
end
mode :stop do
- description "Start the listener daemon"
+ description "Stop the listener daemon"
def run
firetower_daemon.shutdown
View
BIN  images/campfire-logo-for-fluid.png
Deleted file not rendered
View
23 lib/firetower/account.rb
@@ -11,6 +11,7 @@ def initialize(subdomain, token, session, options = {})
data = session.get(subdomain, "/users/#{user_id}.json")
cache[user_id] = data['user']
end
+ @joined_rooms = []
end
def rooms
@@ -45,6 +46,28 @@ def paste!(room_name, text)
})
end
+ def join!(room_name)
+ room = rooms[room_name]
+ session.post(subdomain, "/room/#{room.id}/join.json")
+ @joined_rooms << room
+ session.logger.info "Joined room #{subdomain}/#{room_name}"
+ session.execute_hook(:join, session, room)
+ end
+
+ def leave!(room_name)
+ room = rooms[room_name]
+ session.post(subdomain, "/room/#{room.id}/leave.json")
+ @joined_rooms.delete(room)
+ session.logger.info "Left room #{subdomain}/#{room_name}"
+ session.execute_hook(:leave, session, room)
+ end
+
+ def close!
+ @joined_rooms.each do |room|
+ leave!(room.name)
+ end
+ end
+
def ssl?
@ssl
end
View
12 lib/firetower/plugins/core/notify_plugin.rb
@@ -4,7 +4,7 @@ class NotifyPlugin < Firetower::Session::Listener
def startup(session)
if session.kind == :server
- notify("Firetower", "Firetower is vigilant!")
+ notify("Firetower", "Firetower is vigilantly scanning the treetops")
end
end
@@ -12,6 +12,10 @@ def join(session, room)
notify("Firetower", "Joined room \"#{room.name}\"")
end
+ def leave(session, room)
+ notify("Firetower", "Left room \"#{room.name}\"")
+ end
+
def receive(session, event)
case event['type']
when "TextMessage"
@@ -22,8 +26,8 @@ def receive(session, event)
end
end
- def error(session, description)
- notify("Campfire Error", description)
+ def error(session, error)
+ notify("Campfire Error", error.message)
end
private
@@ -31,7 +35,7 @@ def error(session, description)
def notify(*args)
system('notify-send', '--icon',
File.expand_path(
- '../images/campfire-logo-for-fluid.png',
+ 'campfire-logo-for-fluid.png',
File.dirname(__FILE__)),
'-c', 'Firetower',
*args) or raise "Desktop notification failed"
View
11 lib/firetower/server.rb
@@ -26,11 +26,16 @@ def run
subscribe_to_room(room)
end
end
+ @logger.info "Finished processing events; closing session"
session.close!
+ @logger.info "Session closed"
end
def subscribe_to_room(room)
@logger.info "Subscribing to #{room}"
+
+ room.account.join!(room.name)
+
stream = Twitter::JSONStream.connect(
:path => "/room/#{room.id}/live.json",
:host => 'streaming.campfirenow.com',
@@ -45,8 +50,9 @@ def subscribe_to_room(room)
end
stream.on_error do |message|
- @logger.error message
- session.execute_hook(:error, session, message)
+ error = RuntimeError.new(message)
+ @logger.error error.message
+ session.execute_hook(:error, error)
end
stream.on_max_reconnects do |timeout, retries|
@@ -55,7 +61,6 @@ def subscribe_to_room(room)
"Unable to connect after #{retries} attempts")
stop_event_loop
end
- session.execute_hook(:join, session, room)
end
end
View
10 lib/firetower/session.rb
@@ -19,7 +19,7 @@ class Session
define_hook :connect, :session, :account
define_hook :join, :session, :room
define_hook :receive, :session, :event
- define_hook :error, :session, :description
+ define_hook :error, :session, :error
define_hook :leave, :session, :room
define_hook :disconnect, :session, :account
define_hook :shutdown, :session
@@ -71,9 +71,9 @@ def default_room
@default_room ||= @subscribed_rooms.first
end
- def post(subdomain, path, data)
+ def post(subdomain, path, data=nil)
request = Net::HTTP::Post.new(path)
- request.body = data.to_json
+ request.body = data.to_json if data
request['Content-Type'] = 'application/json'
perform_request(subdomain, request)
end
@@ -98,7 +98,9 @@ def perform_request(subdomain, request)
end
def close!
- # TODO
+ accounts.values.each do |account|
+ account.close!
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.