File: websocket.rb

package info (click to toggle)
ruby-websocket 1.2.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 412 kB
  • sloc: ruby: 2,667; makefile: 4
file content (46 lines) | stat: -rw-r--r-- 1,432 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

# WebSocket protocol implementation in Ruby
# This module does not provide a WebSocket server or client, but is made for using
# in http servers or clients to provide WebSocket support.
# @author Bernard "Imanel" Potocki
# @see http://github.com/imanel/websocket-ruby main repository
module WebSocket
  # Default WebSocket version to use
  DEFAULT_VERSION = 13
  ROOT = __dir__

  autoload :Error,            "#{ROOT}/websocket/error"
  autoload :ExceptionHandler, "#{ROOT}/websocket/exception_handler"
  autoload :Frame,            "#{ROOT}/websocket/frame"
  autoload :Handshake,        "#{ROOT}/websocket/handshake"
  autoload :NiceInspect,      "#{ROOT}/websocket/nice_inspect"

  # Limit of frame size payload in bytes
  def self.max_frame_size
    @max_frame_size ||= 20 * 1024 * 1024 # 20MB
  end

  # Set limit of frame size payload in bytes
  def self.max_frame_size=(val)
    @max_frame_size = val
  end

  # If set to true error will be raised instead of setting `error` method.
  # All errors inherit from WebSocket::Error.
  def self.should_raise
    @should_raise ||= false
  end

  # Should protocol errors raise ruby errors? If false then `error` flag is set instead.
  def self.should_raise=(val)
    @should_raise = val
  end
end

# Try loading websocket-native if available
begin
  require 'websocket-native'
rescue LoadError => e
  raise unless e.message =~ /websocket-native/
end