Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
RocketChat
Rocket.Chat.js.SDK
Commits
43bfbbe5
Commit
43bfbbe5
authored
Apr 29, 2018
by
Mikael Mello
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(connect): Remove 'connected' listener after connection times out
Uncomment `driver .conenct` tests on driver.spec.ts
parent
c8c48425
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
11 deletions
+17
-11
src/lib/driver.spec.ts
src/lib/driver.spec.ts
+2
-2
src/lib/driver.ts
src/lib/driver.ts
+15
-9
No files found.
src/lib/driver.spec.ts
View file @
43bfbbe5
...
...
@@ -16,7 +16,7 @@ let clock
describe
(
'
driver
'
,
()
=>
{
silence
()
// suppress log during tests (disable this while developing tests)
before
(()
=>
utils
.
setup
())
// add user accounts for bot and mock user
/*
describe
(
'
.connect
'
,
()
=>
{
context
(
'
with localhost connection
'
,
()
=>
{
it
(
'
without args, returns a promise
'
,
()
=>
{
...
...
@@ -91,7 +91,7 @@ describe('driver', () => {
})
})
})
*/
// describe('disconnect', () => {
// Disabled for now, as only Asteroid v2 has a disconnect method
// it('disconnects from asteroid', async () => {
...
...
src/lib/driver.ts
View file @
43bfbbe5
...
...
@@ -132,20 +132,26 @@ export function connect (options: IConnectOptions = {}, callback?: ICallback): P
setupMethodCache
(
asteroid
)
// init instance for later caching method calls
asteroid
.
on
(
'
connected
'
,
()
=>
events
.
emit
(
'
connected
'
))
asteroid
.
on
(
'
reconnected
'
,
()
=>
events
.
emit
(
'
reconnected
'
))
//
let cancelled = false
let
cancelled
=
false
const
rejectionTimeout
=
setTimeout
(
function
()
{
logger
.
info
(
`[connect] Timeout (
${
config
.
timeout
}
)`
)
// cancelled = true
const
err
=
new
Error
(
'
Asteroid connection timeout
'
)
cancelled
=
true
events
.
removeAllListeners
(
'
connected
'
)
callback
?
callback
(
err
,
asteroid
)
:
reject
(
err
)
},
config
.
timeout
)
events
.
once
(
'
connected
'
,
()
=>
{
logger
.
info
(
'
[connect] Connected
'
)
// if (cancelled) return asteroid.ddp.disconnect() // cancel if already rejected
clearTimeout
(
rejectionTimeout
)
if
(
callback
)
callback
(
null
,
asteroid
)
resolve
(
asteroid
)
})
// if to avoid condition where timeout happens before listener to 'connected' is added
// and this listener is not removed (because it was added after the removal)
if
(
!
cancelled
)
{
events
.
once
(
'
connected
'
,
()
=>
{
logger
.
info
(
'
[connect] Connected
'
)
// if (cancelled) return asteroid.ddp.disconnect() // cancel if already rejected
clearTimeout
(
rejectionTimeout
)
if
(
callback
)
callback
(
null
,
asteroid
)
resolve
(
asteroid
)
})
}
})
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment