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.



305
306
307
308
# File 'lib/websocket_client.rb', line 305

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

Instance Attribute Details

#handshake_futureObject (readonly)

Returns the value of attribute handshake_future.



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

def handshake_future
  @handshake_future
end

Instance Method Details

#channelActive(ctx) ⇒ Object



314
315
316
317
# File 'lib/websocket_client.rb', line 314

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

#channelInactive(ctx) ⇒ Object



319
320
321
# File 'lib/websocket_client.rb', line 319

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’



327
328
329
# File 'lib/websocket_client.rb', line 327

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

#exceptionCaught(ctx, cause) ⇒ Object



337
338
339
340
341
# File 'lib/websocket_client.rb', line 337

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

#handlerAdded(ctx) ⇒ Object



310
311
312
# File 'lib/websocket_client.rb', line 310

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

#messageReceived(ctx, msg) ⇒ Object



331
332
333
334
335
# File 'lib/websocket_client.rb', line 331

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