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
ab0521eb
Commit
ab0521eb
authored
Oct 09, 2020
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
smacks: move functions out of plugin's `initialize` method
parent
c9ba42d0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
222 additions
and
222 deletions
+222
-222
src/headless/converse-smacks.js
src/headless/converse-smacks.js
+222
-222
No files found.
src/headless/converse-smacks.js
View file @
ab0521eb
...
@@ -14,27 +14,14 @@ const u = converse.env.utils;
...
@@ -14,27 +14,14 @@ const u = converse.env.utils;
Strophe
.
addNamespace
(
'
SM
'
,
'
urn:xmpp:sm:3
'
);
Strophe
.
addNamespace
(
'
SM
'
,
'
urn:xmpp:sm:3
'
);
converse
.
plugins
.
add
(
'
converse-smacks
'
,
{
function
isStreamManagementSupported
()
{
initialize
()
{
// Configuration values for this plugin
// ====================================
// Refer to docs/source/configuration.rst for explanations of these
// configuration settings.
api
.
settings
.
extend
({
'
enable_smacks
'
:
true
,
'
smacks_max_unacked_stanzas
'
:
5
,
});
function
isStreamManagementSupported
()
{
if
(
api
.
connection
.
isType
(
'
bosh
'
)
&&
!
_converse
.
isTestEnv
())
{
if
(
api
.
connection
.
isType
(
'
bosh
'
)
&&
!
_converse
.
isTestEnv
())
{
return
false
;
return
false
;
}
}
return
api
.
disco
.
stream
.
getFeature
(
'
sm
'
,
Strophe
.
NS
.
SM
);
return
api
.
disco
.
stream
.
getFeature
(
'
sm
'
,
Strophe
.
NS
.
SM
);
}
}
function
handleAck
(
el
)
{
function
handleAck
(
el
)
{
if
(
!
_converse
.
session
.
get
(
'
smacks_enabled
'
))
{
if
(
!
_converse
.
session
.
get
(
'
smacks_enabled
'
))
{
return
true
;
return
true
;
}
}
...
@@ -62,18 +49,18 @@ converse.plugins.add('converse-smacks', {
...
@@ -62,18 +49,18 @@ converse.plugins.add('converse-smacks', {
'
unacked_stanzas
'
:
unacked_stanzas
.
slice
(
delta
)
'
unacked_stanzas
'
:
unacked_stanzas
.
slice
(
delta
)
});
});
return
true
;
return
true
;
}
}
function
sendAck
()
{
function
sendAck
()
{
if
(
_converse
.
session
.
get
(
'
smacks_enabled
'
))
{
if
(
_converse
.
session
.
get
(
'
smacks_enabled
'
))
{
const
h
=
_converse
.
session
.
get
(
'
num_stanzas_handled
'
);
const
h
=
_converse
.
session
.
get
(
'
num_stanzas_handled
'
);
const
stanza
=
u
.
toStanza
(
`<a xmlns="
${
Strophe
.
NS
.
SM
}
" h="
${
h
}
"/>`
);
const
stanza
=
u
.
toStanza
(
`<a xmlns="
${
Strophe
.
NS
.
SM
}
" h="
${
h
}
"/>`
);
api
.
send
(
stanza
);
api
.
send
(
stanza
);
}
}
return
true
;
return
true
;
}
}
function
stanzaHandler
(
el
)
{
function
stanzaHandler
(
el
)
{
if
(
_converse
.
session
.
get
(
'
smacks_enabled
'
))
{
if
(
_converse
.
session
.
get
(
'
smacks_enabled
'
))
{
if
(
u
.
isTagEqual
(
el
,
'
iq
'
)
||
u
.
isTagEqual
(
el
,
'
presence
'
)
||
u
.
isTagEqual
(
el
,
'
message
'
))
{
if
(
u
.
isTagEqual
(
el
,
'
iq
'
)
||
u
.
isTagEqual
(
el
,
'
presence
'
)
||
u
.
isTagEqual
(
el
,
'
message
'
))
{
const
h
=
_converse
.
session
.
get
(
'
num_stanzas_handled
'
);
const
h
=
_converse
.
session
.
get
(
'
num_stanzas_handled
'
);
...
@@ -81,9 +68,9 @@ converse.plugins.add('converse-smacks', {
...
@@ -81,9 +68,9 @@ converse.plugins.add('converse-smacks', {
}
}
}
}
return
true
;
return
true
;
}
}
function
initSessionData
()
{
function
initSessionData
()
{
_converse
.
session
.
save
({
_converse
.
session
.
save
({
'
smacks_enabled
'
:
_converse
.
session
.
get
(
'
smacks_enabled
'
)
||
false
,
'
smacks_enabled
'
:
_converse
.
session
.
get
(
'
smacks_enabled
'
)
||
false
,
'
num_stanzas_handled
'
:
_converse
.
session
.
get
(
'
num_stanzas_handled
'
)
||
0
,
'
num_stanzas_handled
'
:
_converse
.
session
.
get
(
'
num_stanzas_handled
'
)
||
0
,
...
@@ -91,9 +78,9 @@ converse.plugins.add('converse-smacks', {
...
@@ -91,9 +78,9 @@ converse.plugins.add('converse-smacks', {
'
num_stanzas_since_last_ack
'
:
_converse
.
session
.
get
(
'
num_stanzas_since_last_ack
'
)
||
0
,
'
num_stanzas_since_last_ack
'
:
_converse
.
session
.
get
(
'
num_stanzas_since_last_ack
'
)
||
0
,
'
unacked_stanzas
'
:
_converse
.
session
.
get
(
'
unacked_stanzas
'
)
||
[]
'
unacked_stanzas
'
:
_converse
.
session
.
get
(
'
unacked_stanzas
'
)
||
[]
});
});
}
}
function
resetSessionData
()
{
function
resetSessionData
()
{
_converse
.
session
&&
_converse
.
session
.
save
({
_converse
.
session
&&
_converse
.
session
.
save
({
'
smacks_enabled
'
:
false
,
'
smacks_enabled
'
:
false
,
'
num_stanzas_handled
'
:
0
,
'
num_stanzas_handled
'
:
0
,
...
@@ -101,18 +88,18 @@ converse.plugins.add('converse-smacks', {
...
@@ -101,18 +88,18 @@ converse.plugins.add('converse-smacks', {
'
num_stanzas_since_last_ack
'
:
0
,
'
num_stanzas_since_last_ack
'
:
0
,
'
unacked_stanzas
'
:
[]
'
unacked_stanzas
'
:
[]
});
});
}
}
function
saveSessionData
(
el
)
{
function
saveSessionData
(
el
)
{
const
data
=
{
'
smacks_enabled
'
:
true
};
const
data
=
{
'
smacks_enabled
'
:
true
};
if
([
'
1
'
,
'
true
'
].
includes
(
el
.
getAttribute
(
'
resume
'
)))
{
if
([
'
1
'
,
'
true
'
].
includes
(
el
.
getAttribute
(
'
resume
'
)))
{
data
[
'
smacks_stream_id
'
]
=
el
.
getAttribute
(
'
id
'
);
data
[
'
smacks_stream_id
'
]
=
el
.
getAttribute
(
'
id
'
);
}
}
_converse
.
session
.
save
(
data
);
_converse
.
session
.
save
(
data
);
return
true
;
return
true
;
}
}
function
onFailedStanza
(
el
)
{
function
onFailedStanza
(
el
)
{
if
(
el
.
querySelector
(
'
item-not-found
'
))
{
if
(
el
.
querySelector
(
'
item-not-found
'
))
{
// Stream resumption must happen before resource binding but
// Stream resumption must happen before resource binding but
// enabling a new stream must happen after resource binding.
// enabling a new stream must happen after resource binding.
...
@@ -133,9 +120,9 @@ converse.plugins.add('converse-smacks', {
...
@@ -133,9 +120,9 @@ converse.plugins.add('converse-smacks', {
*/
*/
api
.
trigger
(
'
streamResumptionFailed
'
);
api
.
trigger
(
'
streamResumptionFailed
'
);
return
true
;
return
true
;
}
}
function
resendUnackedStanzas
()
{
function
resendUnackedStanzas
()
{
const
stanzas
=
_converse
.
session
.
get
(
'
unacked_stanzas
'
);
const
stanzas
=
_converse
.
session
.
get
(
'
unacked_stanzas
'
);
// We clear the unacked_stanzas array because it'll get populated
// We clear the unacked_stanzas array because it'll get populated
// again in `onStanzaSent`
// again in `onStanzaSent`
...
@@ -158,9 +145,9 @@ converse.plugins.add('converse-smacks', {
...
@@ -158,9 +145,9 @@ converse.plugins.add('converse-smacks', {
// differently, more like push stanzas, so that they don't need
// differently, more like push stanzas, so that they don't need
// explicit handlers.
// explicit handlers.
stanzas
.
forEach
(
s
=>
api
.
send
(
s
));
stanzas
.
forEach
(
s
=>
api
.
send
(
s
));
}
}
function
onResumedStanza
(
el
)
{
function
onResumedStanza
(
el
)
{
saveSessionData
(
el
);
saveSessionData
(
el
);
handleAck
(
el
);
handleAck
(
el
);
resendUnackedStanzas
();
resendUnackedStanzas
();
...
@@ -168,9 +155,9 @@ converse.plugins.add('converse-smacks', {
...
@@ -168,9 +155,9 @@ converse.plugins.add('converse-smacks', {
_converse
.
connection
.
authenticated
=
true
;
_converse
.
connection
.
authenticated
=
true
;
_converse
.
connection
.
restored
=
true
;
_converse
.
connection
.
restored
=
true
;
_converse
.
connection
.
_changeConnectStatus
(
Strophe
.
Status
.
CONNECTED
,
null
);
_converse
.
connection
.
_changeConnectStatus
(
Strophe
.
Status
.
CONNECTED
,
null
);
}
}
async
function
sendResumeStanza
()
{
async
function
sendResumeStanza
()
{
const
promise
=
u
.
getResolveablePromise
();
const
promise
=
u
.
getResolveablePromise
();
_converse
.
connection
.
_addSysHandler
(
el
=>
promise
.
resolve
(
onResumedStanza
(
el
)),
Strophe
.
NS
.
SM
,
'
resumed
'
);
_converse
.
connection
.
_addSysHandler
(
el
=>
promise
.
resolve
(
onResumedStanza
(
el
)),
Strophe
.
NS
.
SM
,
'
resumed
'
);
_converse
.
connection
.
_addSysHandler
(
el
=>
promise
.
resolve
(
onFailedStanza
(
el
)),
Strophe
.
NS
.
SM
,
'
failed
'
);
_converse
.
connection
.
_addSysHandler
(
el
=>
promise
.
resolve
(
onFailedStanza
(
el
)),
Strophe
.
NS
.
SM
,
'
failed
'
);
...
@@ -181,9 +168,9 @@ converse.plugins.add('converse-smacks', {
...
@@ -181,9 +168,9 @@ converse.plugins.add('converse-smacks', {
api
.
send
(
stanza
);
api
.
send
(
stanza
);
_converse
.
connection
.
flush
();
_converse
.
connection
.
flush
();
await
promise
;
await
promise
;
}
}
async
function
sendEnableStanza
()
{
async
function
sendEnableStanza
()
{
if
(
!
api
.
settings
.
get
(
'
enable_smacks
'
)
||
_converse
.
session
.
get
(
'
smacks_enabled
'
))
{
if
(
!
api
.
settings
.
get
(
'
enable_smacks
'
)
||
_converse
.
session
.
get
(
'
smacks_enabled
'
))
{
return
;
return
;
}
}
...
@@ -198,9 +185,9 @@ converse.plugins.add('converse-smacks', {
...
@@ -198,9 +185,9 @@ converse.plugins.add('converse-smacks', {
_converse
.
connection
.
flush
();
_converse
.
connection
.
flush
();
await
promise
;
await
promise
;
}
}
}
}
async
function
enableStreamManagement
()
{
async
function
enableStreamManagement
()
{
if
(
!
api
.
settings
.
get
(
'
enable_smacks
'
))
{
if
(
!
api
.
settings
.
get
(
'
enable_smacks
'
))
{
return
;
return
;
}
}
...
@@ -215,9 +202,9 @@ converse.plugins.add('converse-smacks', {
...
@@ -215,9 +202,9 @@ converse.plugins.add('converse-smacks', {
}
else
{
}
else
{
resetSessionData
();
resetSessionData
();
}
}
}
}
function
onStanzaSent
(
stanza
)
{
function
onStanzaSent
(
stanza
)
{
if
(
!
_converse
.
session
)
{
if
(
!
_converse
.
session
)
{
log
.
warn
(
'
No _converse.session!
'
);
log
.
warn
(
'
No _converse.session!
'
);
return
;
return
;
...
@@ -244,11 +231,24 @@ converse.plugins.add('converse-smacks', {
...
@@ -244,11 +231,24 @@ converse.plugins.add('converse-smacks', {
_converse
.
session
.
save
({
'
num_stanzas_since_last_ack
'
:
num
});
_converse
.
session
.
save
({
'
num_stanzas_since_last_ack
'
:
num
});
}
}
}
}
}
}
api
.
listen
.
on
(
'
userSessionInitialized
'
,
initSessionData
);
api
.
listen
.
on
(
'
beforeResourceBinding
'
,
enableStreamManagement
);
converse
.
plugins
.
add
(
'
converse-smacks
'
,
{
initialize
()
{
// Configuration values for this plugin
// ====================================
// Refer to docs/source/configuration.rst for explanations of these
// configuration settings.
api
.
settings
.
extend
({
'
enable_smacks
'
:
true
,
'
smacks_max_unacked_stanzas
'
:
5
,
});
api
.
listen
.
on
(
'
afterResourceBinding
'
,
sendEnableStanza
);
api
.
listen
.
on
(
'
afterResourceBinding
'
,
sendEnableStanza
);
api
.
listen
.
on
(
'
beforeResourceBinding
'
,
enableStreamManagement
);
api
.
listen
.
on
(
'
send
'
,
onStanzaSent
);
api
.
listen
.
on
(
'
send
'
,
onStanzaSent
);
api
.
listen
.
on
(
'
userSessionInitialized
'
,
initSessionData
);
}
}
});
});
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