Skip to content
Snippets Groups Projects
Commit 55c24eeb authored by Tiger Wang's avatar Tiger Wang Committed by Tiger Wang
Browse files

No longer send room presence with every message

parent b0425cd6
No related branches found
No related tags found
No related merge requests found
import { client, xml } from "@xmpp/client"
import uuid from "uuid"
import debug from "@xmpp/debug"
export default class XMPPConnection extends EventTarget {
async joinChannel(channel) {
joinChannel(channel) {
const channelIdent = `${channel}@conference.xmpp.lets-draw.live/${this.username}`
const presence = xml(
"presence",
{ to: channelIdent },
xml("x", { xmlns: "http://jabber.org/protocol/muc" }),
)
this.sendOrQueue(presence)
}
sendOrQueue(message) {
if (this.online) {
await this.xmpp.send(presence)
this.xmpp.send(message)
} else {
this.queue.push(presence)
this.queue.push(message)
}
}
}
async sendChannelMessage(channel, message) {
sendChannelMessage(channel, message) {
const channelIdent = `${channel}@conference.xmpp.lets-draw.live`
const sentmessage = xml(
const wrappedMessage = xml(
"message",
{
type: "groupchat",
......@@ -28,7 +32,7 @@ export default class XMPPConnection extends EventTarget {
xml("body", {}, message),
)
await this.xmpp.send(sentmessage)
this.sendOrQueue(wrappedMessage)
}
constructor() {
......@@ -45,6 +49,19 @@ export default class XMPPConnection extends EventTarget {
password: "beartest",
})
this.xmpp = xmpp
debug(xmpp, true)
xmpp.on('status', status => {
console.debug('🛈', 'status', status)
})
xmpp.on('input', input => {
console.debug('', input)
})
xmpp.on('output', output => {
console.debug('', output)
})
xmpp.on("error", (err) => {
console.error("", err.toString())
})
......@@ -53,7 +70,7 @@ export default class XMPPConnection extends EventTarget {
this.online = false
})
xmpp.on("stanza", async (stanza) => {
xmpp.on("stanza", (stanza) => {
if (stanza.is("message")) {
this.dispatchEvent(
new CustomEvent("stanza", {
......@@ -77,13 +94,11 @@ export default class XMPPConnection extends EventTarget {
})
xmpp.start().catch(console.error)
this.joinChannel("imperial")
this.xmpp = xmpp
}
sneakilySendTheOtherTeamOur(secrets) {
this.joinChannel("imperial").then(
this.sendChannelMessage("imperial", secrets),
)
this.sendChannelMessage("imperial", secrets)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment