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
00484280
Commit
00484280
authored
Jul 21, 2017
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: Catch and log errors that might happen during `initStatus`
parent
6ac01ed2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
193 additions
and
12 deletions
+193
-12
src/converse-core.js
src/converse-core.js
+16
-12
src/converse-disco.js
src/converse-disco.js
+177
-0
No files found.
src/converse-core.js
View file @
00484280
...
...
@@ -119,7 +119,10 @@
const
DEFAULT_IMAGE_TYPE
=
'
image/png
'
;
const
DEFAULT_IMAGE
=
"
iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABt+uBvAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gwHCy455JBsggAABkJJREFUeNrtnM1PE1sUwHvvTD8otWLHST/Gimi1CEgr6M6FEWuIBo2pujDVsNDEP8GN/4MbN7oxrlipG2OCgZgYlxAbkRYw1KqkIDRCSkM7nXvvW8x7vjyNeQ9m7p1p3z1LQk/v/Dhz7vkEXL161cHl9wI5Ag6IA+KAOCAOiAPigDggLhwQB2S+iNZ+PcYY/SWEEP2HAAAIoSAIoihCCP+ngDDGtVotGAz29/cfOXJEUZSOjg6n06lp2sbGRqlUWlhYyGazS0tLbrdbEASrzgksyeYJId3d3el0uqenRxRFAAAA4KdfIIRgjD9+/Pj8+fOpqSndslofEIQwHA6Pjo4mEon//qmFhYXHjx8v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WBz99EFhDGu1+t+v//48ePxeFxRlD179ng8nh0Efgiher2+vr6ur3HMzMysrq7uTJVdACGEurq6Ll++nEgkPB7Pj9jPoDHqOxyqqubz+WfPnuVyuV9XPeyeagAAAoHArVu3BgcHab8CuVzu4cOHpVKJUnfA5GweY+xyuc6cOXPv3r1IJMLAR8iyPDw8XK/Xi8Wiqqqmm5KZgBBC7e3tN27cuHbtGuPVpf7+/lAoNDs7W61WzfVKpgHSSzw3b95MpVKW3MfRaDQSiczNzVUqFRMZmQOIEOL1eq9fv3727FlL1t50URRFluX5+flqtWpWEGAOIFEUU6nUlStXLKSjy759+xwOx9zcnKZpphzGHMzhcDiTydgk9r1w4YIp7RPTAAmCkMlk2FeLf/tIEKbTab/fbwtAhJBoNGrutpNx6e7uPnTokC1eMU3T0um0DZPMkZER6wERQnw+n/FFSxpy7Nix3bt3WwwIIcRgIWnHkkwmjecfRgGx7DtuV/r6+iwGhDHev3+/bQF1dnYaH6E2CkiWZdsC2rt3r8WAHA5HW1ubbQGZcjajgOwTH/4qNko1Wlg4IA6IA+KAOKBWBUQIsfNojyliKIoRRfH9+/dut9umf3wzpoUNNQ4BAJubmwz+ic+OxefzWWlBhJD29nbug7iT5sIBcUAcEAfEAXFAHBAHxOVn+QMrmWpuPZx12gAAAABJRU5ErkJggg==
"
;
_converse
.
log
=
function
(
txt
,
level
)
{
_converse
.
log
=
function
(
message
,
level
)
{
if
(
message
instanceof
Error
)
{
message
=
message
.
stack
;
}
const
logger
=
_
.
assignIn
({
'
debug
'
:
_
.
noop
,
'
error
'
:
_
.
noop
,
...
...
@@ -128,23 +131,23 @@
},
console
);
if
(
level
===
Strophe
.
LogLevel
.
ERROR
)
{
if
(
_converse
.
debug
)
{
logger
.
trace
(
`ERROR:
${
txt
}
`
);
logger
.
trace
(
`ERROR:
${
message
}
`
);
}
else
{
logger
.
error
(
`ERROR:
${
txt
}
`
);
logger
.
error
(
`ERROR:
${
message
}
`
);
}
}
else
if
(
level
===
Strophe
.
LogLevel
.
WARN
)
{
logger
.
warn
(
`WARNING:
${
txt
}
`
);
logger
.
warn
(
`WARNING:
${
message
}
`
);
}
else
if
(
level
===
Strophe
.
LogLevel
.
FATAL
)
{
if
(
_converse
.
debug
)
{
logger
.
error
(
`FATAL:
${
txt
}
`
);
logger
.
error
(
`FATAL:
${
message
}
`
);
}
else
{
logger
.
error
(
`FATAL:
${
txt
}
`
);
logger
.
error
(
`FATAL:
${
message
}
`
);
}
}
else
if
(
_converse
.
debug
)
{
if
(
level
===
Strophe
.
LogLevel
.
DEBUG
)
{
logger
.
debug
(
`DEBUG:
${
txt
}
`
);
logger
.
debug
(
`DEBUG:
${
message
}
`
);
}
else
{
logger
.
info
(
`INFO:
${
txt
}
`
);
logger
.
info
(
`INFO:
${
message
}
`
);
}
}
};
...
...
@@ -801,10 +804,11 @@
// close them now.
_converse
.
chatboxviews
.
closeAllChatBoxes
();
_converse
.
features
=
new
_converse
.
Features
();
_converse
.
initStatus
().
then
(
_converse
.
initStatus
()
.
then
(
_
.
partial
(
_converse
.
onStatusInitialized
,
false
),
_
.
partial
(
_converse
.
onStatusInitialized
,
false
)
);
_
.
partial
(
_converse
.
onStatusInitialized
,
false
)
)
.
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
)
);
_converse
.
emit
(
'
connected
'
);
}
};
...
...
src/converse-disco.js
0 → 100644
View file @
00484280
// Converse.js (A browser based XMPP chat client)
// http://conversejs.org
//
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2)
//
/* This is a Converse.js plugin which add support for XEP-0030: Service Discovery */
/*global Backbone, define, window, document */
(
function
(
root
,
factory
)
{
define
([
"
converse-core
"
,
"
sizzle
"
,
"
strophe.disco
"
],
factory
);
}(
this
,
function
(
converse
,
sizzle
)
{
const
{
Backbone
,
Promise
,
Strophe
,
b64_sha1
,
_
}
=
converse
.
env
;
converse
.
plugins
.
add
(
'
converse-disco
'
,
{
initialize
()
{
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
const
{
_converse
}
=
this
;
// Promises exposed by this plugin
_converse
.
api
.
promises
.
add
(
'
discoInitialized
'
);
_converse
.
DiscoEntity
=
Backbone
.
Model
.
extend
({
/* A Disco Entity is a JID addressable entity that can be queried
* for features.
* See XEP-0030: https://xmpp.org/extensions/xep-0030.html
*/
initialize
(
settings
)
{
if
(
_
.
isNil
(
settings
.
jid
))
{
throw
new
Error
(
'
DiscoEntity must be instantiated with a JID
'
);
}
this
.
features
=
new
_converse
.
Features
({
'
jid
'
:
settings
.
jid
});
}
});
_converse
.
DiscoEntities
=
Backbone
.
Collection
.
extend
({
model
:
_converse
.
DiscoEntity
,
initialize
()
{
this
.
browserStorage
=
new
Backbone
.
BrowserStorage
[
_converse
.
storage
](
b64_sha1
(
`converse.disco-entities-
${
_converse
.
bare_jid
}
`
)
);
this
.
fetchEntities
().
then
(
_
.
partial
(
_converse
.
emit
,
'
discoInitialized
'
),
_
.
partial
(
_converse
.
emit
,
'
discoInitialized
'
)
);
},
fetchEntities
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
fetch
({
add
:
true
,
success
:
function
(
collection
)
{
if
(
collection
.
length
===
0
)
{
/* The sessionStorage is empty */
// TODO: check for domain in collection even if
// not empty
this
.
create
({
'
id
'
:
_converse
.
domain
,
'
jid
'
:
_converse
.
domain
});
}
resolve
();
}.
bind
(
this
),
error
()
{
reject
(
new
Error
(
"
Could not fetch disco entities
"
));
}
});
});
}
});
_converse
.
Features
=
Backbone
.
Collection
.
extend
({
/* Service Discovery
* -----------------
* This collection stores Feature Models, representing features
* provided by available XMPP entities (e.g. servers)
* See XEP-0030 for more details: http://xmpp.org/extensions/xep-0030.html
* All features are shown here: http://xmpp.org/registrar/disco-features.html
*/
model
:
Backbone
.
Model
,
initialize
(
jid
)
{
this
.
addClientIdentities
().
addClientFeatures
();
this
.
browserStorage
=
new
Backbone
.
BrowserStorage
[
_converse
.
storage
](
b64_sha1
(
`converse.features-
${
jid
}
`
)
);
this
.
on
(
'
add
'
,
this
.
onFeatureAdded
,
this
);
this
.
fetchFeatures
(
jid
);
},
fetchFeatures
(
jid
)
{
if
(
this
.
browserStorage
.
records
.
length
===
0
)
{
// browserStorage is empty, so we've likely never queried this
// domain for features yet
_converse
.
connection
.
disco
.
info
(
jid
,
null
,
this
.
onInfo
.
bind
(
this
));
_converse
.
connection
.
disco
.
items
(
jid
,
null
,
this
.
onItems
.
bind
(
this
));
}
else
{
this
.
fetch
({
add
:
true
});
}
},
onFeatureAdded
(
feature
)
{
_converse
.
emit
(
'
serviceDiscovered
'
,
feature
);
},
addClientIdentities
()
{
/* See http://xmpp.org/registrar/disco-categories.html
*/
_converse
.
connection
.
disco
.
addIdentity
(
'
client
'
,
'
web
'
,
'
Converse.js
'
);
return
this
;
},
addClientFeatures
()
{
/* The strophe.disco.js plugin keeps a list of features which
* it will advertise to any #info queries made to it.
*
* See: http://xmpp.org/extensions/xep-0030.html#info
*/
_converse
.
connection
.
disco
.
addFeature
(
Strophe
.
NS
.
BOSH
);
_converse
.
connection
.
disco
.
addFeature
(
Strophe
.
NS
.
CHATSTATES
);
_converse
.
connection
.
disco
.
addFeature
(
Strophe
.
NS
.
DISCO_INFO
);
_converse
.
connection
.
disco
.
addFeature
(
Strophe
.
NS
.
ROSTERX
);
// Limited support
if
(
_converse
.
message_carbons
)
{
_converse
.
connection
.
disco
.
addFeature
(
Strophe
.
NS
.
CARBONS
);
}
_converse
.
emit
(
'
addClientFeatures
'
);
return
this
;
},
onItems
(
stanza
)
{
_
.
each
(
stanza
.
querySelectorAll
(
'
query item
'
),
(
item
)
=>
{
_converse
.
connection
.
disco
.
info
(
item
.
getAttribute
(
'
jid
'
),
null
,
this
.
onInfo
.
bind
(
this
));
});
},
onInfo
(
stanza
)
{
if
((
sizzle
(
'
identity[category=server][type=im]
'
,
stanza
).
length
===
0
)
&&
(
sizzle
(
'
identity[category=conference][type=text]
'
,
stanza
).
length
===
0
))
{
// This isn't an IM server component
return
;
}
_
.
forEach
(
stanza
.
querySelectorAll
(
'
feature
'
),
(
feature
)
=>
{
const
namespace
=
feature
.
getAttribute
(
'
var
'
);
this
[
namespace
]
=
true
;
this
.
create
({
'
var
'
:
namespace
,
'
from
'
:
stanza
.
getAttribute
(
'
from
'
)
});
});
}
});
_converse
.
api
.
waitUntil
(
'
connected
'
).
then
(()
=>
{
_converse
.
disco_entities
=
new
_converse
.
DiscoEntities
();
});
_converse
.
api
.
listen
.
on
(
'
beforeTearDown
'
,
()
=>
{
if
(
_converse
.
disco_entities
)
{
_converse
.
disco_entities
.
each
((
entity
)
=>
{
entity
.
features
.
reset
();
entity
.
features
.
browserStorage
.
_clear
();
});
_converse
.
disco_entities
.
reset
();
_converse
.
disco_entities
.
browserStorage
.
_clear
();
}
});
}
});
}));
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