Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
0c61a5d7
Commit
0c61a5d7
authored
May 11, 2017
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: Refactor common code into `restoreBOSHSession`
parent
5dd3b93a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
30 deletions
+44
-30
spec/converse.js
spec/converse.js
+3
-1
src/converse-core.js
src/converse-core.js
+41
-29
No files found.
spec/converse.js
View file @
0c61a5d7
...
...
@@ -30,7 +30,9 @@
_converse
.
keepalive
=
true
;
_converse
.
authentication
=
"
prebind
"
;
expect
(
_converse
.
logIn
.
bind
(
_converse
)).
toThrow
(
new
Error
(
"
attemptPreboundSession: when using 'keepalive' with 'prebind, you must supply the JID of the current user.
"
));
new
Error
(
"
restoreBOSHSession: tried to restore a
\"
keepalive
\"
session
"
+
"
but we don't have the JID for the user!
"
));
_converse
.
authentication
=
authentication
;
_converse
.
jid
=
jid
;
_converse
.
keepalive
=
false
;
...
...
src/converse-core.js
View file @
0c61a5d7
...
...
@@ -1894,29 +1894,46 @@
xhr
.
send
();
};
this
.
restoreBOSHSession
=
function
()
{
/* Tries to restore a cached BOSH session. */
if
(
!
this
.
jid
)
{
throw
new
Error
(
"
restoreBOSHSession: tried to restore a
\"
keepalive
\"
session
"
+
"
but we don't have the JID for the user!
"
);
}
try
{
this
.
connection
.
restore
(
this
.
jid
,
this
.
onConnectStatusChanged
);
return
true
;
}
catch
(
e
)
{
this
.
log
(
"
Could not restore session for jid:
"
+
this
.
jid
+
"
Error message:
"
+
e
.
message
);
this
.
clearSession
();
// If there's a roster, we want to clear it (see #555)
return
false
;
}
};
this
.
attemptPreboundSession
=
function
(
reconnecting
)
{
/* Handle session resumption or initialization when prebind is being used.
/* Handle session resumption or initialization when prebind is
* being used.
*/
if
(
!
reconnecting
&&
this
.
keepalive
)
{
if
(
!
this
.
jid
)
{
throw
new
Error
(
"
attemptPreboundSession: when using 'keepalive' with 'prebind,
"
+
"
you must supply the JID of the current user.
"
);
if
(
!
reconnecting
)
{
if
(
this
.
keepalive
&&
this
.
restoreBOSHSession
())
{
return
;
}
try
{
return
this
.
connection
.
restore
(
this
.
jid
,
this
.
onConnectStatusChanged
);
}
catch
(
e
)
{
this
.
log
(
"
Could not restore session for jid:
"
+
this
.
jid
+
"
Error message:
"
+
e
.
message
);
this
.
clearSession
();
// If there's a roster, we want to clear it (see #555)
// No keepalive, or session resumption has failed.
if
(
this
.
jid
&&
this
.
sid
&&
this
.
rid
)
{
return
this
.
connection
.
attach
(
this
.
jid
,
this
.
sid
,
this
.
rid
,
this
.
onConnectStatusChanged
);
}
}
// No keepalive, or session resumption has failed.
if
(
!
reconnecting
&&
this
.
jid
&&
this
.
sid
&&
this
.
rid
)
{
return
this
.
connection
.
attach
(
this
.
jid
,
this
.
sid
,
this
.
rid
,
this
.
onConnectStatusChanged
);
}
else
if
(
this
.
prebind_url
)
{
if
(
this
.
prebind_url
)
{
return
this
.
startNewBOSHSession
();
}
else
{
throw
new
Error
(
"
attemptPreboundSession: If you use prebind and not keepalive,
"
+
throw
new
Error
(
"
attemptPreboundSession: If you use prebind and not keepalive,
"
+
"
then you MUST supply JID, RID and SID values or a prebind_url.
"
);
}
};
...
...
@@ -1966,13 +1983,8 @@
* 1. keepalive
* 2. auto_login
*/
if
(
this
.
keepalive
&&
!
reconnecting
)
{
try
{
return
this
.
connection
.
restore
(
this
.
jid
,
this
.
onConnectStatusChanged
);
}
catch
(
e
)
{
this
.
log
(
"
Could not restore session. Error message:
"
+
e
.
message
);
this
.
clearSession
();
// If there's a roster, we want to clear it (see #555)
}
if
(
!
reconnecting
&&
this
.
keepalive
&&
this
.
restoreBOSHSession
())
{
return
;
}
if
(
this
.
auto_login
)
{
if
(
credentials
)
{
...
...
@@ -1983,14 +1995,14 @@
this
.
fetchLoginCredentials
().
done
(
this
.
autoLogin
.
bind
(
this
));
}
else
if
(
!
this
.
jid
)
{
throw
new
Error
(
"
initConnection: If you use auto_login, you also need
"
+
"
to give either a jid value (and if applicable a
"
+
"
password) or you need to pass in a URL from where the
"
+
"
username and password can be fetched (via credentials_url).
"
"
attemptNonPreboundSession: If you use auto_login,
"
+
"
you also need to give either a jid value (and if
"
+
"
applicable a password) or you need to pass in a URL
"
+
"
from where the username and password can be fetched
"
+
"
(via credentials_url).
"
);
}
else
{
// Probably ANONYMOUS login
this
.
autoLogin
();
this
.
autoLogin
();
// Probably ANONYMOUS login
}
}
else
if
(
reconnecting
)
{
this
.
autoLogin
();
...
...
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