Class: SocketClientWebSockets

Inherits:
SocketClientBase show all
Defined in:
lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb

Instance Attribute Summary

Attributes inherited from SocketClientBase

#callback_on_disconnect, #ip, #player, #should_disconnect_session, #time_last_request

Instance Method Summary collapse

Methods inherited from SocketClientBase

#get_requests, #is_online?, manager_remote, manager_remote=, #receive_data, #send_response_error, #send_response_ok, #unbind

Instance Method Details

#close_connection_after_writingObject



98
99
100
# File 'lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb', line 98

def close_connection_after_writing
  @websocket.close_connection_after_writing
end

#post_initObject



68
69
70
# File 'lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb', line 68

def post_init
  super
end

#send_raw_data(response) ⇒ Object



91
92
93
94
95
# File 'lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb', line 91

def send_raw_data(response)
  try_send_binary(response)

  nil
end

#send_response(response_obj) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb', line 78

def send_response(response_obj)
  return unless @is_online

  report_about_sent_request(response_obj)

  response = AMF::Root.serialize(response_obj)

  try_send_binary(response)

  nil #for prevent return other value
end

#websocket=(value) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb', line 24

def websocket=(value)
  @websocket = value

  init_ip_internal(@websocket.get_peername)

  @websocket.onopen do |handshake|
    begin
      on_connection_open(handshake)
    rescue Exception => e
      on_error(e)
    end
  end

  @websocket.onclose do
    begin
      on_connection_closed
    rescue Exception => e
      on_error(e)
    end
  end

  @websocket.onmessage do |data|
    begin
      receive_data(data)
    rescue Exception => e
      on_error(e)
    end
  end

  @websocket.onbinary do |data|
    begin
      receive_data(data)
    rescue Exception => e
      on_error(e)
    end
  end
end