Skip to content

Commit

Permalink
[#1] Upd websocket-ruby version (added subprotocols support)
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Feb 4, 2017
1 parent f59bea9 commit eed9f5a
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 59 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
@@ -1,6 +1,10 @@
# Change log

## master
## 0.4.1 (2017-02-04)

- Use `websocket-ruby` with subprotocols support ([@palkan][])

## 0.4.0 (2017-01-29)

- Initial version. ([@palkan][])

Expand Down
4 changes: 2 additions & 2 deletions examples/sinatra/Gemfile
Expand Up @@ -9,8 +9,8 @@ gem 'puma'
gem 'pry-byebug'

# litecable deps
gem "anyway_config", "~>0.5.0"
gem "websocket"
gem "anyway_config", "~> 0.5.0"
gem "websocket", "~> 1.2.4"

# anycable
gem "anycable", "~> 0.4.2"
2 changes: 1 addition & 1 deletion lib/lite_cable/connection/subscriptions.rb
Expand Up @@ -56,7 +56,7 @@ def execute_command(data)
when "unsubscribe" then remove(data["identifier"])
when "message" then perform_action(data["identifier"], data["data"])
else
raise UnknownCommandError
raise UnknownCommandError, "Command not found #{command}"
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/lite_cable/server/client_socket/base.rb
Expand Up @@ -113,6 +113,8 @@ def close_socket
frame = WebSocket::Frame::Outgoing::Server.new(version: version, type: :close, code: 1000)
@socket.write(frame.to_s) if frame.supported?
@socket.close
rescue IOError, Errno::EPIPE, Errno::ETIMEDOUT # rubocop:disable Lint/HandleExceptions
# already closed
end

def keepalive
Expand Down
8 changes: 4 additions & 4 deletions lib/lite_cable/server/middleware.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
module LiteCable
module Server
require "lite_cable/server/websocket_ext/protocols"
# Rack middleware to hijack the socket
class Middleware
class HijackNotAvailable < RuntimeError; end
Expand Down Expand Up @@ -30,10 +29,11 @@ def call(env)
private

def send_handshake(env)
handshake = WebSocket::Handshake::Server.new
handshake.from_rack env
handshake.protocols LiteCable::INTERNAL[:protocols]
handshake = WebSocket::Handshake::Server.new(
protocols: LiteCable::INTERNAL[:protocols]
)

handshake.from_rack env
env['rack.hijack_io'].write handshake.to_s
handshake
end
Expand Down
45 changes: 0 additions & 45 deletions lib/lite_cable/server/websocket_ext/protocols.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/lite_cable/version.rb
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module LiteCable
VERSION = "0.4.0"
VERSION = "0.4.1"
end
2 changes: 1 addition & 1 deletion litecable.gemspec
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "anyway_config", "~>0.5.0"

spec.add_development_dependency "rack", "~> 2.0"
spec.add_development_dependency "websocket", "~> 1.2.0"
spec.add_development_dependency "websocket", "~> 1.2.4"
spec.add_development_dependency "websocket-client-simple", "~> 0.3.0"
spec.add_development_dependency "concurrent-ruby", "~> 1.0.0"
spec.add_development_dependency "puma", "~> 3.6.0"
Expand Down
4 changes: 2 additions & 2 deletions spec/integrations/server_spec.rb
Expand Up @@ -70,7 +70,7 @@ def bulk(data)

let(:cookies) { "user=john" }
let(:path) { "/?sid=123" }
let(:client) { @client = SyncClient.new("ws://127.0.0.1:3099#{path}", cookies) }
let(:client) { @client = SyncClient.new("ws://127.0.0.1:3099#{path}", cookies: cookies) }
let(:logs) { ServerTest.logs }

after { logs.clear }
Expand Down Expand Up @@ -127,7 +127,7 @@ def bulk(data)
end

describe "broadcasts" do
let(:client2) { @client2 = SyncClient.new("ws://127.0.0.1:3099/?sid=234", "user=alice") }
let(:client2) { @client2 = SyncClient.new("ws://127.0.0.1:3099/?sid=234", cookies: "user=alice") }

let(:clients) { [client, client2] }

Expand Down
9 changes: 7 additions & 2 deletions spec/support/sync_client.rb
Expand Up @@ -11,15 +11,20 @@ class SyncClient

attr_reader :pings

def initialize(url, cookies = '')
def initialize(url, cookies: '')
messages = @messages = Queue.new
closed = @closed = Concurrent::Event.new
has_messages = @has_messages = Concurrent::Semaphore.new(0)
pings = @pings = Concurrent::AtomicFixnum.new(0)

open = Concurrent::Promise.new

@ws = WebSocket::Client::Simple.connect(url, headers: { 'COOKIE' => cookies }) do |ws|
@ws = WebSocket::Client::Simple.connect(
url,
headers: {
'COOKIE' => cookies
}
) do |ws|
ws.on(:error) do |event|
event = RuntimeError.new(event.message) unless event.is_a?(Exception)

Expand Down

0 comments on commit eed9f5a

Please sign in to comment.