https://github.com/jaredhanson/junction
Essential XMPP middleware for Node.js.
https://github.com/jaredhanson/junction
Last synced: over 1 year ago
JSON representation
Essential XMPP middleware for Node.js.
- Host: GitHub
- URL: https://github.com/jaredhanson/junction
- Owner: jaredhanson
- License: mit
- Created: 2011-03-07T00:00:57.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2018-10-15T19:39:34.000Z (almost 8 years ago)
- Last Synced: 2025-03-28T19:21:20.397Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 190 KB
- Stars: 106
- Watchers: 7
- Forks: 13
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Junction
Junction is an extensible [XMPP](http://xmpp.org/) middleware layer for [Node](http://nodejs.org).
Highly scalable applications can be constructed by assembling sets of "plugins"
known as _middleware_ and _filters_. Middleware process incoming stanzas, while
filters process outgoing stanzas.
This architecture has been proven effective by [Connect](http://www.senchalabs.org/connect/),
which provides HTTP middleware. Junction adopts this approach, repurposing it
for use in XMPP, allowing XMPP applications to be built quickly and easily,
while harnessing the powerful patterns familiar to Node.js developers.
## Installation
$ npm install junction
## Usage
#### Create an Application
To create a new application, simply invoke `junction()`. Use the built in
message and presence parsing middleware to parse common stanzas.
var app = junction()
.use(junction.messageParser())
.use(junction.presenceParser());
#### Handle Stanzas
Use additional middleware to define your application's behavior. In this
example, the built in `message` middleware is used to handle chat messages.
Anytime a message is received, we send a greeting and echo the message body.
app.use(junction.message(function(handler) {
handler.on('chat', function(stanza) {
var msg = new Message(stanza.from);
msg.c('body', {}).t('Hello ' + stanza.from + '!\n\n' +
'You said: ' + stanza.body);
stanza.connection.send(msg);
});
}));
Junction provides [bundled middleware](https://github.com/jaredhanson/junction/tree/master/lib/junction/middleware)
to handle core XMPP functionality. Additional middleware and higher-level
frameworks are available as separate modules.
#### Trailing Middleware
Conclude the app by using the typical trailing middleware:
app.use(junction.serviceUnavailable())
.use(junction.errorHandler());
`serviceUnavailable` middleware responds with a `service-unavailable` stanza
error when other XMPP entities send the application a request that it doesn't
support. This is recommended for well-behaved XMPP applications.
`errorHandler` middleware will respond with stanza errors when the application
encounters an error condition.
These middleware should be used _last_ in the stack, ensuring that other
middleware take priority.
#### Connect to XMPP Network
With the app configured, connect to the XMPP network.
app.connect({ jid: 'user@jabber.org', password: 's3cr3t' }).on('online', function() {
console.log('connected as: ' + this.jid);
this.send(new Presence());
});
Junction uses [node-xmpp](https://github.com/astro/node-xmpp) for the underlying
connection, allowing apps to connect as clients, components, or any other
supported connection type.
## Frameworks
At its core, XMPP is a protocol that allows structured data to be exchanged in
real-time between entities on the network. While typically used for instant
messaging and presence, numerous XMPP extension protocols (known as XEPs) are
available which make XMPP broadly applicable to non-IM applications.
These XEPs build on XMPP's core, while defining their own higher-level
semantics. Junction-based frameworks implement support for these extensions,
building on essential middleware and enhancing it with tooling designed to
support development of applications making use of the XEP.
FrameworkDescription
DiscoService Discovery (XEP-0030) framework.
PubSubPublish-Subscribe (XEP-0060) framework.
## Middleware
Additional middleware is available to parse non-core extension elements commonly
found in stanzas. Some middleware implement complete support for simple XEPs
that don't justify the need for a full-fledged framework.
MiddlewareDescription
junction-attentionAttention (XEP-0224) middleware.
junction-delayDelayed Delivery (XEP-0203) middleware.
junction-lastactivityLast Activity (XEP-0012) middleware.
junction-legacy-delayLegacy Delayed Delivery (XEP-0091) middleware.
junction-legacy-timeLegacy Entity Time (XEP-0090) middleware.
junction-nicknameUser Nickname (XEP-0172) middleware.
junction-pingXMPP Ping (XEP-0199) middleware.
junction-softwareversionSoftware Version (XEP-0092) middleware.
junction-timeEntity Time (XEP-0202) middleware.
junction-capsEntity Capabilities (XEP-0115) middleware.
## Tests
$ npm install --dev
$ make test
[](http://travis-ci.org/jaredhanson/junction)
## Credits
- [Jared Hanson](http://github.com/jaredhanson)
## License
[The MIT License](http://opensource.org/licenses/MIT)
Copyright (c) 2011-2017 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)>