Sign in

    moon-xmpp

    An XMPP client library for MoonBit

    xmpp
    Download zip
    Author
    Version
    0.9.5
    License
    MIT
    Last updated
    23 days ago
    Downloads
    40

    #moon-xmpp

    An XMPP client library for MoonBit, implementing the client side of XMPP Core (RFC 6120) and XMPP IM (RFC 6121).

    #Status

    Work in progress. moon-xmpp is being developed as an entry for a MoonBit hackathon. The core session lifecycle (streams, STARTTLS, SASL, binding, presence, chat) is implemented, covered by 100+ tests, and verified against a real local XMPP server (see scripts/e2e.sh); GUI-client interop testing is the remaining step — see Roadmap and docs/ACCEPTANCE.md.

    #What it does

    moon-xmpp lets MoonBit programs connect to standard XMPP servers such as ejabberd, log in securely, and exchange one-on-one chat messages that interoperate with off-the-shelf clients such as Psi, Gajim, or Conversations.

    The acceptance scenario for the project:

    1. moon-xmpp connects to an ejabberd server, negotiates STARTTLS, authenticates with SASL, and binds a resource.
    2. It sends a chat message to another account; the message shows up in a third-party client in real time.
    3. A reply sent from that client is received by moon-xmpp.

    #Protocol coverage

    FeatureStandardStatus
    XML streamsRFC 6120 §4done
    STARTTLSRFC 6120 §5done
    SASL: PLAIN, SCRAM-SHA-1, SCRAM-SHA-256RFC 4422, RFC 4616, RFC 5802, RFC 7677done
    Resource bindingRFC 6120 §7done
    Initial presenceRFC 6121 §4.2done
    Chat messagesRFC 6120 §8, RFC 6121 §5.2done
    JID parsing and normalizationRFC 8264done

    #Non-goals

    • Roster and presence subscription management (RFC 6121 §2–3) — out of scope for now; may be revisited after the core works end to end.
    • XMPP extensions (XEPs), such as SASL2 (XEP-0388), Stream Management (XEP-0198), Message Carbons (XEP-0280), or MAM (XEP-0313).
    • Server-to-server (s2s) federation and any server-side functionality — this is a client library only.

    #Installation

    moon add daqing/moon-xmpp

    Then import it in the moon.pkg of your package:

    import { "daqing/moon-xmpp" @xmpp, }

    #Usage

    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()
    let id = conn.send_chat(to="bob@example.com", body="Hello from MoonBit!")
    let stanza = conn.recv_stanza() // Chat / Presence / Other
    }

    #Demo

    A small CLI lives in cmd/main:

    git clone https://github.com/daqing/moon-xmpp cd moon-xmpp moon run cmd/main -- \ --jid alice@example.com \ --password '…' \ --to bob@example.com \ --body 'Hello from MoonBit!'

    It connects (STARTTLS by default, --host/--port to override), logs in, binds a resource, goes online, sends the message, and then prints incoming messages and presence broadcasts until the stream ends. With a standard client (Psi, Gajim, Conversations) logged in as bob@example.com, the message arrives immediately; a reply sent from that client is printed by the running CLI.

    #Roadmap

    #Development

    Requires the MoonBit toolchain (moon). Targets the native backend.

    moon build # build all packages (native target) moon test # run the test suite moon fmt # format the code moon info # regenerate package interfaces

    Integration testing runs against a local XMPP server:

    scripts/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

    #License


    version

    fn version() -> String

    Return the version of the moon-xmpp library.

    Source Files