Monthly Archive for April, 2011
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | var server = require("http").createServer(); var socket = require("socket.io").listen(server); var xmpp = require("node-xmpp"); socket.on("connection", function(connection) { var client = new xmpp.Client({jid: "[email protected]", password: ""}); client.on("online", function() { client.send(new xmpp.Element("presence", {type: "chat"})); connection.on("message", function(message) { client.send(new xmpp.Element("message", {to: "[email protected]", type: "chat"}).c("body").t(message)); }); connection.on("disconnect", function() { client.end(); }); }); client.on("stanza", function(stanza) { if (stanza.is("message")) { var b = stanza.getChildren("body"); if (b[0]) connection.send(b[0].getText()); } }); }); server.listen(8080); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <!DOCTYPE HTML> <title>XMPP</title> <form><p><input> <button disabled>Send</button></p></form> <ul></ul> <script> (function() { var script = document.createElement("script"); script.src = "jquery-1.4.3.min.js"; script.onload = function() { $.getScript("http://localhost:8080/socket.io/socket.io.js", function() { var socket = new io.Socket("localhost", {"port": 8080}); socket.on("connect", function() { $("form").submit(function() { socket.send($("input").val()); return false; }); $("button").removeAttr("disabled"); }); socket.on("disconnect", function() { $("button").attr("disabled", "disabled"); }); socket.on("message", function(message) { $("<li></li>").text(message).prependTo("ul"); }); socket.connect(); }); }; document.getElementsByTagName("head")[0].appendChild(script); })(); </script> |
Recent Comments