Hi,
I've been coding own implementation of BOSH for Ajax-capable web
browsers.
First design rule is to make it functional, then optimize it.
Optimization of course covers both amount of JS code running in browser,
and in-wire optimization of data traffic.
First pipelining:
As XEP-0124 states, in principle, it's possible to use http-pipelining
and so just one http/https connection to BOSH. Unfortunately this seems
impossible due the nature of current browsers.
In Firefox pipelining could be enabled but programmable use of it is
very hard, if impossible. I couldn't find any good references of
succesfull implementations.
For other browsers things get even more hairy. Outside browsers this is
likely possible but outside this scope.
The fallback is of course to use two (or up to max permitted by BOSH
server) connections but this increases BOSH server load considerably,
especially if https is used to secure connection (and in some cases to
deflate downlink data).
Someone was considering http chunking for comet to stick in single
connection and improve 2-way comms.
Is there any JS examples or references to handle (BOSH-) sockets the
most efficient way, ultimately with single XMLHttpRequest connection ?
Then in-wire and JS-side optimization:
Parsing XML in JS is possible but unnecessarily complicates stanza
handling and adds up considerably amount of JS code running in browser.
My decision was to convert stanzas to JS-object for (much) easier
processing later on. This happens of course for both directions.
Because of nature of XMPP stanzas, and my goal to avoid use of existing
and more generic libraries for xml (or BOSH) ended up to following kind
of stanza representation:
--- XMPP ---
<iq type='set' id='bind_2'>
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
<resource>someresource</resource>
</bind>
</iq>
--- JS-object ---
{ iq: { _iq: { type: "set", id: "bind_2" },
bind: { _bind: { xmlns: "urn:ietf:params:xml:ns:xmpp-bind" },
resource: "someresource"
}
}
}
---
Writing parser for JS-object above was not too complicated. Actually it
would be much nicer to have BOSH server to support both Content-Type:
'text/xml; charset=utf-8' and 'application/json' directly.
Best approach might be to try json content type with session creation
request and if not supported then (load JS and) use fall-back method of
xml representation with object-xml conversion.
Any comments about that ?
Cheers,
-Mika