An XMPP client library for MoonBit
Dependencies
| Feature | Standard | Status |
|---|---|---|
| XML streams | RFC 6120 §4 | done |
| STARTTLS | RFC 6120 §5 | done |
| SASL: PLAIN, SCRAM-SHA-1, SCRAM-SHA-256 | RFC 4422, RFC 4616, RFC 5802, RFC 7677 | done |
| Resource binding | RFC 6120 §7 | done |
| Initial presence | RFC 6121 §4.2 | done |
| Roster: get, set, push | RFC 6121 §2 | done |
| Presence subscriptions | RFC 6121 §3 | done |
| Chat messages | RFC 6120 §8, RFC 6121 §5.2 | done |
| JID parsing and normalization | RFC 8264 | done |
moon add daqing/moon-xmppimport {
"daqing/moon-xmpp" @xmpp,
}The API is built on moonbitlang/async. MoonBit has no await keyword — async calls look like ordinary calls, and errors propagate implicitly (functions raising XmppError must be called from a raising context).
///|
async fn main {
let conn = @xmpp.connect(host="example.com", port=5222)
conn.open_stream(domain="example.com")
ignore(conn.starttls(domain="example.com"))
ignore(conn.authenticate(jid="alice@example.com", password="secret"))
ignore(conn.bind_resource(resource="laptop"))
conn.send_initial_presence()
ignore(conn.get_roster())
ignore(conn.send_subscribe(to="bob@example.com"))
let id = conn.send_chat(to="bob@example.com", body="Hello from MoonBit!")
let stanza = conn.recv_stanza() // Chat / Presence / RosterPush / Subscription / Other
}git clone https://github.com/daqing/moon-xmpp
cd moon-xmpp
moon run cmd/moon-xmpp -- \
--jid alice@example.com \
--password '…'| Command | Effect |
|---|---|
| roster | print the cached roster with availability |
| send <jid> <message> | send a chat message |
| subscribe <jid> | ask to see a contact's presence |
| approve <jid> | accept a subscription request |
| unsubscribe <jid> | stop receiving a contact's presence |
| deny <jid> | refuse a subscription request |
| help | list the commands |
| quit | close the session (also exit, or EOF) |
moon run cmd/moon-xmpp -- --jid alice@example.com --password '…' \
--to bob@example.com --body 'Hello from MoonBit!'
moon run cmd/moon-xmpp -- --jid alice@example.com --password '…' \
--roster --subscribe bob@example.com --approve bob@example.com --replmoon build # build all packages (native target)
moon test # run the test suite
moon fmt # format the code
moon info # regenerate package interfacesscripts/prosody.sh start # or scripts/ejabberd.sh on x86
scripts/prosody.sh register alice secret123
scripts/prosody.sh register bob secret123
scripts/e2e.sh # two-direction delivery test
scripts/roster.sh # roster and subscription testfn version() -> StringInstall
Download zipAn XMPP client library for MoonBit
Dependencies