Class: Onebot::WebSocket::Server

Inherits:
Bot
  • Object
show all
Defined in:
lib/Core/WebSocket/Server.rb

Instance Attribute Summary collapse

Attributes inherited from Bot

#selfID

Instance Method Summary collapse

Methods inherited from Bot

#method_missing, #respond_to_missing?, #sendMessage

Constructor Details

#initialize(env:, logger: nil, options: { ping: 5 }) {|_self| ... } ⇒ Server

Returns a new instance of Server.

Yields:

  • (_self)

Yield Parameters:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/Core/WebSocket/Server.rb', line 11

def initialize(env:, logger: nil, options: { ping: 5 }, &block)
  super
  @eventLogger = Logging::EventLogger.new(logger)
  @ws = Faye::WebSocket.new(env, %w[irc xmpp], options)
  @api = API.new(@ws, @eventLogger)
  @eventLogger.log(['客户端', '连接', @ws.url, @ws.version], ::Logger::INFO, 'Server')

  @ws.on :message do |event|
    Thread.new { dataParse(event.data) }
  end

  @ws.on :close do |event|
    @eventLogger.log(['客户端', '断开', event.code].to_s, ::Logger::INFO, 'Server')
    @ws = nil
  end

  yield self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Onebot::WebSocket::Bot

Instance Attribute Details

#apiObject

Returns the value of attribute api.



7
8
9
# File 'lib/Core/WebSocket/Server.rb', line 7

def api
  @api
end

#wsFaye::WebSocket

Returns ws server.

Returns:

  • ws server



6
7
8
# File 'lib/Core/WebSocket/Server.rb', line 6

def ws
  @ws
end

Instance Method Details

#rack_responseObject



30
31
32
# File 'lib/Core/WebSocket/Server.rb', line 30

def rack_response
  @ws.rack_response
end