class WebSocket::Driver::Hybi
def frame(buffer, type = nil, code = nil)
def frame(buffer, type = nil, code = nil) return queue([buffer, type, code]) if @ready_state <= 0 return false unless @ready_state == 1 message = Message.new frame = Frame.new message.rsv1 = message.rsv2 = message.rsv3 = false message.opcode = OPCODES[type || (String === buffer ? :text : :binary)] payload = Driver.encode(buffer) payload = [code, payload].pack('S>a*') if code message.data = payload if MESSAGE_OPCODES.include?(message.opcode) message = @extensions.process_outgoing_message(message) end frame.final = true frame.rsv1 = message.rsv1 frame.rsv2 = message.rsv2 frame.rsv3 = message.rsv3 frame.opcode = message.opcode frame.masked = !!@masking frame.masking_key = SecureRandom.random_bytes(4) if frame.masked frame.length = message.data.bytesize frame.payload = message.data send_frame(frame) true rescue ::WebSocket::Extensions::ExtensionError => error fail(:extension_error, error.message) end