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
197451db
Commit
197451db
authored
Sep 12, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support XEP-0128 service discovery extensions
Also add new API methods which return features and XEP-128 fields.
parent
acef8fea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
33 deletions
+95
-33
src/converse-disco.js
src/converse-disco.js
+95
-33
No files found.
src/converse-disco.js
View file @
197451db
...
...
@@ -46,6 +46,12 @@
);
this
.
features
.
on
(
'
add
'
,
this
.
onFeatureAdded
,
this
);
this
.
fields
=
new
Backbone
.
Collection
();
this
.
fields
.
browserStorage
=
new
Backbone
.
BrowserStorage
.
session
(
b64_sha1
(
`converse.fields-
${
this
.
get
(
'
jid
'
)}
`
)
);
this
.
fields
.
on
(
'
add
'
,
this
.
onFieldAdded
,
this
);
this
.
identities
=
new
Backbone
.
Collection
();
this
.
identities
.
browserStorage
=
new
Backbone
.
BrowserStorage
.
session
(
b64_sha1
(
`converse.identities-
${
this
.
get
(
'
jid
'
)}
`
)
...
...
@@ -109,6 +115,11 @@
_converse
.
emit
(
'
serviceDiscovered
'
,
feature
);
},
onFieldAdded
(
field
)
{
field
.
entity
=
this
;
_converse
.
emit
(
'
discoExtensionFieldDiscovered
'
,
field
);
},
fetchFeatures
()
{
if
(
this
.
features
.
browserStorage
.
records
.
length
===
0
)
{
this
.
queryInfo
();
...
...
@@ -184,12 +195,22 @@
if
(
stanza
.
querySelector
(
`feature[var="
${
Strophe
.
NS
.
DISCO_ITEMS
}
"]`
))
{
this
.
queryForItems
();
}
_
.
forEach
(
stanza
.
querySelectorAll
(
'
feature
'
),
(
feature
)
=>
{
_
.
forEach
(
stanza
.
querySelectorAll
(
'
feature
'
),
feature
=>
{
this
.
features
.
create
({
'
var
'
:
feature
.
getAttribute
(
'
var
'
),
'
from
'
:
stanza
.
getAttribute
(
'
from
'
)
});
});
// XEP-0128 Service Discovery Extensions
_
.
forEach
(
sizzle
(
'
x[type="result"][xmlns="jabber:x:data"] field
'
,
stanza
),
field
=>
{
this
.
fields
.
create
({
'
var
'
:
field
.
getAttribute
(
'
var
'
),
'
value
'
:
_
.
get
(
field
.
querySelector
(
'
value
'
),
'
textContent
'
),
'
from
'
:
stanza
.
getAttribute
(
'
from
'
)
});
});
this
.
waitUntilFeaturesDiscovered
.
resolve
(
this
);
this
.
trigger
(
'
featuresDiscovered
'
);
}
...
...
@@ -508,40 +529,40 @@
}
},
/**
* Used to determine whether an entity supports a given feature.
*
* @method _converse.api.disco.supports
* @param {string} feature The feature that might be
* supported. In the XML stanza, this is the `var`
* attribute of the `<feature>` element. For
* example: `http://jabber.org/protocol/muc`
* @param {string} jid The JID of the entity
* (and its associated items) which should be queried
* @returns {promise} A promise which resolves with a list containing
* _converse.Entity instances representing the entity
* itself or those items associated with the entity if
* they support the given feature.
*
* @example
* _converse.api.disco.supports(Strophe.NS.MAM, _converse.bare_jid)
* .then(value => {
* // `value` is a map with two keys, `supported` and `feature`.
* if (value.supported) {
* // The feature is supported
* } else {
* // The feature is not supported
* }
* }).catch(() => {
* _converse.log(
* "Error or timeout while checking for feature support",
* Strophe.LogLevel.ERROR
* );
* });
*/
/**
* Used to determine whether an entity supports a given feature.
*
* @method _converse.api.disco.supports
* @param {string} feature The feature that might be
* supported. In the XML stanza, this is the `var`
* attribute of the `<feature>` element. For
* example: `http://jabber.org/protocol/muc`
* @param {string} jid The JID of the entity
* (and its associated items) which should be queried
* @returns {promise} A promise which resolves with a list containing
* _converse.Entity instances representing the entity
* itself or those items associated with the entity if
* they support the given feature.
*
* @example
* _converse.api.disco.supports(Strophe.NS.MAM, _converse.bare_jid)
* .then(value => {
* // `value` is a map with two keys, `supported` and `feature`.
* if (value.supported) {
* // The feature is supported
* } else {
* // The feature is not supported
* }
* }).catch(() => {
* _converse.log(
* "Error or timeout while checking for feature support",
* Strophe.LogLevel.ERROR
* );
* });
*/
'
supports
'
(
feature
,
jid
)
{
if
(
_
.
isNil
(
jid
))
{
throw
new
TypeError
(
'
disco.supports: You need to provide an entity JID
'
);
throw
new
TypeError
(
'
api.
disco.supports: You need to provide an entity JID
'
);
}
return
_converse
.
api
.
waitUntil
(
'
discoInitialized
'
)
.
then
(()
=>
_converse
.
api
.
disco
.
entities
.
get
(
jid
,
true
))
...
...
@@ -555,6 +576,47 @@
}).
then
(
result
=>
f
.
filter
(
f
.
isObject
,
result
));
},
/**
* Return all the features associated with a disco entity
*
* @method _converse.api.disco.getFeatures
* @param {string} jid The JID of the entity whose features are returned.
* @example
* const features = await _converse.api.disco.getFeatures('room@conference.example.org');
*/
'
getFeatures
'
(
jid
)
{
if
(
_
.
isNil
(
jid
))
{
throw
new
TypeError
(
'
api.disco.getFeatures: You need to provide an entity JID
'
);
}
return
_converse
.
api
.
waitUntil
(
'
discoInitialized
'
)
.
then
(()
=>
_converse
.
api
.
disco
.
entities
.
get
(
jid
,
true
))
.
then
(
entity
=>
entity
.
waitUntilFeaturesDiscovered
)
.
then
(
entity
=>
entity
.
features
)
.
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
},
/**
* Return all the service discovery extensions fields
* associated with an entity.
*
* See [XEP-0129: Service Discovery Extensions](https://xmpp.org/extensions/xep-0128.html)
*
* @method _converse.api.disco.getFields
* @param {string} jid The JID of the entity whose fields are returned.
* @example
* const fields = await _converse.api.disco.getFields('room@conference.example.org');
*/
'
getFields
'
(
jid
)
{
if
(
_
.
isNil
(
jid
))
{
throw
new
TypeError
(
'
api.disco.getFields: You need to provide an entity JID
'
);
}
return
_converse
.
api
.
waitUntil
(
'
discoInitialized
'
)
.
then
(()
=>
_converse
.
api
.
disco
.
entities
.
get
(
jid
,
true
))
.
then
(
entity
=>
entity
.
waitUntilFeaturesDiscovered
)
.
then
(
entity
=>
entity
.
fields
)
.
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
},
/**
* Get the identity (with the given category and type) for a given disco entity.
*
...
...
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