Git Product home page Git Product logo

xmpp-ftw / xmpp-ftw Goto Github PK

View Code? Open in Web Editor NEW
254.0 254.0 32.0 8.21 MB

The goal of this project is to make XMPP really simple to use for developers. This module takes away all of the XML and works by hooking to events which are passed between client and server using a transport in JSON. For example code see https://github.com/lloydwatkin/xmpp-ftw-demo.

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

License: Apache License 2.0

JavaScript 100.00%

xmpp-ftw's Introduction

XMPP-FTW (For The Web/Win)

The goal of this project is to make XMPP really simple to use for developers. This module takes away all of the XML and works by hooking to events which are passed between client and server using a transport in JSON. In the example code we use socket.io, but there is no reason this can not be replaced with engine.io, or implement your own transport and pass in as a connection.

Try it out...

The code is now up and running at http://xmpp-ftw.org so you can try it out. Be aware that this setup is only for trying xmpp-ftw out and may be slow as we need to go client ↔ heroku (east coast US) ↔ your XMPP server and back each time.

The version running on the website matches 'master' branch here and auto-deploys with commits.

Also check out the xmpp-ftw-demo repository which is what http://xmpp-ftw.org is running.

Blog posts/Talks

Badges!

Build Status

Dependency Status

Coverage Status

Known Vulnerabilities

Instructions

  • npm i xmpp-ftw
  • Create your socket.io connection manually and then pass this socket into the constructor
io.sockets.on('connection', function(socket) {
     new require('xmpp-ftw').Xmpp(socket);       
});
  • All events are prefixed with 'xmpp.'

Logging

Logging is handled using a Winston like interface but by default does not record any logging (uses a null logger). Developers can inject any logging platform they wish provided it uses the same interface as Winston. In order to inject a logger simply call setLogger on the main XMPP-FTW object after instantiation.

Methods used in XMPP-FTW projects are:

  • log()
  • warn()
  • info()
  • error()

Server-side

If you want to run xmpp-ftw server side (e.g. to write a bot) then this should be a good starting point:

var xmppFtw = require('xmpp-ftw')
var Emitter = require('events').EventEmitter

var Socket = function() {
    this.server = new Emitter()
    this.client = new Emitter()
    var self = this
    this.server.send = function(event, data, rsm, callback) {
        self.client.emit(event, data, rsm, callback)
    }
    this.client.send = function(event, data, callback) {
        self.server.emit(event, data, callback)
    }
}
Socket.prototype.on = function(event, data, rsm) {
    this.server.on(event, data, rsm)
}
Socket.prototype.send = function(event, data, callback) {
    this.server.send(event, data, callback)
}
Socket.prototype.removeAllListeners = function(event) {
    this.server.removeAllListeners(event)
}

var socket = new Socket()
var client = new xmppFtw.Xmpp(socket)
socket.client.on('xmpp.connection', function (data) {
    console.log('Connected', data)
})
socket.client.on('xmpp.error', function (error) {
    console.log('error', error)
})
socket.client.on('xmpp.error.client', function (error) {
    console.log('client error', error)
})
socket.client.send('xmpp.login', { login: 'detiails', here: true })
socket.client.send(
    'xmpp.chat.message',
    {
        to: '[email protected]',
        content: 'Hello world'
    },
    function (error, data) { console.log(error, data) }
)

License

License is Apache 2.0, please let me know if this doesn't suit.

See also...

xmpp-ftw's People

Contributors

bitdeli-chef avatar greenkeeperio-bot avatar lloydwatkin avatar shobhitsinghal624 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xmpp-ftw's Issues

Split out XEP-0203 support

Already implemented in lib/chat.js but split it out into its own separate module so others can use it.

callback or not

Hi @lloydwatkin I've been using you modules for a while, and it really helps me a lot.

But while using some of the api you provided, I found that some of the method like socket.emit('xmpp.discover.items', data, cb); has a callback function, but some api like socket.emit('xmpp.chat.message', data); doesn't have one.

I may need to wrap these things in my code so I may need a unified api.

I've check your code both in xmpp-ftw-disco and xmpp-ftw. I don't see the reason. Not sure if this is related the xmpp protocol or not.

Can you explain it? Thanks!

Improve chat implementation

As chat was one of the first implemented modules it may require improvement.

This is also an issue to cover the addition of unit &/or integration tests to the system.

Expose a better API

At present from other modules I need to do:

var Base = require ('xmpp-ftw/lib/base')

This is horrible and creates brittle code. Ideally I should be able to do something like:

var Base = require ('xmpp-ftw').Base
var RSM = require ('xmpp-ftw').utils.xep0059

...or similar. Therefore no depending on internal module code structure.

Remove the use of jQuery and use LTX

jQuery made it nice and easy to start but now you know better and can use LTX itself to get data from stanzas. Remove all use of jQuery and use pure LTX from @astro.

