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
2d511a5e
Commit
2d511a5e
authored
Dec 13, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make `openAndEnterChatRoom` and async function
parent
c9546109
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
77 deletions
+70
-77
tests/utils.js
tests/utils.js
+70
-77
No files found.
tests/utils.js
View file @
2d511a5e
...
...
@@ -116,87 +116,80 @@
return
_converse
.
api
.
rooms
.
open
(
`
${
room
}
@
${
server
}
`
);
};
utils
.
openAndEnterChatRoom
=
function
(
_converse
,
room
,
server
,
nick
)
{
let
view
;
utils
.
openAndEnterChatRoom
=
async
function
(
_converse
,
room
,
server
,
nick
)
{
const
room_jid
=
`
${
room
}
@
${
server
}
`
.
toLowerCase
();
const
stanzas
=
_converse
.
connection
.
IQ_stanzas
;
await
_converse
.
api
.
rooms
.
open
(
room_jid
);
const
view
=
_converse
.
chatboxviews
.
get
(
room_jid
);
let
stanza
=
await
utils
.
waitUntil
(()
=>
_
.
get
(
_
.
filter
(
stanzas
,
iq
=>
iq
.
nodeTree
.
querySelector
(
`iq[to="
${
room_jid
}
"] query[xmlns="http://jabber.org/protocol/disco#info"]`
)).
pop
(),
'
nodeTree
'
));
return
_converse
.
api
.
rooms
.
open
(
room_jid
).
then
(()
=>
{
view
=
_converse
.
chatboxviews
.
get
(
room_jid
);
return
utils
.
waitUntil
(()
=>
_
.
get
(
_
.
filter
(
stanzas
,
iq
=>
iq
.
nodeTree
.
querySelector
(
`iq[to="
${
room_jid
}
"] query[xmlns="http://jabber.org/protocol/disco#info"]`
)).
pop
(),
'
nodeTree
'
));
}).
then
(
stanza
=>
{
const
features_stanza
=
$iq
({
'
from
'
:
room_jid
,
'
id
'
:
stanza
.
getAttribute
(
'
id
'
),
'
to
'
:
'
dummy@localhost/desktop
'
,
'
type
'
:
'
result
'
}).
c
(
'
query
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/disco#info
'
})
.
c
(
'
identity
'
,
{
'
category
'
:
'
conference
'
,
'
name
'
:
room
[
0
].
toUpperCase
()
+
room
.
slice
(
1
),
'
type
'
:
'
text
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
http://jabber.org/protocol/muc
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
jabber:iq:register
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_passwordprotected
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_hidden
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_temporary
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_open
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_unmoderated
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_nonanonymous
'
})
.
c
(
'
x
'
,
{
'
xmlns
'
:
'
jabber:x:data
'
,
'
type
'
:
'
result
'
})
.
c
(
'
field
'
,
{
'
var
'
:
'
FORM_TYPE
'
,
'
type
'
:
'
hidden
'
})
.
c
(
'
value
'
).
t
(
'
http://jabber.org/protocol/muc#roominfo
'
).
up
().
up
()
.
c
(
'
field
'
,
{
'
type
'
:
'
text-single
'
,
'
var
'
:
'
muc#roominfo_description
'
,
'
label
'
:
'
Description
'
})
.
c
(
'
value
'
).
t
(
'
This is the description
'
).
up
().
up
()
.
c
(
'
field
'
,
{
'
type
'
:
'
text-single
'
,
'
var
'
:
'
muc#roominfo_occupants
'
,
'
label
'
:
'
Number of occupants
'
})
.
c
(
'
value
'
).
t
(
0
);
_converse
.
connection
.
_dataRecv
(
utils
.
createRequest
(
features_stanza
));
return
utils
.
waitUntil
(()
=>
_
.
filter
(
stanzas
,
s
=>
sizzle
(
`iq[to="
${
room_jid
}
"] query[node="x-roomuser-item"]`
,
s
.
nodeTree
).
length
).
pop
()
);
}).
then
(
iq
=>
{
// We remove the stanza, otherwise we might get stale stanzas returned in our filter above.
stanzas
.
splice
(
stanzas
.
indexOf
(
iq
),
1
)
const
features_stanza
=
$iq
({
'
from
'
:
room_jid
,
'
id
'
:
stanza
.
getAttribute
(
'
id
'
),
'
to
'
:
'
dummy@localhost/desktop
'
,
'
type
'
:
'
result
'
}).
c
(
'
query
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/disco#info
'
})
.
c
(
'
identity
'
,
{
'
category
'
:
'
conference
'
,
'
name
'
:
room
[
0
].
toUpperCase
()
+
room
.
slice
(
1
),
'
type
'
:
'
text
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
http://jabber.org/protocol/muc
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
jabber:iq:register
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_passwordprotected
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_hidden
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_temporary
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_open
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_unmoderated
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_nonanonymous
'
})
.
c
(
'
x
'
,
{
'
xmlns
'
:
'
jabber:x:data
'
,
'
type
'
:
'
result
'
})
.
c
(
'
field
'
,
{
'
var
'
:
'
FORM_TYPE
'
,
'
type
'
:
'
hidden
'
})
.
c
(
'
value
'
).
t
(
'
http://jabber.org/protocol/muc#roominfo
'
).
up
().
up
()
.
c
(
'
field
'
,
{
'
type
'
:
'
text-single
'
,
'
var
'
:
'
muc#roominfo_description
'
,
'
label
'
:
'
Description
'
})
.
c
(
'
value
'
).
t
(
'
This is the description
'
).
up
().
up
()
.
c
(
'
field
'
,
{
'
type
'
:
'
text-single
'
,
'
var
'
:
'
muc#roominfo_occupants
'
,
'
label
'
:
'
Number of occupants
'
})
.
c
(
'
value
'
).
t
(
0
);
_converse
.
connection
.
_dataRecv
(
utils
.
createRequest
(
features_stanza
));
const
iq
=
await
utils
.
waitUntil
(()
=>
_
.
filter
(
stanzas
,
s
=>
sizzle
(
`iq[to="
${
room_jid
}
"] query[node="x-roomuser-item"]`
,
s
.
nodeTree
).
length
).
pop
());
// The XMPP server returns the reserved nick for this user.
const
IQ_id
=
iq
.
nodeTree
.
getAttribute
(
'
id
'
);
const
stanza
=
$iq
({
'
type
'
:
'
result
'
,
'
id
'
:
IQ_id
,
'
from
'
:
view
.
model
.
get
(
'
jid
'
),
'
to
'
:
_converse
.
connection
.
jid
}).
c
(
'
query
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/disco#info
'
,
'
node
'
:
'
x-roomuser-item
'
})
.
c
(
'
identity
'
,
{
'
category
'
:
'
conference
'
,
'
name
'
:
nick
,
'
type
'
:
'
text
'
});
_converse
.
connection
.
_dataRecv
(
utils
.
createRequest
(
stanza
));
return
utils
.
waitUntil
(()
=>
view
.
model
.
get
(
'
nick
'
));
}).
then
(()
=>
{
// The user has just entered the room (because join was called)
// and receives their own presence from the server.
// See example 24: http://xmpp.org/extensions/xep-0045.html#enter-pres
var
presence
=
$pres
({
to
:
_converse
.
connection
.
jid
,
from
:
`
${
room_jid
}
/
${
nick
}
`
,
id
:
u
.
getUniqueId
()
}).
c
(
'
x
'
).
attrs
({
xmlns
:
'
http://jabber.org/protocol/muc#user
'
})
.
c
(
'
item
'
).
attrs
({
affiliation
:
'
owner
'
,
jid
:
_converse
.
bare_jid
,
role
:
'
moderator
'
}).
up
()
.
c
(
'
status
'
).
attrs
({
code
:
'
110
'
});
_converse
.
connection
.
_dataRecv
(
utils
.
createRequest
(
presence
));
return
utils
.
waitUntil
(()
=>
(
view
.
model
.
get
(
'
connection_status
'
)
===
converse
.
ROOMSTATUS
.
ENTERED
));
}).
catch
(
e
=>
{
console
.
error
(
e
);
throw
e
;
});
// We remove the stanza, otherwise we might get stale stanzas returned in our filter above.
stanzas
.
splice
(
stanzas
.
indexOf
(
iq
),
1
)
// The XMPP server returns the reserved nick for this user.
const
IQ_id
=
iq
.
nodeTree
.
getAttribute
(
'
id
'
);
stanza
=
$iq
({
'
type
'
:
'
result
'
,
'
id
'
:
IQ_id
,
'
from
'
:
view
.
model
.
get
(
'
jid
'
),
'
to
'
:
_converse
.
connection
.
jid
}).
c
(
'
query
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/disco#info
'
,
'
node
'
:
'
x-roomuser-item
'
})
.
c
(
'
identity
'
,
{
'
category
'
:
'
conference
'
,
'
name
'
:
nick
,
'
type
'
:
'
text
'
});
_converse
.
connection
.
_dataRecv
(
utils
.
createRequest
(
stanza
));
await
utils
.
waitUntil
(()
=>
view
.
model
.
get
(
'
nick
'
));
// The user has just entered the room (because join was called)
// and receives their own presence from the server.
// See example 24: http://xmpp.org/extensions/xep-0045.html#enter-pres
var
presence
=
$pres
({
to
:
_converse
.
connection
.
jid
,
from
:
`
${
room_jid
}
/
${
nick
}
`
,
id
:
u
.
getUniqueId
()
}).
c
(
'
x
'
).
attrs
({
xmlns
:
'
http://jabber.org/protocol/muc#user
'
})
.
c
(
'
item
'
).
attrs
({
affiliation
:
'
owner
'
,
jid
:
_converse
.
bare_jid
,
role
:
'
moderator
'
}).
up
()
.
c
(
'
status
'
).
attrs
({
code
:
'
110
'
});
_converse
.
connection
.
_dataRecv
(
utils
.
createRequest
(
presence
));
await
utils
.
waitUntil
(()
=>
(
view
.
model
.
get
(
'
connection_status
'
)
===
converse
.
ROOMSTATUS
.
ENTERED
));
};
utils
.
clearBrowserStorage
=
function
()
{
...
...
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