Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
96e6de95
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,发现更多精彩内容 >>
提交
96e6de95
编写于
3月 03, 2016
作者:
J
Javan Makhmali
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Defer starting connection monitor until a connection is opened
上级
8e9a1a62
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
41 deletion
+52
-41
actioncable/app/assets/javascripts/action_cable/connection.coffee
...ble/app/assets/javascripts/action_cable/connection.coffee
+7
-3
actioncable/app/assets/javascripts/action_cable/connection_monitor.coffee
...assets/javascripts/action_cable/connection_monitor.coffee
+45
-36
actioncable/app/assets/javascripts/action_cable/consumer.coffee
...cable/app/assets/javascripts/action_cable/consumer.coffee
+0
-2
未找到文件。
actioncable/app/assets/javascripts/action_cable/connection.coffee
浏览文件 @
96e6de95
#= require ./connection_monitor
# Encapsulate the cable connection held by the consumer. This is an internal class not intended for direct user manipulation.
{
message_types
}
=
ActionCable
.
INTERNAL
...
...
@@ -6,6 +8,7 @@ class ActionCable.Connection
@
reopenDelay
:
500
constructor
:
(
@
consumer
)
->
@
monitor
=
new
ActionCable
.
ConnectionMonitor
this
send
:
(
data
)
->
if
@
isOpen
()
...
...
@@ -23,6 +26,7 @@ class ActionCable.Connection
@
uninstallEventHandlers
()
if
@
webSocket
?
@
webSocket
=
new
WebSocket
(
@
consumer
.
url
)
@
installEventHandlers
()
@
monitor
.
start
()
true
close
:
->
...
...
@@ -72,9 +76,9 @@ class ActionCable.Connection
{
identifier
,
message
,
type
}
=
JSON
.
parse
(
event
.
data
)
switch
type
when
message_types
.
welcome
@
consumer
.
connectionMonitor
.
connected
()
@
monitor
.
recordConnect
()
when
message_types
.
ping
@
consumer
.
connectionMonitor
.
p
ing
()
@
monitor
.
recordP
ing
()
when
message_types
.
confirmation
@
consumer
.
subscriptions
.
notify
(
identifier
,
"connected"
)
when
message_types
.
rejection
...
...
@@ -98,5 +102,5 @@ class ActionCable.Connection
disconnect
:
->
return
if
@
disconnected
@
disconnected
=
true
@
consumer
.
connectionMonitor
.
disconnected
()
@
consumer
.
subscriptions
.
notifyAll
(
"disconnected"
)
@
monitor
.
recordDisconnect
()
actioncable/app/assets/javascripts/action_cable/connection_monitor.coffee
浏览文件 @
96e6de95
...
...
@@ -7,60 +7,69 @@ class ActionCable.ConnectionMonitor
@
staleThreshold
:
6
# Server::Connections::BEAT_INTERVAL * 2 (missed two pings)
constructor
:
(
@
con
sumer
)
->
@
start
()
constructor
:
(
@
con
nection
)
->
@
reconnectAttempts
=
0
connected
:
->
@
reset
()
@
pingedAt
=
now
()
delete
@
disconnectedAt
ActionCable
.
log
(
"ConnectionMonitor connected"
)
start
:
->
unless
@
isRunning
()
@
startedAt
=
now
()
delete
@
stoppedAt
@
startPolling
()
document
.
addEventListener
(
"visibilitychange"
,
@
visibilityDidChange
)
ActionCable
.
log
(
"ConnectionMonitor started. pollInterval =
#{
@
getPollInterval
()
}
ms"
)
disconnected
:
->
@
disconnectedAt
=
now
()
ActionCable
.
log
(
"ConnectionMonitor disconnected"
)
stop
:
->
if
@
isRunning
()
@
stoppedAt
=
now
()
@
stopPolling
()
document
.
removeEventListener
(
"visibilitychange"
,
@
visibilityDidChange
)
ActionCable
.
log
(
"ConnectionMonitor stopped"
)
isRunning
:
->
@
startedAt
?
and
not
@
stoppedAt
?
p
ing
:
->
recordP
ing
:
->
@
pingedAt
=
now
()
re
se
t
:
->
re
cordConnec
t
:
->
@
reconnectAttempts
=
0
@
consumer
.
connection
.
isOpen
()
@
recordPing
()
delete
@
disconnectedAt
ActionCable
.
log
(
"ConnectionMonitor recorded connect"
)
start
:
->
@
reset
()
delete
@
stoppedAt
@
startedAt
=
now
()
recordDisconnect
:
->
@
disconnectedAt
=
now
()
ActionCable
.
log
(
"ConnectionMonitor recorded disconnect"
)
# Private
startPolling
:
->
@
stopPolling
()
@
poll
()
document
.
addEventListener
(
"visibilitychange"
,
@
visibilityDidChange
)
ActionCable
.
log
(
"ConnectionMonitor started, pollInterval is
#{
@
getInterval
()
}
ms"
)
stop
:
->
@
stoppedAt
=
now
()
document
.
removeEventListener
(
"visibilitychange"
,
@
visibilityDidChange
)
ActionCable
.
log
(
"ConnectionMonitor stopped"
)
stopPolling
:
->
clearTimeout
(
@
pollTimeout
)
poll
:
->
setTimeout
=>
unless
@
stoppedAt
@
reconnectIfStale
()
@
poll
()
,
@
getInterval
()
@
pollTimeout
=
setTimeout
=>
@
reconnectIfStale
()
@
poll
()
,
@
getPollInterval
()
getInterval
:
->
get
Poll
Interval
:
->
{
min
,
max
}
=
@
constructor
.
pollInterval
interval
=
5
*
Math
.
log
(
@
reconnectAttempts
+
1
)
clamp
(
interval
,
min
,
max
)
*
1000
Math
.
round
(
clamp
(
interval
,
min
,
max
)
*
1000
)
reconnectIfStale
:
->
if
@
connectionIsStale
()
ActionCable
.
log
(
"ConnectionMonitor detected stale connection
, reconnectAttempts =
#{
@
reconnectAttempts
}
"
)
ActionCable
.
log
(
"ConnectionMonitor detected stale connection
. reconnectAttempts =
#{
@
reconnectAttempts
}
, pollInterval =
#{
@
getPollInterval
()
}
ms, time disconnected =
#{
secondsSince
(
@
disconnectedAt
)
}
s, stale threshold =
#{
@
constructor
.
staleThreshold
}
s
"
)
@
reconnectAttempts
++
if
@
disconnectedRecently
()
ActionCable
.
log
(
"ConnectionMonitor skipping reopen
because recently disconnected at
#{
@
disconnectedAt
}
"
)
ActionCable
.
log
(
"ConnectionMonitor skipping reopen
ing recent disconnect
"
)
else
ActionCable
.
log
(
"ConnectionMonitor reopening"
)
@
con
sumer
.
con
nection
.
reopen
()
@
connection
.
reopen
()
connectionIsStale
:
->
secondsSince
(
@
pingedAt
?
@
startedAt
)
>
@
constructor
.
staleThreshold
...
...
@@ -71,9 +80,9 @@ class ActionCable.ConnectionMonitor
visibilityDidChange
:
=>
if
document
.
visibilityState
is
"visible"
setTimeout
=>
if
@
connectionIsStale
()
or
not
@
con
sumer
.
con
nection
.
isOpen
()
ActionCable
.
log
(
"ConnectionMonitor reopening stale connection
after visibilitychange to
#{
document
.
visibilityState
}
"
)
@
con
sumer
.
con
nection
.
reopen
()
if
@
connectionIsStale
()
or
not
@
connection
.
isOpen
()
ActionCable
.
log
(
"ConnectionMonitor reopening stale connection
on visibilitychange. visbilityState =
#{
document
.
visibilityState
}
"
)
@
connection
.
reopen
()
,
200
now
=
->
...
...
actioncable/app/assets/javascripts/action_cable/consumer.coffee
浏览文件 @
96e6de95
#= require ./connection
#= require ./connection_monitor
#= require ./subscriptions
#= require ./subscription
...
...
@@ -19,7 +18,6 @@ class ActionCable.Consumer
constructor
:
(
@
url
)
->
@
subscriptions
=
new
ActionCable
.
Subscriptions
this
@
connection
=
new
ActionCable
.
Connection
this
@
connectionMonitor
=
new
ActionCable
.
ConnectionMonitor
this
send
:
(
data
)
->
@
connection
.
send
(
data
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录