Class: SocketClientWebSockets

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

Instance Attribute Summary collapse

Attributes inherited from SocketClientBase

#ip, #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 Attribute Details

#playerObject

Returns the value of attribute player.



35
36
37
# File 'lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb', line 35

def player
  @player
end

Instance Method Details

#close_connection_after_writingObject



112
113
114
# File 'lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb', line 112

def close_connection_after_writing
  @websocket.close_connection_after_writing
end

#post_initObject



82
83
84
# File 'lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb', line 82

def post_init
  super
end

#send_raw_data(response) ⇒ Object



105
106
107
108
109
# File 'lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb', line 105

def send_raw_data(response)
  try_send_binary(response)

  nil
end

#send_response(response_obj) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb', line 92

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



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb', line 38

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