/**
* Comment here for explanation of the options.
*
* Create a new XMPP Object with the required params
*
* @param string $jabberHost Jabber Server Host
* @param string $boshUri Full URI to the http-bind
* @param string $resource Resource identifier
* @param bool $useSsl Use SSL (not working yet, TODO)
* @param bool $debug Enable debug
*/
$xmppPrebind = new XmppPrebind('your-jabber-host.tld', 'http://your-jabber-
host/http-bind/', 'Your XMPP Clients resource name', false, false);
$xmppPrebind->connect($username, $password);
$xmppPrebind->auth();
$sessionInfo = $xmppPrebind->getSessionInfo(); // array containing sid, rid and
jid
<link type="text/css" rel="stylesheet" media="screen"
href="css/converse.css" />
0 down vote favorite
I'm trying to pre-bind with converse.js a conncection established with Stroph,
I'm wondering if I'm doing it right because once it is linked, 3 chat windows
from the same user are opened. Here's my js code:
require(["jquery", "converse"], function ($, converse) {
connection = new Strophe.Connection(BOSH_SERVICE);
connection.connect(_JID, _JID_PASS, function () {
_SID = connection._proto.sid;
converse.initialize({
allow_otr: true,
auto_list_rooms: false,
auto_subscribe: false,
jid: _JID,
sid: _SID,
rid: connection._proto.rid,//_RID,
prebind: true,
bosh_service_url: BOSH_SERVICE,
show_controlbox_by_default: true,
debug: true,
expose_rid_and_sid: true,
roster_groups: true
});
});
require(["jquery", "converse"], function ($, converse) {
$.ajax({
'url': '/conversejs/bind/',
'success': function (data) {
converse.initialize({
prebind: true,
rid: data.rid,
sid: data.sid,
jid: data.jid,
bosh_service_url: 'https://bind.opkode.im',
show_controlbox_by_default: true,
});
}
});
});
/assets/converse.js/builds/converse.website.min.js
<?php
$xmppUser = 'asterisk@example.org';
$xmppPass = 'FIXME';
$xmppTarget = 'user@example.org';
$callerName = 'FIXME';
$adrLink = 'https://FIXME';
$telLink = 'tel:FIXME';
$textMsg = 'Incoming call from ' . $callerName;
$htmlMsg = 'Incoming call from '
. '<a href="' . htmlspecialchars($adrLink) . '">'
. htmlspecialchars($callerName)
. '</a>'
. ' <a href="' . htmlspecialchars($telLink) . '">'
. '&#9742;</a>';
$postMsg = 'to=' . urlencode($xmppTarget)
. '&type=chat'
. '&body=' . urlencode($textMsg);
.= '&html=' . urlencode(
'<body xmlns="http://www.w3.org/1999/xhtml">'
. $htmlMsg
. '</body>body>'
);
$ctx = stream_context_create(
array(
'http' => array(
'method' => 'POST',
'header' => array(
'Content-type: application/x-www-form-urlencoded',
'Authorization: Basic ' . base64_encode($xmppUser . ':' .
$xmppPass),
),
'content' => $postMsg
)
)
);
file_get_contents('http://xmpp.example.org:5280/msg/', false, $ctx);
?>
Have a read of http://metajack.im/2008/10/03/getting-attached-to-strophe/
Establish a session for the user to XMPP server from your server (at user
login?)
Then pass via "jid", "rid", sid" in HTML dynamic page - something like:
converse.initialize({
auto_list_rooms: false,
auto_subscribe: true,
bosh_service_url: '<%= session.getAttribute("bosh") %>',
hide_muc_server: false,
i18n: locales.en, // Refer to ./locale/locales.js to see which locales are
supported
prebind: true,
show_controlbox_by_default: true,
fullname: '<%= session.getAttribute("userid") %>',
xhr_user_search: false,
jid:'<%= session.getAttribute("jid") %>',
sid:'<%= session.getAttribute("sid") %>',
rid:'<%= session.getAttribute("rid") %>'
});
converse.attach();

Xmpp prebind

  • 1.
    /** * Comment herefor explanation of the options. * * Create a new XMPP Object with the required params * * @param string $jabberHost Jabber Server Host * @param string $boshUri Full URI to the http-bind * @param string $resource Resource identifier * @param bool $useSsl Use SSL (not working yet, TODO) * @param bool $debug Enable debug */ $xmppPrebind = new XmppPrebind('your-jabber-host.tld', 'http://your-jabber- host/http-bind/', 'Your XMPP Clients resource name', false, false); $xmppPrebind->connect($username, $password); $xmppPrebind->auth(); $sessionInfo = $xmppPrebind->getSessionInfo(); // array containing sid, rid and jid <link type="text/css" rel="stylesheet" media="screen" href="css/converse.css" /> 0 down vote favorite I'm trying to pre-bind with converse.js a conncection established with Stroph, I'm wondering if I'm doing it right because once it is linked, 3 chat windows from the same user are opened. Here's my js code: require(["jquery", "converse"], function ($, converse) { connection = new Strophe.Connection(BOSH_SERVICE); connection.connect(_JID, _JID_PASS, function () { _SID = connection._proto.sid; converse.initialize({ allow_otr: true, auto_list_rooms: false, auto_subscribe: false, jid: _JID, sid: _SID, rid: connection._proto.rid,//_RID, prebind: true, bosh_service_url: BOSH_SERVICE, show_controlbox_by_default: true, debug: true, expose_rid_and_sid: true, roster_groups: true }); }); require(["jquery", "converse"], function ($, converse) { $.ajax({ 'url': '/conversejs/bind/', 'success': function (data) { converse.initialize({ prebind: true, rid: data.rid, sid: data.sid,
  • 2.
    jid: data.jid, bosh_service_url: 'https://bind.opkode.im', show_controlbox_by_default:true, }); } }); }); /assets/converse.js/builds/converse.website.min.js <?php $xmppUser = 'asterisk@example.org'; $xmppPass = 'FIXME'; $xmppTarget = 'user@example.org'; $callerName = 'FIXME'; $adrLink = 'https://FIXME'; $telLink = 'tel:FIXME'; $textMsg = 'Incoming call from ' . $callerName; $htmlMsg = 'Incoming call from ' . '<a href="' . htmlspecialchars($adrLink) . '">' . htmlspecialchars($callerName) . '</a>' . ' <a href="' . htmlspecialchars($telLink) . '">' . '&#9742;</a>'; $postMsg = 'to=' . urlencode($xmppTarget) . '&type=chat' . '&body=' . urlencode($textMsg); .= '&html=' . urlencode( '<body xmlns="http://www.w3.org/1999/xhtml">' . $htmlMsg . '</body>body>' ); $ctx = stream_context_create( array( 'http' => array( 'method' => 'POST', 'header' => array( 'Content-type: application/x-www-form-urlencoded', 'Authorization: Basic ' . base64_encode($xmppUser . ':' . $xmppPass), ), 'content' => $postMsg ) ) ); file_get_contents('http://xmpp.example.org:5280/msg/', false, $ctx); ?> Have a read of http://metajack.im/2008/10/03/getting-attached-to-strophe/ Establish a session for the user to XMPP server from your server (at user login?) Then pass via "jid", "rid", sid" in HTML dynamic page - something like: converse.initialize({
  • 3.
    auto_list_rooms: false, auto_subscribe: true, bosh_service_url:'<%= session.getAttribute("bosh") %>', hide_muc_server: false, i18n: locales.en, // Refer to ./locale/locales.js to see which locales are supported prebind: true, show_controlbox_by_default: true, fullname: '<%= session.getAttribute("userid") %>', xhr_user_search: false, jid:'<%= session.getAttribute("jid") %>', sid:'<%= session.getAttribute("sid") %>', rid:'<%= session.getAttribute("rid") %>' }); converse.attach();