Skip to content

Instantly share code, notes, and snippets.

@rastkojokic
Created May 18, 2015 09:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rastkojokic/2fa83e36e0770fd5f26e to your computer and use it in GitHub Desktop.
Save rastkojokic/2fa83e36e0770fd5f26e to your computer and use it in GitHub Desktop.
var WEBSOCKET_SERVICE = 'http://127.0.0.1:5280/websocket';
var connection = null;
function log(msg)
{
$('#log').append('<div></div>').append(document.createTextNode(msg));
}
function rawInput(data)
{
log('RECV: ' + data);
}
function rawOutput(data)
{
log('SENT: ' + data);
}
function onConnect(status)
{
log('Status: ' + status);
console.log(connection)
if (status == Strophe.Status.CONNECTING) {
log('Strophe is connecting.');
} else if (status == Strophe.Status.CONNFAIL) {
log('Strophe failed to connect.');
$('#connect').get(0).value = 'connect';
} else if (status == Strophe.Status.DISCONNECTING) {
log('Strophe is disconnecting.');
} else if (status == Strophe.Status.DISCONNECTED) {
log('Strophe is disconnected.');
$('#connect').get(0).value = 'connect';
} else if (status == Strophe.Status.CONNECTED) {
log('Strophe is connected.');
connection.disconnect();
}
}
$(document).ready(function () {
connection = new Strophe.Connection(WEBSOCKET_SERVICE);
connection.rawInput = rawInput;
connection.rawOutput = rawOutput;
$('#connect').bind('click', function () {
var button = $('#connect').get(0);
if (button.value == 'connect') {
button.value = 'disconnect';
connection.connect($('#jid').get(0).value,
$('#pass').get(0).value,
onConnect);
} else {
button.value = 'connect';
connection.disconnect();
}
});
});
@lefam
Copy link

lefam commented May 24, 2015

To use Strophe with websockets I guess your WEBSOCKET_SERVICE url should be ws://127.0.0.1:5280/websocket and not http://127.0.0.1:5280/websocket as you are doing now.

@vicvolk
Copy link

vicvolk commented Aug 19, 2015

I'm struggling with a similar problem. I've installed ejabberd, created two accounts and now I want to connect to ejabberd and send a message from user1 to user2. I see, that you use var WEBSOCKET_SERVICE = 'http://127.0.0.1:5280/websocket' as an end point. Would you be so kind to share, whether you managed to solve your own problem and also share on how to configure ejabberd.yml, because at this moment I see a number of elements that form the whole puzzle - ejabberd configuration, Apache configuration and valid javascript code. But I can not make them work together. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment