Module: FayeServer

Defined in:
lib/faye-server/faye_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#messaging_serverObject

Returns the value of attribute messaging_server.



2
3
4
# File 'lib/faye-server/faye_server.rb', line 2

def messaging_server
  @messaging_server
end

#messaging_server_optionsObject

Returns the value of attribute messaging_server_options.



2
3
4
# File 'lib/faye-server/faye_server.rb', line 2

def messaging_server_options
  @messaging_server_options
end

#messaging_server_portObject

Returns the value of attribute messaging_server_port.



2
3
4
# File 'lib/faye-server/faye_server.rb', line 2

def messaging_server_port
  @messaging_server_port
end

#messaging_server_threadObject

Returns the value of attribute messaging_server_thread.



2
3
4
# File 'lib/faye-server/faye_server.rb', line 2

def messaging_server_thread
  @messaging_server_thread
end

Instance Method Details

#publish(options = {}) ⇒ Object

Publish a message to a given channel Requres a :channel, and a :message



27
28
29
30
31
# File 'lib/faye-server/faye_server.rb', line 27

def publish(options={})
	raise 'No Channel Provided' if !options[:channel]
	raise 'No Message Provided' if !options[:message]
	self.messaging_server.get_client.publish(options[:channel], options[:message])
end

#start(options = {}) ⇒ Object

Starts the Faye Server in a new thread



5
6
7
8
9
10
11
# File 'lib/faye-server/faye_server.rb', line 5

def start(options={})
	raise 'Already Running' if self.messaging_server and self.messaging_server_thread.status
	self.messaging_server_thread = Thread.new do
		self.messaging_server = Faye::RackAdapter.new(self.messaging_server_options)
		self.messaging_server.listen(self.messaging_server_port)
	end
end

#stopObject

Stops Faye Server Somtimes Thin will return that it is wating on a client connection and you need to hit “ctrl-c”



15
16
17
18
19
20
21
22
23
# File 'lib/faye-server/faye_server.rb', line 15

def stop
	raise 'Not Running' if !self.messaging_server or !self.messaging_server_thread.status
	self.messaging_server.stop
	if self.messaging_server_thread == 'dead'
		true
	else
		false
	end
end