This file contains hidden or 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
function onIq(xml) { | |
// in this case, the IQ stanzas handled are just subscription results | |
xmlDom = $(xml); | |
var iqId = xmlDom.attr('id'); | |
if (iqId == terms[0] || iqId == terms[1]) { | |
if (xmlDom.find('subscription:first').attr('subscription') == 'subscribed') { | |
console.log("Subscribed to "+iqId); | |
} | |
} | |
return true; |
This file contains hidden or 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 Collecta = { | |
subscribeSearchStanza: function(searchName) { | |
// generate XML for a search subscription on Collecta XMPP API | |
return $iq({type: 'set', from: anonymous_jid, to: 'search.collecta.com', id: searchName }) | |
.c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) | |
.c('subscribe', {node: 'search', jid: anonymous_jid}) | |
.up().c('options') | |
.c('x', {xmlns: 'jabber:x:data', type: 'submit'}) | |
.c('field', {"var": 'FORM_TYPE', type: 'hidden'}) | |
.c('value').t('http://jabber.org/protocol/pubsub#subscribe_options') |
This file contains hidden or 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
function startComparison() { | |
// creates 2 search subscriptions and send the request to Collecta XMPP API via Strophejs | |
console.log("Subscribing to nodes: "+ terms[0] +" and "+ terms[1]); | |
connection.send(Collecta.subscribeSearchStanza(terms[0]).tree()); | |
connection.send(Collecta.subscribeSearchStanza(terms[1]).tree()); | |
} |
This file contains hidden or 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
function onPresence(prs) { | |
// in this case, presence got from the XMPP server means to activate UI and allow user to enter the 2 terms to compare | |
console.log("Got presence!"); | |
anonymous_jid = $(prs).attr('to'); | |
// ... outras coisas | |
return true; | |
} |
This file contains hidden or 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
// real-time-comparison.js | |
function onConnect(status) | |
{ | |
if (status == Strophe.Status.CONNECTING) { | |
// ... outros status | |
} else if (status == Strophe.Status.CONNECTED) { | |
// adding one handler for each type of XMPP stanza | |
connection.addHandler(onPresence, null, 'presence', null, null, null); | |
connection.addHandler(onIq, null, 'iq', null, null, null); | |
connection.addHandler(onMessage, null, 'message', null, null, null); |
This file contains hidden or 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
// initiating a BOSH connection to create an anonymous connection to the Collecta XMPP server | |
connection = new Strophe.Connection(Config.BOSH_SERVICE); | |
connection.connect(Config.HOST, null, onConnect); |
This file contains hidden or 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
// config.js | |
var Config = { | |
API_KEY: 'YOUR_COLLECTA_API_KEY', | |
BOSH_SERVICE: 'http://collecta.com/xmpp-httpbind', | |
HOST: "guest.collecta.com" | |
}; |
This file contains hidden or 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
<iq type="set" id="an_id" | |
from="[email protected]/casa" | |
to="talleye.com"> | |
<query xmlns="jabber:iq:roster"/> | |
</iq> |
This file contains hidden or 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
<message to="[email protected]/escitorio" | |
from="[email protected]/casa" | |
type="chat" > | |
<body>Cadê você?</body> | |
</message> |
This file contains hidden or 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
<presence from="[email protected]/casa"> | |
<status>Ouvindo música...</status> | |
</presence> |