Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xmpp-pane
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Adrien Dorsaz
xmpp-pane
Commits
f5e7955a
Commit
f5e7955a
authored
Jun 07, 2018
by
Adrien Dorsaz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic presence and message support
parent
44cd9618
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
0 deletions
+86
-0
src/xmpp/constants.js
src/xmpp/constants.js
+6
-0
src/xmpp/core/message.js
src/xmpp/core/message.js
+40
-0
src/xmpp/core/presence.js
src/xmpp/core/presence.js
+40
-0
No files found.
src/xmpp/constants.js
View file @
f5e7955a
...
...
@@ -24,6 +24,12 @@ class Constants {
static
get
NS_XMPP_BIND
()
{
return
"
urn:ietf:params:xml:ns:xmpp-bind
"
;
}
static
get
STANZA_MESSAGE_VALID_TYPE
()
{
return
[
"
error
"
];
}
static
get
STANZA_PRESENCE_VALID_TYPE
()
{
return
[
"
error
"
];
}
static
get
STANZA_IQ_VALID_TYPE
()
{
return
[
"
get
"
,
"
set
"
,
"
result
"
,
"
error
"
];
}
...
...
src/xmpp/core/message.js
View file @
f5e7955a
...
...
@@ -7,4 +7,44 @@ class Message extends Stanza {
constructor
(
_config
)
{
super
(
_config
);
}
build
(
bodyElement
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
message
=
this
.
dom
.
createElement
(
'
presence
'
);
// By default, the "to" attribute should be defined
// but it could be not defined to send message. to bare JID of the client
if
(
this
.
to
)
{
message
.
setAttribute
(
'
to
'
,
this
.
to
);
}
message
.
setAttribute
(
'
from
'
,
this
.
from
);
if
(
this
.
xmllang
)
{
message
.
setAttribute
(
'
xml:lang
'
,
this
.
xmllang
);
}
message
.
setAttribute
(
'
id
'
,
this
.
id
);
for
(
let
key
of
Object
.
keys
(
this
.
extendedAttributes
))
{
message
.
setAttribute
(
key
,
this
.
extendedAttributes
[
key
]);
}
if
(
!
Constants
.
STANZA_MESSAGE_VALID_TYPE
.
find
((
type
)
=>
{
return
type
==
this
.
type
}))
{
reject
(
'
message error: type
'
+
this
.
type
+
'
is unknown for message stanzas.
'
);
}
message
.
setAttribute
(
'
type
'
,
this
.
type
);
if
(
typeof
(
bodyElement
)
==
'
object
'
)
{
message
.
appendChild
(
bodyElement
);
resolve
(
iq
);
}
else
{
reject
(
'
type of body is not DOM Element
'
);
}
});
}
}
src/xmpp/core/presence.js
View file @
f5e7955a
...
...
@@ -7,4 +7,44 @@ class Presence extends Stanza {
constructor
(
_config
)
{
super
(
_config
);
}
build
(
bodyElement
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
presence
=
this
.
dom
.
createElement
(
'
presence
'
);
// By default, the "to" attribute is not used to broadcast presence to every subscribed entities
// However client MAY set "to" to route the presence to a recipient
if
(
this
.
to
)
{
presence
.
setAttribute
(
'
to
'
,
this
.
to
);
}
presence
.
setAttribute
(
'
from
'
,
this
.
from
);
if
(
this
.
xmllang
)
{
presence
.
setAttribute
(
'
xml:lang
'
,
this
.
xmllang
);
}
presence
.
setAttribute
(
'
id
'
,
this
.
id
);
for
(
let
key
of
Object
.
keys
(
this
.
extendedAttributes
))
{
presence
.
setAttribute
(
key
,
this
.
extendedAttributes
[
key
]);
}
if
(
!
Constants
.
STANZA_PRESENCE_VALID_TYPE
.
find
((
type
)
=>
{
return
type
==
this
.
type
}))
{
reject
(
'
presence error: type
'
+
this
.
type
+
'
is unknown for presence stanzas.
'
);
}
presence
.
setAttribute
(
'
type
'
,
this
.
type
);
if
(
typeof
(
bodyElement
)
==
'
object
'
)
{
presence
.
appendChild
(
bodyElement
);
resolve
(
iq
);
}
else
{
reject
(
'
type of body is not DOM Element
'
);
}
});
}
}
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