Sha256: b2e33393dda7f82450b0dba08498195bd3d9e0f47097f7b39021952380106c9c
Contents?: true
Size: 1.57 KB
Versions: 5
Compression:
Stored size: 1.57 KB
Contents
require 'json' require File.join(File.dirname(__FILE__), '../../../app/volt/tasks/query_tasks') module Volt class SocketConnectionHandler # Create one instance of the dispatcher # We track the connected user_id with the channel for use with permissions. # This may be changed as new listeners connect, which is fine. attr_accessor :user_id def self.dispatcher=(val) @@dispatcher = val end def self.dispatcher @@dispatcher end # Sends a message to all, optionally skipping a users channel def self.send_message_all(skip_channel = nil, *args) return unless defined?(@@channels) @@channels.each do |channel| if skip_channel && channel == skip_channel next end channel.send_message(*args) end end def initialize(session, *args) @session = session @@channels ||= [] @@channels << self end def process_message(message) # self.class.message_all(message) # Messages are json and wrapped in an array message = JSON.parse(message).first @@dispatcher.dispatch(self, message) end def send_message(*args) str = JSON.dump([*args]) @session.send(str) end def closed unless @closed @closed = true # Remove ourself from the available channels @@channels.delete(self) QueryTasks.new(self).close! else Volt.logger.error("Socket Error: Connection already closed\n#{inspect}") end end def inspect "<#{self.class}:#{object_id}>" end end end
Version data entries
5 entries across 5 versions & 1 rubygems