Giter Club home page Giter Club logo

node-xmpp's Introduction

node-xmpp

idiomatic XMPP library for node.js

Now usable in browsers too thanks to Browserify.

build status

Installation

With package manager npm:

npm install node-xmpp

How to use

Please see the various examples.

Objectives of node-xmpp:

  • Use node.js conventions, especially EventEmitter, ie. for write buffer control
  • Fast parsing, node-expat was written for this library
  • Client support for both XMPP clients and components
  • Optional server infrastructure with Router
  • After authentication, leave trivial protocol bits to the user, that is XML handling according to any XEP

Features

  • Client authentication with SASL DIGEST-MD5, PLAIN, ANONYMOUS, X-FACEBOOK-PLATFORM
  • _xmpp-client._tcp SRV record support
  • Simple JID parsing with Stringprep normalization
    • Optional now, you won't need ICU for just node-xmpp
    • Please be aware if you identify users by JIDs
    • npm install node-stringprep
  • Uses ltx
    • Much easier to handle than a standard DOM
    • xmlns-aware
    • Easy XML builder like Strophe.js (see down)
    • Non-buffering serialization
    • Was split out of node-xmpp for modularization and resuability
  • Component connections
  • Run your own server/talk to other servers with xmpp.Router
  • Even runs in the Browser.

Dependencies

Optional

Related Libraries

Design

Inheritance tree and associations:

┌────────────┐1     1┌────────────┐
│ net.Stream ├───────┤ Connection │
└────────────┘       └────────────┘
                           ↑
      ┌────────────┬───────┴───┬────────────┐
      │            │           │            │
┏━━━━━┷━━━━┓ ┏━━━━━┷━━━━━┓ ┌───┴────┐ ┌─────┴─────┐
┃  Client  ┃ ┃ Component ┃ │ Server │ │ C2SStream │
┗━━━━━━━━━━┛ ┗━━━━━━━━━━━┛ └────────┘ └───────────┘
                               ↑            ↑0..*
         ┌─────────────────────┤            │accepts
         │                     │            │1
┌────────┴───────┐ ┌───────────┴────┐ ┏━━━━━┷━━━━━┓
│ OutgoingServer │ │ IncomingServer │ ┃ C2SServer ┃
└─────────────┬──┘ └───┬────────────┘ ┗━━━━━┯━━━━━┛
         0..* │        │ 0..*               │
      creates │        │ accepts            │
             ┏┷━━━━━━━━┷┓                   │
             ┃  Router  ┃←──────────────────┘
             ┗━━━━━━━━━━┛ 1

This foundation is complemented by two basic data structures:

  • JID: a Jabber-Id, represented as a triple of user, domain, resource
  • Element: any XML Element

Building XML Elements

Strophe.js' XML Builder is very convenient for producing XMPP stanzas. ltx includes it in a much more primitive way: the c(), cnode() and t() methods can be called on any Element object, returning the new child element.

This can be confusing: in the end, you will hold the last-added child until you use up(), a getter for the parent. Connection.send() first invokes tree() to retrieve the uppermost parent, the XMPP stanza, before sending it out the wire.

Browser Support

node-xmpp now comes with a prebuilt browser bundle:

<script src="/node_modules/node-xmpp/node-xmpp-browser.js"></script>
<script type="text/javascript">
    var client = new XMPP.Client(opts);
</script>

Keepalives

Rather than send empty packets in order to keep any socket alive please try the following:

this.client.connection.socket.setTimeout(0)
this.client.connection.socket.setKeepAlive(true, 10000)

Where this.client is the result of new require('node-xmpp').Client().

Roadmap for future versions

  • Events harmonization
  • Common pause/resume/... for any Client/Component/Server session
  • Smoothen reconnect
  • Websockets server (at least for testing the client)
  • Lookup BOSH URLs in DNS TXT records
  • Move connecting to connection, use WS/BOSH as TCP fallback
  • Use split-out srv library
  • Ensure tls end/close/drain events
  • Properly disconnect on stream errors, not on connection errors
  • Tests for S2S connections
  • Tests for Component connections (w/ Component server?)
  • Find a browser-based demo app that can be switched from Strophe.js

node-xmpp's People

Contributors

aensley avatar andbas avatar astro avatar c4milo avatar cheggaaa avatar daniel15 avatar danielzzz avatar dhruvbird avatar dodo avatar eelcocramer avatar flosse avatar frane avatar hammerdr avatar hpychan avatar julien51 avatar justincampbell avatar kkreamer avatar lloydwatkin avatar naltatis avatar ndarilek avatar phyrex1an avatar serjrd avatar shamrin avatar snowmantw avatar sonnyp avatar statico avatar tootallnate avatar trentm avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.