Skip to content

Instantly share code, notes, and snippets.

@tsega
Created December 8, 2013 07:30
Show Gist options
  • Save tsega/7854303 to your computer and use it in GitHub Desktop.
Save tsega/7854303 to your computer and use it in GitHub Desktop.
// First Define a Strophe Object
var Strobj = {
connection: null,
room: null,
nickname: null,
xmpp_server: "@localhost",
BOSH: "http://localhost:5280/http-bind",
muc: "@conference.localhost",
NS_MUC: "http://jabber.org/protocol/muc",
joined: null,
participants: null,
// Method to get the username from the jid
username : function(jid) { },
// Method to handle the on presence event
on_presence: function (presence) { },
// Method to handle the public message event
on_public_message: function (message) { },
// Method to handle the private message event
on_private_message: function (message) { },
// Method to add chat message in the chat window
add_message: function (msg) { },
// Method to handle the response of user after a chat request (invitation)
on_response: function(message){ }
};
// jQuery document ready function to handle whatever you need
$(document).ready(function(){
// Send chat invitation button click event handler
$("#send-invitation").click(function(e){
e.preventDefault();
// Manually trigger the 'contact_invited' event defined below
$(document).trigger('contact_invited', {
sender: $("#jid").val(),
receiver: $(this).val() + Strobj.xmpp_server,
room: $("#room").val() + Strobj.muc
});
});
});
// The Event that is manually fired when an inivitation is sent
$(document).bind('contact_invited', function(ev, data) {
var message = $msg({
from: data.sender,
to : data.room
})
.c('x', {
xmlns : "http://jabber.org/protocol/muc#user"
})
.c('invite', {
to : data.receiver
})
.c('reason').t(Strobj.username(data.sender) + " has requested to chat with you.");
Strobj.connection.send(message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment