Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
26bcf81a
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
26bcf81a
编写于
12月 16, 2015
作者:
D
David Heinemeier Hansson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move Cable to ActionCable for client-side constant to avoid conflicts
上级
346a7528
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
49 addition
and
18 deletion
+49
-18
actioncable/lib/assets/javascripts/action_cable.coffee.erb
actioncable/lib/assets/javascripts/action_cable.coffee.erb
+3
-3
actioncable/lib/assets/javascripts/action_cable/connection.coffee
...ble/lib/assets/javascripts/action_cable/connection.coffee
+2
-2
actioncable/lib/assets/javascripts/action_cable/connection_monitor.coffee
...assets/javascripts/action_cable/connection_monitor.coffee
+2
-2
actioncable/lib/assets/javascripts/action_cable/consumer.coffee
...cable/lib/assets/javascripts/action_cable/consumer.coffee
+31
-0
actioncable/lib/assets/javascripts/action_cable/subscription.coffee
...e/lib/assets/javascripts/action_cable/subscription.coffee
+3
-3
actioncable/lib/assets/javascripts/action_cable/subscriptions.coffee
.../lib/assets/javascripts/action_cable/subscriptions.coffee
+6
-6
actioncable/lib/rails/generators/channel/templates/assets/consumer.coffee
...rails/generators/channel/templates/assets/consumer.coffee
+2
-2
未找到文件。
actioncable/lib/assets/javascripts/cable.coffee.erb
→
actioncable/lib/assets/javascripts/
action_
cable.coffee.erb
浏览文件 @
26bcf81a
#= require_self
#= require cable/consumer
#= require
action_
cable/consumer
@Cable =
@
Action
Cable =
INTERNAL:
<%=
ActionCable
::
INTERNAL
.
to_json
%>
createConsumer: (url = @getConfig("url")) ->
new Cable.Consumer @createWebSocketURL(url)
new
Action
Cable.Consumer @createWebSocketURL(url)
getConfig: (name) ->
element = document.head.querySelector("meta[name='action-cable-#{name}']")
...
...
actioncable/lib/assets/javascripts/cable/connection.coffee
→
actioncable/lib/assets/javascripts/
action_
cable/connection.coffee
浏览文件 @
26bcf81a
# Encapsulate the cable connection held by the consumer. This is an internal class not intended for direct user manipulation.
{
message_types
}
=
Cable
.
INTERNAL
{
message_types
}
=
Action
Cable
.
INTERNAL
class
Cable
.
Connection
class
Action
Cable
.
Connection
@
reopenDelay
:
500
constructor
:
(
@
consumer
)
->
...
...
actioncable/lib/assets/javascripts/cable/connection_monitor.coffee
→
actioncable/lib/assets/javascripts/
action_
cable/connection_monitor.coffee
浏览文件 @
26bcf81a
# Responsible for ensuring the cable connection is in good health by validating the heartbeat pings sent from the server, and attempting
# revival reconnections if things go astray. Internal class, not intended for direct user manipulation.
class
Cable
.
ConnectionMonitor
class
Action
Cable
.
ConnectionMonitor
@
pollInterval
:
min
:
3
max
:
30
@
staleThreshold
:
6
# Server::Connections::BEAT_INTERVAL * 2 (missed two pings)
identifier
:
Cable
.
INTERNAL
.
identifiers
.
ping
identifier
:
Action
Cable
.
INTERNAL
.
identifiers
.
ping
constructor
:
(
@
consumer
)
->
@
consumer
.
subscriptions
.
add
(
this
)
...
...
actioncable/lib/assets/javascripts/cable/consumer.coffee
→
actioncable/lib/assets/javascripts/
action_
cable/consumer.coffee
浏览文件 @
26bcf81a
#= require cable/connection
#= require cable/connection_monitor
#= require cable/subscriptions
#= require cable/subscription
#= require
action_
cable/connection
#= require
action_
cable/connection_monitor
#= require
action_
cable/subscriptions
#= require
action_
cable/subscription
# The Cable.Consumer establishes the connection to a server-side Ruby Connection object. Once established,
# the Cable.ConnectionMonitor will ensure that its properly maintained through heartbeats and checking for stale updates.
# The
Action
Cable.Consumer establishes the connection to a server-side Ruby Connection object. Once established,
# the
Action
Cable.ConnectionMonitor will ensure that its properly maintained through heartbeats and checking for stale updates.
# The Consumer instance is also the gateway to establishing subscriptions to desired channels through the #createSubscription
# method.
#
# The following example shows how this can be setup:
#
# @App = {}
# App.cable = Cable.createConsumer "ws://example.com/accounts/1"
# App.cable =
Action
Cable.createConsumer "ws://example.com/accounts/1"
# App.appearance = App.cable.subscriptions.create "AppearanceChannel"
#
# For more details on how you'd configure an actual channel subscription, see Cable.Subscription.
class
Cable
.
Consumer
# For more details on how you'd configure an actual channel subscription, see
Action
Cable.Subscription.
class
Action
Cable
.
Consumer
constructor
:
(
@
url
)
->
@
subscriptions
=
new
Cable
.
Subscriptions
this
@
connection
=
new
Cable
.
Connection
this
@
connectionMonitor
=
new
Cable
.
ConnectionMonitor
this
@
subscriptions
=
new
Action
Cable
.
Subscriptions
this
@
connection
=
new
Action
Cable
.
Connection
this
@
connectionMonitor
=
new
Action
Cable
.
ConnectionMonitor
this
send
:
(
data
)
->
@
connection
.
send
(
data
)
...
...
actioncable/lib/assets/javascripts/cable/subscription.coffee
→
actioncable/lib/assets/javascripts/
action_
cable/subscription.coffee
浏览文件 @
26bcf81a
# A new subscription is created through the Cable.Subscriptions instance available on the consumer.
# A new subscription is created through the
Action
Cable.Subscriptions instance available on the consumer.
# It provides a number of callbacks and a method for calling remote procedure calls on the corresponding
# Channel instance on the server side.
#
...
...
@@ -23,7 +23,7 @@
#
# This is how the server component would look:
#
# class AppearanceChannel < ApplicationCable::Channel
# class AppearanceChannel < Application
Action
Cable::Channel
# def subscribed
# current_user.appear
# end
...
...
@@ -43,7 +43,7 @@
#
# The "AppearanceChannel" name is automatically mapped between the client-side subscription creation and the server-side Ruby class name.
# The AppearanceChannel#appear/away public methods are exposed automatically to client-side invocation through the @perform method.
class
Cable
.
Subscription
class
Action
Cable
.
Subscription
constructor
:
(
@
subscriptions
,
params
=
{},
mixin
)
->
@
identifier
=
JSON
.
stringify
(
params
)
extend
(
this
,
mixin
)
...
...
actioncable/lib/assets/javascripts/cable/subscriptions.coffee
→
actioncable/lib/assets/javascripts/
action_
cable/subscriptions.coffee
浏览文件 @
26bcf81a
# Collection class for creating (and internally managing) channel subscriptions. The only method intended to be triggered by the user
# us Cable.Subscriptions#create, and it should be called through the consumer like so:
# us
Action
Cable.Subscriptions#create, and it should be called through the consumer like so:
#
# @App = {}
# App.cable = Cable.createConsumer "ws://example.com/accounts/1"
# App.cable =
Action
Cable.createConsumer "ws://example.com/accounts/1"
# App.appearance = App.cable.subscriptions.create "AppearanceChannel"
#
# For more details on how you'd configure an actual channel subscription, see Cable.Subscription.
class
Cable
.
Subscriptions
# For more details on how you'd configure an actual channel subscription, see
Action
Cable.Subscription.
class
Action
Cable
.
Subscriptions
constructor
:
(
@
consumer
)
->
@
subscriptions
=
[]
@
history
=
[]
...
...
@@ -14,7 +14,7 @@ class Cable.Subscriptions
create
:
(
channelName
,
mixin
)
->
channel
=
channelName
params
=
if
typeof
channel
is
"object"
then
channel
else
{
channel
}
new
Cable
.
Subscription
this
,
params
,
mixin
new
Action
Cable
.
Subscription
this
,
params
,
mixin
# Private
...
...
@@ -63,7 +63,7 @@ class Cable.Subscriptions
sendCommand
:
(
subscription
,
command
)
->
{
identifier
}
=
subscription
if
identifier
is
Cable
.
INTERNAL
.
identifiers
.
ping
if
identifier
is
Action
Cable
.
INTERNAL
.
identifiers
.
ping
@
consumer
.
connection
.
isOpen
()
else
@
consumer
.
send
({
command
,
identifier
})
...
...
actioncable/lib/rails/generators/channel/templates/assets/consumer.coffee
浏览文件 @
26bcf81a
#= require cable
#= require
action_
cable
#= require_self
#= require ./channels
@
App
=
{}
App
.
cable
=
Cable
.
createConsumer
()
App
.
cable
=
Action
Cable
.
createConsumer
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录