I should create a label for "de-WTFing" for this work :)

Anonymous Login

node-xmpp client connection options:

{
  jid: '@' + domain,
  preferredSaslMechanism: 'ANONYMOUS'
}

Also allow setting of host.

logo not approriate for the interwebz

i think the animal on your current logo is sweet and nice, what ever it is, but i think it is not appropriate for the web.
It should be a cat.
… or porn.

TypeError when sending presence subscription to same user

Bit of an edge/idiot case, but when a user sends an xmpp.presence.subscribed payload to themselves, a TypeError occurs which brings down the node component.

Stack trace is:

TypeError: Cannot call method 'split' of undefined
    at Base._getJid (/www/bummer.io.fresh/node_modules/xmpp-ftw/lib/base.js:44:22)
    at Presence.handleError (/www/bummer.io.fresh/node_modules/xmpp-ftw/lib/presence.js:81:21)
    at Presence.handle (/www/bummer.io.fresh/node_modules/xmpp-ftw/lib/presence.js:47:51)
    at /www/bummer.io.fresh/node_modules/xmpp-ftw/index.js:187:35
    at Array.some (native)
    at Xmpp.handleStanza (/www/bummer.io.fresh/node_modules/xmpp-ftw/index.js:184:20)
    at Client.<anonymous> (/www/bummer.io.fresh/node_modules/xmpp-ftw/index.js:41:54)
    at Client.EventEmitter.emit (events.js:95:17)
    at Client.onStanza (/www/bummer.io.fresh/node_modules/xmpp-ftw/node_modules/node-xmpp/lib/xmpp/client.js:157:14)
    at Connection.EventEmitter.emit (events.js:95:17)

And the last stanza is:

info: Stanza received: <presence type="error" to="[email protected]/89639c5b-66cc-4035-a02e-b2da870b32f0" xmlns:stream="http://etherx.jabber.org/streams"><error type="modify"><bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Invalid presence type</text></error></presence>

Build generic RSM system

Build a generic RSM system which can be used for both incoming and outgoing stanzas.

Once complete create more issues to apply as required.

Support primus-emitter 2.0

I saw https://github.com/cayasso/primus-emitter has been move to 2.x , the most import change it's change emit function to send.If move primus-emitter to 2.x will not work.

Chat state problem

<message id="purple7c9a49fd"
     type="chat"
     to="[email protected]/..." 
     from="[email protected]/..."
     xmlns:stream="http://etherx.jabber.org/streams">
    <active xmlns="http://jabber.org/protocol/chatstates"/>
    <body>hey</body>
</message>

[TypeError: Cannot call method 'getChild' of undefined]

Unable to close connections - Object #<Sparky> has no method 'disconnect'

Connections stay open even when closing browser tab or even browser. Error message seen on node console is:
[TypeError: Object # has no method 'disconnect']

Even when an explicit primus.end() is send from client. XMPP-FTW sends an 'end' event back, but apparently no real desconnection is done.

Connection on XMPP server are alive until node process is closed.

Improve error stanza handling

Take the following example:

<iq id="361fe:1" type="error" to="lloyd@localhost/a95c4e64-3394-4921-9fb7-5881ade17a21" from="pubsub.localhost" xmlns:stream="http://etherx.jabber.org/streams">
    <error type="modify">
        <unexpected-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
        <not-subscribed xmlns="http://jabber.org/protocol/pubsub#errors"/>
    </error>
</iq>

Received by client:

{"type":"modify","condition":"unexpected-request"}

I got 'unexpected request' would have been better to get 'no-subscribed' or both?

Client errors

At present if a user provides invalid data to xmpp-ftw it silently ignores the message. What we really should be doing is firing a 'client error' message (or returning a client error message in the case of messages with callbacks).

Suggested event: xmpp.error.client
Format:

  {
    'description': "You didn't provide a JID",
    'message': { ... original incoming message ... }
  }

XEP-0004 Support form results

Currently there is no support for data form results in the parser. This should be supported for full XEP-0004 compliance.

Implement logout

Not only should we send a presence 'unavailable' we should also kill the logged in client and free up memory/etc

PEP update can not be parsed

Stanza received:

<message to="[email protected]/3241d981-0bee-4224-9de1-4d9b2feac47f" 
     from="[email protected]" xmlns:stream="http://etherx.jabber.org/streams">
    <event xmlns="http://jabber.org/protocol/pubsub#event">
        <items node="http://jabber.org/protocol/tune">
            <item id="512CCEB85F045">
                <tune xmlns="http://jabber.org/protocol/tune"/>
            </item>
        </items>
    </event>
    <delay xmlns="urn:xmpp:delay" stamp="2011-02-27T20:42:32Z" from="[email protected]/X200"/>
</message>

[TypeError: Cannot call method 'getChild' of undefined]

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.