-
-
Save rastkojokic/2fa83e36e0770fd5f26e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
}); | |
}); |
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
To use Strophe with websockets I guess your WEBSOCKET_SERVICE url should be
ws://127.0.0.1:5280/websocket
and nothttp://127.0.0.1:5280/websocket
as you are doing now.