Class: WebSocket::ClientChannelHandler

Inherits:
SimpleChannelInboundHandler
  • Object
show all
Includes:
Listenable
Defined in:
lib/websocket_client.rb

Overview

The ClientChannelHandler class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Listenable

#add_listener, #listeners, #notify, #remove_listener, #replace_listeners

Constructor Details

#initialize(handshaker) ⇒ ClientChannelHandler

Returns a new instance of ClientChannelHandler.



303
304
305
306
# File 'lib/websocket_client.rb', line 303

def initialize(handshaker)
  super()
  @handshaker = handshaker
end

Instance Attribute Details

#handshake_futureObject (readonly)

Returns the value of attribute handshake_future.



301
302
303
# File 'lib/websocket_client.rb', line 301

def handshake_future
  @handshake_future
end

Instance Method Details

#channelActive(ctx) ⇒ Object



312
313
314
315
# File 'lib/websocket_client.rb', line 312

def channelActive(ctx)
  @handshaker.handshake(ctx.channel())
  notify(:channelActive, ctx)
end

#channelInactive(ctx) ⇒ Object



317
318
319
# File 'lib/websocket_client.rb', line 317

def channelInactive(ctx)
  notify(:channelInactive, ctx)
end

#channelRead0(ctx, msg) ⇒ Object

Please keep in mind that this method will be renamed to messageReceived(ChannelHandlerContext, I) in 5.0.

java_signature ‘protected void channelRead0(ChannelHandlerContext ctx, I msg) throws Exception’



325
326
327
# File 'lib/websocket_client.rb', line 325

def channelRead0(ctx, msg)
  messageReceived(ctx, msg)
end

#exceptionCaught(ctx, cause) ⇒ Object



335
336
337
338
339
# File 'lib/websocket_client.rb', line 335

def exceptionCaught(ctx, cause)
  cause.printStackTrace()
  @handshake_future.setFailure(cause) unless @handshake_future.isDone()
  ctx.close()
end

#handlerAdded(ctx) ⇒ Object



308
309
310
# File 'lib/websocket_client.rb', line 308

def handlerAdded(ctx)
  @handshake_future = ctx.newPromise()
end

#messageReceived(ctx, msg) ⇒ Object



329
330
331
332
333
# File 'lib/websocket_client.rb', line 329

def messageReceived(ctx, msg)
  return finish_handshake(ctx, msg) unless @handshaker.isHandshakeComplete()
  validate_message(msg)
  notify(:messageReceived, ctx, msg)
end