Module: JsClient
- Includes:
- EM::Protocols::LineText2
- Defined in:
- lib/jschat/client.rb
Defined Under Namespace
Modules: KeyboardInput
Classes: TabComplete
Instance Method Summary
collapse
Instance Method Details
#keyboard=(keyboard) ⇒ Object
239
240
241
|
# File 'lib/jschat/client.rb', line 239
def keyboard=(keyboard)
@keyboard = keyboard
end
|
#names ⇒ Object
248
249
250
|
# File 'lib/jschat/client.rb', line 248
def names
@names
end
|
#names=(names) ⇒ Object
This should take room into account
244
245
246
|
# File 'lib/jschat/client.rb', line 244
def names=(names)
@names = names
end
|
#post_init ⇒ Object
743
744
745
746
747
|
# File 'lib/jschat/client.rb', line 743
def post_init
@protocol = JsChat::Protocol.new self
send_identify ClientConfig[:name]
end
|
#receive_line(data) ⇒ Object
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
|
# File 'lib/jschat/client.rb', line 664
def receive_line(data)
data.split("\n").each do |line|
json = JSON.parse(line.strip)
protocol_response = @protocol.process_message json
if protocol_response
if protocol_response.kind_of? Array
protocol_response.each do |response|
@keyboard.show_message response.message, response.time
end
else
@keyboard.show_message protocol_response.message, protocol_response.time
end
elsif json.has_key? 'notice'
@keyboard.show_message "* #{json['notice']}"
else
@keyboard.show_message "* [SERVER] #{line}"
end
end
rescue Exception => exception
@keyboard.show_message "* [CLIENT ERROR] #{exception}"
end
|
#send_change_name(username) ⇒ Object
728
729
730
731
732
733
734
|
# File 'lib/jschat/client.rb', line 728
def send_change_name(username)
if @protocol.identified?
send_data({ 'change' => 'user', 'user' => { 'name' => username } }.to_json + "\n")
else
send_identify username
end
end
|
#send_identify(username) ⇒ Object
724
725
726
|
# File 'lib/jschat/client.rb', line 724
def send_identify(username)
send_data({ 'identify' => username }.to_json + "\n")
end
|
#send_join(room) ⇒ Object
687
688
689
690
691
692
|
# File 'lib/jschat/client.rb', line 687
def send_join(room)
@current_room = room
@keyboard.room_name = room
@keyboard.display_room_name
send_data({ 'join' => room }.to_json + "\n")
end
|
#send_lastlog(room = nil) ⇒ Object
711
712
713
714
|
# File 'lib/jschat/client.rb', line 711
def send_lastlog(room = nil)
room = @current_room if room.nil? or room.strip.empty?
send_data({ 'lastlog' => room }.to_json + "\n")
end
|
#send_message(line) ⇒ Object
716
717
718
|
# File 'lib/jschat/client.rb', line 716
def send_message(line)
send_data({ 'to' => @current_room, 'send' => line }.to_json + "\n")
end
|
#send_names(room = nil) ⇒ Object
706
707
708
709
|
# File 'lib/jschat/client.rb', line 706
def send_names(room = nil)
room = @current_room if room.nil? or room.strip.empty?
send_data({ 'names' => room }.to_json + "\n")
end
|
#send_part(room = nil) ⇒ Object
701
702
703
704
|
# File 'lib/jschat/client.rb', line 701
def send_part(room = nil)
room = @current_room if room.nil?
send_data({ 'part' => room }.to_json + "\n")
end
|
#send_private_message(user, message) ⇒ Object
720
721
722
|
# File 'lib/jschat/client.rb', line 720
def send_private_message(user, message)
send_data({ 'to' => user, 'send' => message }.to_json + "\n")
end
|
#switch_room(room) ⇒ Object
694
695
696
697
698
699
|
# File 'lib/jschat/client.rb', line 694
def switch_room(room)
@current_room = room
@keyboard.room_name = room
@keyboard.display_room_name
@keyboard.show_message "* Switched room to: #{room}"
end
|
#unbind ⇒ Object
736
737
738
739
740
741
|
# File 'lib/jschat/client.rb', line 736
def unbind
Ncurses.endwin
Ncurses.clear
puts "Disconnected from server"
exit
end
|