litecable 0.4.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +32 -1
- data/LICENSE.txt +1 -1
- data/README.md +30 -28
- data/lib/lite_cable.rb +23 -2
- data/lib/lite_cable/anycable.rb +21 -12
- data/lib/lite_cable/broadcast_adapters.rb +35 -0
- data/lib/lite_cable/broadcast_adapters/any_cable.rb +11 -0
- data/lib/lite_cable/broadcast_adapters/base.rb +17 -0
- data/lib/lite_cable/broadcast_adapters/memory.rb +11 -0
- data/lib/lite_cable/channel.rb +1 -0
- data/lib/lite_cable/channel/base.rb +2 -0
- data/lib/lite_cable/channel/registry.rb +3 -0
- data/lib/lite_cable/channel/streams.rb +1 -0
- data/lib/lite_cable/coders.rb +1 -0
- data/lib/lite_cable/coders/json.rb +1 -0
- data/lib/lite_cable/coders/raw.rb +1 -0
- data/lib/lite_cable/config.rb +8 -6
- data/lib/lite_cable/connection.rb +1 -0
- data/lib/lite_cable/connection/authorization.rb +1 -0
- data/lib/lite_cable/connection/base.rb +2 -0
- data/lib/lite_cable/connection/identification.rb +3 -0
- data/lib/lite_cable/connection/streams.rb +1 -0
- data/lib/lite_cable/connection/subscriptions.rb +5 -3
- data/lib/lite_cable/internal.rb +1 -0
- data/lib/lite_cable/logging.rb +3 -1
- data/lib/lite_cable/server.rb +1 -6
- data/lib/lite_cable/server/client_socket.rb +1 -0
- data/lib/lite_cable/server/client_socket/base.rb +16 -21
- data/lib/lite_cable/server/client_socket/subscriptions.rb +3 -2
- data/lib/lite_cable/server/heart_beat.rb +4 -1
- data/lib/lite_cable/server/middleware.rb +11 -10
- data/lib/lite_cable/server/subscribers_map.rb +3 -0
- data/lib/lite_cable/version.rb +2 -1
- data/lib/litecable.rb +1 -0
- metadata +31 -50
- data/.gitignore +0 -40
- data/.rubocop.yml +0 -63
- data/.travis.yml +0 -7
- data/Gemfile +0 -4
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/circle.yml +0 -8
- data/examples/sinatra/Gemfile +0 -16
- data/examples/sinatra/Procfile +0 -3
- data/examples/sinatra/README.md +0 -33
- data/examples/sinatra/anycable +0 -18
- data/examples/sinatra/app.rb +0 -52
- data/examples/sinatra/assets/app.css +0 -169
- data/examples/sinatra/assets/cable.js +0 -584
- data/examples/sinatra/assets/reset.css +0 -223
- data/examples/sinatra/bin/anycable-go +0 -0
- data/examples/sinatra/chat.rb +0 -39
- data/examples/sinatra/config.ru +0 -28
- data/examples/sinatra/views/index.slim +0 -8
- data/examples/sinatra/views/layout.slim +0 -15
- data/examples/sinatra/views/login.slim +0 -8
- data/examples/sinatra/views/resetcss.slim +0 -224
- data/examples/sinatra/views/room.slim +0 -68
- data/lib/lite_cable/server/websocket_ext/protocols.rb +0 -45
- data/litecable.gemspec +0 -33
@@ -1,68 +0,0 @@
|
|
1
|
-
h2 ="Room: #{@room_id}"
|
2
|
-
|
3
|
-
.messages#message_list
|
4
|
-
|
5
|
-
.message-form
|
6
|
-
form#message_form
|
7
|
-
.row
|
8
|
-
input#message_txt type="text" required="required"
|
9
|
-
.row
|
10
|
-
button.btn type="submit"
|
11
|
-
span Send!
|
12
|
-
|
13
|
-
javascript:
|
14
|
-
var roomId = #{{ @room_id }};
|
15
|
-
var user = "#{{ @user }}";
|
16
|
-
var socketId = Date.now();
|
17
|
-
|
18
|
-
var messageList = document.getElementById("message_list");
|
19
|
-
var messageForm = document.getElementById("message_form");
|
20
|
-
var textInput = document.getElementById("message_txt");
|
21
|
-
|
22
|
-
messageForm.onsubmit = function(e){
|
23
|
-
e.preventDefault();
|
24
|
-
var msg = textInput.value;
|
25
|
-
console.log("Send message", msg);
|
26
|
-
textInput.value = null;
|
27
|
-
chatChannel.perform('speak', { message: msg });
|
28
|
-
};
|
29
|
-
|
30
|
-
var escape = function(str) {
|
31
|
-
return ('' + str).replace(/&/g, '&')
|
32
|
-
.replace(/</g, '<')
|
33
|
-
.replace(/>/g, '>')
|
34
|
-
.replace(/"/g, '"');
|
35
|
-
}
|
36
|
-
|
37
|
-
var addMessage = function(data){
|
38
|
-
var node = document.createElement('div');
|
39
|
-
var me = data['user'] == user && data['sid'] == socketId
|
40
|
-
node.className = "message" + (me ? ' me' : '') + (data['system'] ? ' system' : '');
|
41
|
-
node.innerHTML =
|
42
|
-
'<div class="author">' + escape(data['user']) + '</div>' +
|
43
|
-
'<div class="txt">' + escape(data['message']) + '</div>';
|
44
|
-
messageList.appendChild(node);
|
45
|
-
};
|
46
|
-
|
47
|
-
ActionCable.startDebugging();
|
48
|
-
var cable = ActionCable.createConsumer('#{{ CABLE_URL }}?sid=' + socketId);
|
49
|
-
|
50
|
-
var chatChannel = cable.subscriptions.create(
|
51
|
-
{ channel: 'chat', id: roomId },
|
52
|
-
{
|
53
|
-
connected: function(){
|
54
|
-
console.log("Connected");
|
55
|
-
addMessage({ user: 'BOT', message: "I'm connected", system: true });
|
56
|
-
},
|
57
|
-
|
58
|
-
disconnected: function(){
|
59
|
-
console.log("Connected");
|
60
|
-
addMessage({ user: 'BOT', message: "Sorry, but you've been disconnected(", system: true });
|
61
|
-
},
|
62
|
-
|
63
|
-
received: function(data){
|
64
|
-
console.log("Received", data);
|
65
|
-
addMessage(data);
|
66
|
-
}
|
67
|
-
}
|
68
|
-
)
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# Add missing protocols support to websocket-ruby
|
3
|
-
module WebSocketExt
|
4
|
-
module Protocols # :nodoc:
|
5
|
-
module Handshake # :nodoc:
|
6
|
-
# Specify server protocols
|
7
|
-
def protocols(values)
|
8
|
-
@protocols = values
|
9
|
-
end
|
10
|
-
|
11
|
-
# Return matching protocol
|
12
|
-
def protocol
|
13
|
-
return @protocol if instance_variable_defined?(:@protocol)
|
14
|
-
protos = @headers['sec-websocket-protocol']
|
15
|
-
|
16
|
-
return @protocol = nil unless protos
|
17
|
-
@protocol = begin
|
18
|
-
protos = protos.split(/ *, */) if protos.is_a?(String)
|
19
|
-
protos.find { |p| @protocols.include?(p) }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module Handler # :nodoc:
|
25
|
-
def handshake_keys
|
26
|
-
return super unless @handshake.protocol
|
27
|
-
super + [
|
28
|
-
[
|
29
|
-
'Sec-WebSocket-Protocol',
|
30
|
-
@handshake.protocol
|
31
|
-
]
|
32
|
-
]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
WebSocket::Handshake::Server.include WebSocketExt::Protocols::Handshake
|
39
|
-
[
|
40
|
-
WebSocket::Handshake::Handler::Server04,
|
41
|
-
WebSocket::Handshake::Handler::Server75,
|
42
|
-
WebSocket::Handshake::Handler::Server76
|
43
|
-
].each do |handler|
|
44
|
-
handler.prepend WebSocketExt::Protocols::Handler
|
45
|
-
end
|
data/litecable.gemspec
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'lite_cable/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "litecable"
|
8
|
-
spec.version = LiteCable::VERSION
|
9
|
-
spec.authors = ["palkan"]
|
10
|
-
spec.email = ["dementiev.vm@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{Fat-free ActionCable implementation}
|
13
|
-
spec.description = %q{Fat-free ActionCable implementation for using with AnyCable (and without Rails)}
|
14
|
-
spec.homepage = "https://github.com/anycable/litecable"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.require_paths = ["lib"]
|
19
|
-
|
20
|
-
spec.add_dependency "anyway_config", "~>0.5.0"
|
21
|
-
|
22
|
-
spec.add_development_dependency "rack", "~> 2.0"
|
23
|
-
spec.add_development_dependency "websocket", "~> 1.2.0"
|
24
|
-
spec.add_development_dependency "websocket-client-simple", "~> 0.3.0"
|
25
|
-
spec.add_development_dependency "concurrent-ruby", "~> 1.0.0"
|
26
|
-
spec.add_development_dependency "puma", "~> 3.6.0"
|
27
|
-
|
28
|
-
spec.add_development_dependency "bundler", "~> 1.13"
|
29
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
-
spec.add_development_dependency "simplecov", ">= 0.3.8"
|
32
|
-
spec.add_development_dependency "pry-byebug"
|
33
|
-
end
|