opal-actioncable 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/opal-actioncable/version.rb +1 -1
- data/opal/action_cable/connection.rb +17 -8
- data/opal/action_cable/connection_monitor.rb +18 -2
- data/opal/action_cable/consumer.rb +22 -9
- data/opal/action_cable/subscription.rb +22 -5
- data/opal/action_cable/subscriptions.rb +19 -8
- data/opal/opal-actioncable.rb +30 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f02264089fcb2f605f6176051ea09646300edbd7
|
4
|
+
data.tar.gz: 2770dae1cf768542bf677e1f8c98ed7aafc90c52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e011c93239a69cedbb18c5a6e499f5f490955f1c2de3ae600518445819235d5edea921d3f308fe90b0be8ce4ed4bf6b998b3e7ad6467bd2db4ae0b274c13ae3
|
7
|
+
data.tar.gz: c703b84afe5ac401f9e5caebaf6e3ed9b2b9fb8a89b96368c3dd8b20f008709f46ee983733e9c40e31e14c4dc8c11478edc7ee2ee5b25c7c36c9282bea48c139
|
data/README.md
CHANGED
@@ -4,14 +4,18 @@ class ActionCable::Connection
|
|
4
4
|
def initialize consumer
|
5
5
|
@native = `new ActionCable.Connection(#{consumer})`
|
6
6
|
%x{
|
7
|
-
Opal.defn(self.$class(), '
|
8
|
-
Opal.defn(self.$class(), '
|
9
|
-
Opal.defn(self.$class(), '
|
10
|
-
Opal.defn(self.$class(), '
|
11
|
-
Opal.defn(self.$class(), '
|
12
|
-
Opal.defn(self.$class(), '
|
13
|
-
Opal.defn(self.$class(), '
|
14
|
-
Opal.defn(self.$class(), '
|
7
|
+
Opal.defn(self.$class(), 'send', function(){ return self.$delegate_native('send', arguments); });
|
8
|
+
Opal.defn(self.$class(), 'open', function(){ return self.$delegate_native('open', arguments); });
|
9
|
+
Opal.defn(self.$class(), 'close', function(){ return self.$delegate_native('close', arguments); });
|
10
|
+
Opal.defn(self.$class(), 'reopen', function(){ return self.$delegate_native('reopen', arguments); });
|
11
|
+
Opal.defn(self.$class(), 'getProtocol', function(){ return self.$delegate_native('getProtocol', arguments); });
|
12
|
+
Opal.defn(self.$class(), 'isOpen', function(){ return self.$delegate_native('isOpen', arguments); });
|
13
|
+
Opal.defn(self.$class(), 'isActive', function(){ return self.$delegate_native('isActive', arguments); });
|
14
|
+
Opal.defn(self.$class(), 'isProtocolSupported', function(){ return self.$delegate_native('isProtocolSupported', arguments); });
|
15
|
+
Opal.defn(self.$class(), 'isState', function(){ return self.$delegate_native('isState', arguments); });
|
16
|
+
Opal.defn(self.$class(), 'getState', function(){ return self.$delegate_native('getState', arguments); });
|
17
|
+
Opal.defn(self.$class(), 'installEventHandlers', function(){ return self.$delegate_native('installEventHandlers', arguments); });
|
18
|
+
Opal.defn(self.$class(), 'uninstallEventHandlers', function(){ return self.$delegate_native('uninstallEventHandlers', arguments); });
|
15
19
|
}
|
16
20
|
end
|
17
21
|
|
@@ -19,4 +23,9 @@ class ActionCable::Connection
|
|
19
23
|
`#{@native}.send(#{data})`
|
20
24
|
end
|
21
25
|
|
26
|
+
def delegate_native name, args
|
27
|
+
`#{@native}[#{name}].apply(#{@native}, args)`
|
28
|
+
end
|
29
|
+
|
30
|
+
|
22
31
|
end
|
@@ -1,7 +1,23 @@
|
|
1
1
|
class ActionCable::ConnectionMonitor
|
2
2
|
include Native::Helpers
|
3
3
|
|
4
|
-
def initialize
|
5
|
-
@native = `new ActionCable.ConnectionMonitor(#{
|
4
|
+
def initialize connection
|
5
|
+
@native = `new ActionCable.ConnectionMonitor(#{connection})`
|
6
|
+
%x{
|
7
|
+
Opal.defn(self.$class(), "visibilityDidChange", #{@native}.visibilityDidChange );
|
8
|
+
Opal.defn(self.$class(), "disconnectedRecently", #{@native}.disconnectedRecently );
|
9
|
+
Opal.defn(self.$class(), "connectionIsStale", #{@native}.connectionIsStale );
|
10
|
+
Opal.defn(self.$class(), "reconnectIfStale", #{@native}.reconnectIfStale );
|
11
|
+
Opal.defn(self.$class(), "getPollInterval", #{@native}.getPollInterval );
|
12
|
+
Opal.defn(self.$class(), "poll", #{@native}.poll );
|
13
|
+
Opal.defn(self.$class(), "stopPolling", #{@native}.stopPolling );
|
14
|
+
Opal.defn(self.$class(), "startPolling", #{@native}.startPolling);
|
15
|
+
Opal.defn(self.$class(), "recordDisconnect", #{@native}.recordDisconnect );
|
16
|
+
Opal.defn(self.$class(), "recordConnect", #{@native}.recordConnect );
|
17
|
+
Opal.defn(self.$class(), "recordPing", #{@native}.recordPing );
|
18
|
+
Opal.defn(self.$class(), "isRunning", #{@native}.isRunning );
|
19
|
+
Opal.defn(self.$class(), "stop", #{@native}.stop );
|
20
|
+
Opal.defn(self.$class(), "start", #{@native}.start );
|
21
|
+
}
|
6
22
|
end
|
7
23
|
end
|
@@ -1,18 +1,31 @@
|
|
1
|
-
class ActionCable::
|
1
|
+
class ActionCable::Connection
|
2
2
|
include Native::Helpers
|
3
|
-
attr_reader :subscriptions, :connection, :connectionMonitor
|
4
3
|
|
5
|
-
def initialize
|
6
|
-
@
|
7
|
-
@subscriptions = ActionCable::Subscriptions.new self
|
8
|
-
@connection = ActionCable::Connection.new self
|
9
|
-
@connectionMonitor = ActionCable::ConnectionMonitor.new self
|
4
|
+
def initialize consumer
|
5
|
+
@native = `new ActionCable.Connection(#{consumer})`
|
10
6
|
%x{
|
11
|
-
|
7
|
+
Opal.defn(self.$class(), 'send', function(){ return self.$delegate_native('send', arguments); });
|
8
|
+
Opal.defn(self.$class(), 'open', function(){ return self.$delegate_native('open', arguments); });
|
9
|
+
Opal.defn(self.$class(), 'close', function(){ return self.$delegate_native('close', arguments); });
|
10
|
+
Opal.defn(self.$class(), 'reopen', function(){ return self.$delegate_native('reopen', arguments); });
|
11
|
+
Opal.defn(self.$class(), 'getProtocol', function(){ return self.$delegate_native('getProtocol', arguments); });
|
12
|
+
Opal.defn(self.$class(), 'isOpen', function(){ return self.$delegate_native('isOpen', arguments); });
|
13
|
+
Opal.defn(self.$class(), 'isActive', function(){ return self.$delegate_native('isActive', arguments); });
|
14
|
+
Opal.defn(self.$class(), 'isProtocolSupported', function(){ return self.$delegate_native('isProtocolSupported', arguments); });
|
15
|
+
Opal.defn(self.$class(), 'isState', function(){ return self.$delegate_native('isState', arguments); });
|
16
|
+
Opal.defn(self.$class(), 'getState', function(){ return self.$delegate_native('getState', arguments); });
|
17
|
+
Opal.defn(self.$class(), 'installEventHandlers', function(){ return self.$delegate_native('installEventHandlers', arguments); });
|
18
|
+
Opal.defn(self.$class(), 'uninstallEventHandlers', function(){ return self.$delegate_native('uninstallEventHandlers', arguments); });
|
12
19
|
}
|
13
20
|
end
|
14
21
|
|
15
22
|
def send data
|
16
|
-
@
|
23
|
+
`#{@native}.send(#{data})`
|
17
24
|
end
|
25
|
+
|
26
|
+
def delegate_native name, args
|
27
|
+
`#{@native}[#{name}].apply(#{@native}, args)`
|
28
|
+
end
|
29
|
+
|
30
|
+
|
18
31
|
end
|
@@ -1,9 +1,19 @@
|
|
1
1
|
class ActionCable::Subscription
|
2
2
|
include Native::Helpers
|
3
3
|
|
4
|
-
def initialize
|
5
|
-
@native = `new ActionCable.Subscription(#{
|
6
|
-
%x{
|
4
|
+
def initialize consumer, params
|
5
|
+
@native = `new ActionCable.Subscription(#{consumer}, #{params.to_n})`
|
6
|
+
%x{
|
7
|
+
Opal.defn(self.$class(), 'perform', #{self}.$perform)
|
8
|
+
if (#{respond_to?(:disconnected)}) Opal.defn(self.$class(), 'disconnected', #{self}.$disconnected)
|
9
|
+
if (#{respond_to?(:rejected)}) Opal.defn(self.$class(), 'rejected', #{self}.$rejected)
|
10
|
+
if (#{respond_to?(:received)}) Opal.defn(self.$class(), 'received', #{self}.$_received)
|
11
|
+
if (#{respond_to?(:connected)}) Opal.defn(self.$class(), 'connected', #{self}.$connected)
|
12
|
+
|
13
|
+
Opal.defn(self.$class(), 'send', #{@native}.send)
|
14
|
+
Opal.defn(self.$class(), 'unsubscribe', #{@native}.unsubscribe)
|
15
|
+
Opal.defn(self.$class(), 'identifier', #{@native}.identifier)
|
16
|
+
}
|
7
17
|
|
8
18
|
self.class.instance_methods(false).each do |method_name|
|
9
19
|
next if method_name == :perform
|
@@ -16,8 +26,15 @@ class ActionCable::Subscription
|
|
16
26
|
end
|
17
27
|
end
|
18
28
|
|
19
|
-
def perform action, data
|
20
|
-
|
29
|
+
def perform action, data={}
|
30
|
+
data ||= {}
|
31
|
+
data[:action] = action
|
32
|
+
`#{@native}.send(#{data.to_n})`
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def _received data
|
37
|
+
received Hash.new data
|
21
38
|
end
|
22
39
|
|
23
40
|
end
|
@@ -2,23 +2,34 @@ class ActionCable::Subscriptions
|
|
2
2
|
include Native::Helpers
|
3
3
|
|
4
4
|
def initialize consumer
|
5
|
+
@consumer = consumer
|
5
6
|
@native = `new ActionCable.Subscriptions(#{consumer})`
|
6
7
|
%x{
|
8
|
+
Opal.defn(self.$class(), 'create', #{@native}.create);
|
7
9
|
Opal.defn(self.$class(), 'add', #{@native}.add);
|
8
|
-
Opal.defn(self.$class(), '
|
9
|
-
Opal.defn(self.$class(), '
|
10
|
-
Opal.defn(self.$class(), '
|
10
|
+
Opal.defn(self.$class(), 'remove', #{@native}.remove);
|
11
|
+
Opal.defn(self.$class(), 'reject', #{@native}.reject);
|
12
|
+
Opal.defn(self.$class(), 'forget', #{@native}.forget);
|
11
13
|
Opal.defn(self.$class(), 'findAll', #{@native}.findAll);
|
14
|
+
Opal.defn(self.$class(), 'reload', #{@native}.reload);
|
15
|
+
Opal.defn(self.$class(), 'notifyAll', #{@native}.notifyAll);
|
16
|
+
Opal.defn(self.$class(), 'notify', #{@native}.notify);
|
12
17
|
Opal.defn(self.$class(), 'sendCommand', #{@native}.sendCommand);
|
13
|
-
|
14
|
-
Opal.defn(self.$class(), 'reject', #{@native}.reject);
|
18
|
+
|
15
19
|
self.subscriptions = #{@native}.subscriptions;
|
16
20
|
self.consumer = #{@native}.consumer;
|
17
21
|
}
|
18
22
|
end
|
19
23
|
|
20
|
-
def create
|
21
|
-
params
|
22
|
-
|
24
|
+
def create params
|
25
|
+
if params.is_a? Hash
|
26
|
+
mixin = params[:channel]
|
27
|
+
else
|
28
|
+
mixin = params
|
29
|
+
params = {channel: params.name}
|
30
|
+
end
|
31
|
+
subscription = mixin.new @consumer, params
|
32
|
+
`#{@native}.add(#{subscription})`
|
33
|
+
subscription
|
23
34
|
end
|
24
35
|
end
|
data/opal/opal-actioncable.rb
CHANGED
@@ -1,27 +1,54 @@
|
|
1
|
-
|
2
1
|
require 'action_cable'
|
3
2
|
|
4
3
|
class ActionCable
|
5
4
|
|
6
5
|
class << self
|
7
|
-
def create_consumer url
|
6
|
+
def create_consumer url=nil
|
7
|
+
start_debugging
|
8
|
+
`if (url === undefined){url = Opal.nil}`
|
9
|
+
url ||= get_config("url") || `ActionCable.INTERNAL.default_mount_path`
|
8
10
|
@@default_consumer ||= Consumer.new create_web_socket_url(url)
|
9
11
|
end
|
12
|
+
|
10
13
|
alias createConsumer create_consumer
|
11
14
|
|
12
15
|
def get_config name
|
13
|
-
`ActionCable.getConfig(#{name})`
|
16
|
+
val = `ActionCable.getConfig(#{name})`
|
17
|
+
`if (val === undefined){val = Opal.nil}`
|
18
|
+
val
|
14
19
|
end
|
20
|
+
|
15
21
|
alias getConfig get_config
|
16
22
|
|
17
23
|
def create_web_socket_url url
|
18
24
|
`ActionCable.createWebSocketURL(#{url})`
|
19
25
|
end
|
26
|
+
|
20
27
|
alias createWebSocketURL create_web_socket_url
|
21
28
|
|
22
29
|
def default_consumer
|
23
30
|
@@default_consumer
|
24
31
|
end
|
32
|
+
|
33
|
+
def start_debugging
|
34
|
+
@@debugging = true
|
35
|
+
end
|
36
|
+
|
37
|
+
alias startDebugging start_debugging
|
38
|
+
|
39
|
+
def stop_debugging
|
40
|
+
@@debugging = false
|
41
|
+
end
|
42
|
+
|
43
|
+
alias stopDebugging stop_debugging
|
44
|
+
|
45
|
+
def log *messages
|
46
|
+
if @@debugging
|
47
|
+
messages << `Date.now`
|
48
|
+
`console.log.apply(console, ["[ActionCable]"].concat(slice.call(messages)));`
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
25
52
|
end
|
26
53
|
end
|
27
54
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-actioncable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Añasco
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-05-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: opal
|