Example #1
0
 server.on("message", function ok(d) {
   if (/PRIVMSG #longassstrings/.test(d)) {
     server.removeListener("message", ok);
     d.length.should.equal(512);
     done();
   }
 });
Example #2
0
 server.on("message", function ok(m) {
   if (!/JOIN/.test(m)) {
     return;
   }
   server.removeListener("message", ok);
   m.should.equal(f("JOIN %s %s\r\n", chan.name, key));
 });
Example #3
0
 server.on("message", function ok(m) {
   if (!/PART/.test(m)) {
     return;
   }
   server.removeListener("message", ok);
   m.should.equal(f("PART %s\r\n", chan));
 });
Example #4
0
 server.on("message", function ok(m) {
   if (!/KICK/.test(m)) {
     return;
   }
   server.removeListener("message", ok);
   m.should.equal(f("KICK %s %s\r\n", chan.name, prsn.nick));
   done();
 });
Example #5
0
 server.on("message", function ok(m) {
   if (!/NOTICE/.test(m)) {
     return;
   }
   server.removeListener("message", ok);
   m.should.equal(f("NOTICE %s :%s\r\n", chan, notice));
   done();
 });
Example #6
0
 server.on("message", function ok(m) {
   if (!/PRIVMSG #nlogax/.test(m)) {
     return;
   }
   server.removeListener("message", ok);
   m.should.equal("PRIVMSG #nlogax :Message, send thyself\r\n");
   done();
 });
Example #7
0
 server.on("message", function ok(m) {
   if (!/MODE/.test(m)) {
     return;
   }
   server.removeListener("message", ok);
   m.should.equal(f("MODE %s -o\r\n", bot.user.nick));
   done();
 });
Example #8
0
 server.on("message", function ok(m) {
   if (!/MODE #modez/.test(m)) {
     return;
   }
   server.removeListener("message", ok);
   m.should.equal(f("MODE %s %s\r\n", chan, mode));
   server.recite(f(":lol@omg.com MODE %s %s\r\n", chan, mode));
 });
Example #9
0
 server.on("message", function ok(m) {
   if (!/QUIT/.test(m)) {
     return;
   }
   m.should.equal("QUIT\r\n");
   bot.connect(function() { done() });
   server.removeListener("message", ok);
 });
Example #10
0
 server.on("message", function ok(m) {
   if (!/PRIVMSG/.test(m)) {
     return;
   }
   server.removeListener("message", ok);
   m.should.equal("PRIVMSG #asl :Sending stuff\r\n");
   done();
 });
Example #11
0
 server.on("message", function ok(m) {
   if (!/PRIVMSG gf3/.test(m)) {
     return;
   }
   server.removeListener("message", ok);
   m.should.equal("PRIVMSG gf3 :Is these a bug?\r\n");
   done();
 });
Example #12
0
 server.on("message", function ok(m) {
   if (!/INVITE/.test(m)) {
     return;
   }
   server.removeListener("message", ok);
   m.should.equal(f("INVITE %s %s\r\n", user.nick, chan));
   done();
 });
Example #13
0
 server.on("message", function ok(m) {
   if (!/PART/.test(m)) {
     return;
   }
   server.removeListener("message", ok);
   m.should.equal(f("PART %s\r\n", chan));
   server.recite(f(":%s!~a@b.c PART %s\r\n", bot.user.nick, chan));
   done();
 });
Example #14
0
 server.on("message", function ok(m) {
   if (!/TOPIC #setowntopic/.test(m)) {
     return;
   }
   server.removeListener("message", ok);
   server.recite(f(":topic@setter.com TOPIC %s :%s\r\n", chan, topic));
   setTimeout(function() {
     chan.topic.should.equal(topic);
     done();
   }, 10);
 });
Example #15
0
    node.on("close", function() {
        // Workaround https://github.com/einaros/ws/pull/253
        // Remove listeners from RED.server
        var listener = null;
        for(var event in node._serverListeners){
            listener = node._serverListeners[event];
            if(typeof listener === "function"){
                RED.server.removeListener(event,listener);
            }
        }
        node._serverListeners = {};

        node.server.close();
        node._inputNodes = [];
    });
Example #16
0
 server.on("end", function ok() {
   server.removeListener("message", ok);
   bot.connect(function() { done() });
 });
Example #17
0
 server.on("message", function ok(m) {
   server.removeListener("message", ok);
   m.should.equal(f("INVITE %s %s\r\n", prsn.nick, chan));
   done();
 });
Example #18
0
// A node red node that sets up a local websocket server
function WebSocketListenerNode(n) {
    // Create a RED node
    RED.nodes.createNode(this,n);

    var node = this;

    // Store local copies of the node configuration (as defined in the .html)
    node.path = n.path;
    node.wholemsg = (n.wholemsg === "true");
    
    node._inputNodes = [];    // collection of nodes that want to receive events

    var path = RED.settings.httpNodeRoot || "/";
    path = path + (path.slice(-1) == "/" ? "":"/") + (node.path.charAt(0) == "/" ? node.path.substring(1) : node.path);

    // Workaround https://github.com/einaros/ws/pull/253
    // Listen for 'newListener' events from RED.server
    node._serverListeners = {};

    var storeListener = function(/*String*/event,/*function*/listener){
        if(event == "error" || event == "upgrade" || event == "listening"){
            node._serverListeners[event] = listener;
        }
    }

    node._clients = {};
    
    RED.server.addListener('newListener',storeListener);

    // Create a WebSocket Server
    node.server = new ws.Server({server:RED.server,path:path});

    // Workaround https://github.com/einaros/ws/pull/253
    // Stop listening for new listener events
    RED.server.removeListener('newListener',storeListener);

    node.server.on('connection', function(socket){
        var id = (1+Math.random()*4294967295).toString(16);
        node._clients[id] = socket;
        
        socket.on('close',function() {
            delete node._clients[id];
        });
        socket.on('message',function(data,flags){
            node.handleEvent(id,socket,'message',data,flags);
        });
        socket.on('error', function(err) {
            node.warn("An error occured on the ws connection: "+inspect(err));
        });
    });

    node.on("close", function() {
        // Workaround https://github.com/einaros/ws/pull/253
        // Remove listeners from RED.server
        var listener = null;
        for(var event in node._serverListeners){
            listener = node._serverListeners[event];
            if(typeof listener === "function"){
                RED.server.removeListener(event,listener);
            }
        }
        node._serverListeners = {};

        node.server.close();
        node._inputNodes = [];
    });
}
Example #19
0
 server.on("message", function ok(m) {
   server.removeListener("message", ok);
   m.should.equal(f("NOTICE %s :%s\r\n", person, notice));
   done();
 });