Giter Site home page Giter Site logo

williamren / xmpp-ftw Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xmpp-ftw/xmpp-ftw

0.0 2.0 0.0 10.9 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: https://xmpp-ftw.jit.su

License: Apache License 2.0

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 https://xmpp-ftw.jit.su 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 โ†” nodejitsu (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 https://xmpp-ftw.jit.su is running.

Blog posts/Talks

Build status

Build Status

Dependency status

Dependency Status

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)

var client = new xmppFtw.Xmpp(socket)
socket.on('xmpp.connection', function(data) {
    console.log('Conected', 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: details, here: true })

License

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

See also...

Bitdeli Badge

xmpp-ftw's People

Contributors

bitdeli-chef avatar lloydwatkin 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.