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
Hiroshi Nakamura
committed
Aug 19, 2011
1 parent
0163c28
commit 3e3d19a
Showing
1 changed file
with
31 additions
and
0 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,31 @@ | |||
# Original code is at https://gist.github.com/948374 | |||
module ChatClient | |||
def self.channel | |||
@channel ||= EM::Channel.new | |||
end | |||
|
|||
def post_init | |||
@buf = '' | |||
@name = "anonymous_#{ChatClient.client_num+=1}" | |||
@sid = ChatClient.channel.subscribe { |msg| | |||
send_msg(msg) | |||
} | |||
# ... | |||
ChatClient.channel << "#{@name.bold} has joined.\n" | |||
end | |||
|
|||
def unbind | |||
ChatClient.channel.unsubscribe(@sid) | |||
ChatClient.channel << "#{@name.bold} has left.\n" | |||
end | |||
|
|||
def receive_data data | |||
@buf << data | |||
# ... | |||
while line = extract_line(@buf) | |||
ChatClient.channel << "#{@name.bold}: #{line}\n" | |||
end | |||
end | |||
|
|||
# ... | |||
end |