Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

An event fired by the router when a new stream is connected... #51

Merged
merged 7 commits into from

3 participants

@superfeedr

Not listened by the library itself (even though you could for the shaper for example), but I would love to use it for xmpp-server :) Let me know your thoughts.

I believe the "methods" part of node-xmpp are great and we have convenient ones for a lot of things, yet, a good JS library needs callbacks/hooks as well :)

@astro astro merged commit 5c5c756 into node-xmpp:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 2 deletions.
  1. +1 −1  lib/xmpp/c2s.js
  2. +4 −1 lib/xmpp/connection.js
  3. +7 −0 lib/xmpp/router.js
View
2  lib/xmpp/c2s.js
@@ -26,7 +26,7 @@ function C2SServer(options) {
// And now start listening to connections on the port provided as an option.
net.createServer(function (inStream) {
self.acceptConnection(inStream);
- }).listen(options.port || 5222, options.domain || '::');
+ }).listen(options.port || 5222, options.bindAddress || '::');
// Load TLS key material
if (options.tls) {
View
5 lib/xmpp/connection.js
@@ -97,6 +97,9 @@ Connection.prototype.setupStream = function() {
Connection.prototype.send = function(stanza) {
var self = this;
var flushed = true;
+ if (!this.socket) {
+ return; // Doh!
+ }
if (!this.socket.writable) {
this.socket.end();
return;
@@ -322,7 +325,7 @@ Connection.prototype.onClose = function() {
Connection.prototype.error = function(condition, message) {
this.emit('error', new Error(message));
- if (!this.socket.writable)
+ if (!this.socket || !this.socket.writable)
return;
if(!this.streamOpened)
View
7 lib/xmpp/router.js
@@ -4,6 +4,9 @@ var JID = require('./jid');
var ltx = require('ltx');
var StreamShaper = require('./../stream_shaper');
var IdleTimeout = require('./../idle_timeout');
+var EventEmitter = require('events').EventEmitter;
+var util = require('util');
+
try {
var StringPrep = require('node-stringprep').StringPrep;
var c = function(n) {
@@ -384,6 +387,7 @@ DomainContext.prototype.end = function() {
* * Incoming SASL EXTERNAL with certificate validation
*/
function Router(s2sPort, bindAddress) {
+ EventEmitter.call(this);
var self = this;
this.ctxs = {};
@@ -391,6 +395,8 @@ function Router(s2sPort, bindAddress) {
self.acceptConnection(inStream);
}).listen(s2sPort || 5269, bindAddress || '::');
}
+util.inherits(Router, EventEmitter);
+
exports.Router = Router;
// Defaults
@@ -458,6 +464,7 @@ Router.prototype.setupStream = function(stream) {
stream.socket.addListener('timeout', function() {
stream.error('connection-timeout');
});
+ this.emit('newStream', stream);
};
/**
Something went wrong with that request. Please try again.