Create chat room using strophe.js

function createRoom() { var room_name = $('#room').val() + '@conference.localhost/' + sessionStorage.getItem("username");; Chat.mucCreateRoom(room_name); }


var Chat = { mucCreateRoom: function (roomName) { //roomname must be of the format: //'roomName@conference.localhost/nickName' Chat.mucSendPresence(roomName); Chat.connection.muc.createInstantRoom(roomName, function (status) { Chat.log("Succesfully created ChatRoom", status); }, function (status) { Chat.log("Error creating ChatRoom", status); } ); } }

Share This:


Send message using strophe.js

function sendMsg(JID,MSG) { Chat.sendMessage(JID, MSG, "chat"); }


var Chat = { sendMessage: function (messgeTo, message, type) { var messagetype = (type) ? type : 'chat'; var reply; if (messagetype === 'groupchat') { reply = $msg({to: messgeTo, from: Chat.connection.jid, type: messagetype, id: Chat.connection.getUniqueId() }).c("body", {xmlns: Strophe.NS.CLIENT}).t(message); } else { reply = $msg({to: messgeTo, from: Chat.connection.jid, type: messagetype }).c("body").t(message); } Chat.connection.send(reply.tree()); Chat.log('I sent ' + messgeTo + ': ' + message, reply.tree()); } }

Share This:


Connect and disconnect XMPP using strophe.js

function connect() { var jid = sessionStorage.getItem("jid"), password = sessionStorage.getItem("password"); var BOSH_SERVICE = Chat.BOSH_SERVICE; var debugginMode = false; Chat.connect(jid, password, BOSH_SERVICE, debugginMode); }


function disconnect() { sessionStorage.removeItem('user_name'); sessionStorage.removeItem('jid'); sessionStorage.removeItem('password'); Chat.disconnect(); window.location="index.html"; }


var Chat = { BOSH_SERVICE: 'http://IP:5280/http-bind', connection: null, connected: false, debuggingMode: false, connect: function (jid, password, BOSH_SERVICE, debugginMode) { //alert(password); Chat.BOSH_SERVICE = (BOSH_SERVICE) ? BOSH_SERVICE : Chat.BOSH_SERVICE; Chat.debuggingMode = (debugginMode) ? debugginMode : true; //set to false after done testing!! Chat.connection = new Strophe.Connection(Chat.BOSH_SERVICE); Chat.connection.connect(jid, password, Chat.onConnect); }, disconnect: function () { Chat.connection.flush(); Chat.connection.disconnect(); Chat.connected = false; }, }

Share This:


What is XMPP

XMPP (Extensible Messaging and Presence Protocol) is a protocol based on Extensible Markup Language (XML) and intended for instant messaging (IM) and online presence detection. It functions between or among servers, and facilitates near-real-time operation like chatting applications.

Share This: