GithubHelp home page GithubHelp logo

tempbottle / node-xmpp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xmppjs/xmpp.js

0.0 2.0 0.0 2.67 MB

XMPP library for node.js

Home Page: http://node-xmpp.org

License: MIT License

JavaScript 100.00%

node-xmpp's Introduction

node-xmpp

idiomatic XMPP library for node.js

Now usable in browsers too thanks to Browserify.

build status

Sub-modules

We've split node-xmpp into a set of submodules, realistically its now one of these that you'll want to use rather than node-xmpp itself. This project remains so existing users can continue to use the project, and as a location for integration tests. New users should make use of the sub-modules.

build status node-xmpp-server

build status node-xmpp-client

build status node-xmpp-component

build status node-xmpp-core

Installation

Note: We now only support nodejs versions 0.8.0 and greater.

With package manager npm:

npm install node-xmpp

Testing

Install the dev dependencies, then...

npm test

To run the tests and the code style checks then use:

grunt test

Also see the tests run in travis. The tests in travis run both the code and code style tests.

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

Built with node-xmpp

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().

Development Roadmap

For the next releases, we will focus on stability and security of node-xmpp. Pull requests are welcome to position node-xmpp as the best, most secure and most stable xmpp library for nodejs.

node-xmpp-core:

  • manifesto: support the STARTTLS method in XMPP as specified in RFC 6120, including mandatory-to-implement cipher suites and certificate validation consistent with RFC 6125
  • manifesto: prefer the latest version of TLS (TLS 1.2) #192
  • manifesto: disable support for the older and less secure SSL standard (SSLv2 and SSLv3)
  • manifesto: provide configuration options to require channel encryption for client-to-server and server-to-server connections
  • manifesto: provide configuration options to prefer or require cipher suites that enable forward secrecy
  • Events harmonization
  • Common pause/resume/... for any Client/Component/Server session
  • Smoothen reconnect
  • Properly disconnect on stream errors, not on connection errors
  • more tests to verify against RFC3920

node-xmpp-client:

  • Lookup BOSH URLs in DNS TXT records
  • Move connecting to connection, use WS/BOSH as TCP fallback
  • Ensure tls end/close/drain events
  • Possible may to use strophe plugins with node-xmpp, see dodo/Lightstream
  • more tests to verify against RFC3921
  • more demo apps to spead the usage
  • develop high-level client-api as seperate project to use json as input and output, see inspiration xmpp-ftw/xmpp-ftw
  • work on early DNSSEC implementation, see XMPP-DNA and DNSSEC

node-xmpp-server:

  • simple Websockets server (at least for testing the client)
  • Tests for S2S connections
  • maifesto: prefer authenticated encryption
  • harmonize c2s, bosh and websocket server components

Documentation

(Builing up documentation slowly)

C2S Client to Server

var client = new xmpp.Client({
    jid: '[email protected]',
    password: 'password'
})

client.on('connection', function() {
    console.log('online')
})

client.on('stanza', function(stanza) {
    console.log('Incoming stanza: ', stanza.toString())
})

Closing a connection

client.end()

node-xmpp's People

Contributors

aensley avatar andbas avatar astro avatar c4milo avatar cheggaaa avatar chris-rock avatar cradle 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 pvoisin avatar shamrin avatar sonnyp avatar srajbr avatar statico avatar tootallnate avatar trentm avatar

Watchers

 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.