Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add flXHR support for cross-domain BOSH support.

  • Loading branch information...
commit edd32ccb8b787f982d19b4df37ca697c1e8824a5 1 parent 104ea3d
@metajack authored
View
32 examples/crossdomain.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>Strophe.js Basic Cross-Domain Example</title>
+
+ <script type='text/javascript'
+ src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js'></script>
+ <script type='text/javascript'
+ src='http://flxhr.flensed.com/code/build/flXHR.js'></script>
+
+ <script type='text/javascript'
+ src='../strophe.js'></script>
+ <script type='text/javascript'
+ src='../plugins/strophe.flxhr.js'></script>
+
+ <script type='text/javascript'
+ src='crossdomain.js'></script>
+</head>
+<body>
+ <div id='login' style='text-align: center'>
+ <form name='cred'>
+ <label for='jid'>JID:</label>
+ <input type='text' id='jid' />
+ <label for='pass'>Password:</label>
+ <input type='password' id='pass' />
+ <input type='button' id='connect' value='connect' />
+ </form>
+ </div>
+ <hr />
+ <div id='log'></div>
+</body>
+</html>
View
62 examples/crossdomain.js
@@ -0,0 +1,62 @@
+// The BOSH_SERVICE here doesn't need to be on the same domain/port, but
+// it must have a /crossdomain.xml policy file that allows access from
+// wherever crossdomain.html lives.
+//
+// Most BOSH connection managers can serve static html files, so you should
+// be able to configure them to serve a /crossdomain.xml file to allow
+// access.
+var BOSH_SERVICE = 'http://localhost:5281/xmpp-httpbind'
+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)
+{
+ 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(BOSH_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();
+ }
+ });
+});
View
12 examples/crossdomain.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
+<cross-domain-policy>
+ <!--
+ Cross domain policy file for allow everything. If you need more
+ information on these, please see:
+ http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html
+ -->
+ <site-control permitted-cross-domain-policies="all"/>
+ <allow-access-from domain="*" />
+ <allow-http-request-headers-from domain="*" headers="*" />
+</cross-domain-policy>
View
31 plugins/strophe.flxhr.js
@@ -0,0 +1,31 @@
+/* flXHR plugin
+**
+** This plugin implements cross-domain XmlHttpRequests via an invisible
+** Flash plugin.
+**
+** In order for this to work, the BOSH service *must* serve a
+** crossdomain.xml file that allows the client access.
+**
+** flXHR.js should be loaded before this plugin.
+*/
+
+Strophe.addConnectionPlugin('flxhr', {
+ init: function () {
+ // replace Strophe.Request._newXHR with new flXHR version
+ // if flXHR is detected
+ if (flensed && flensed.flXHR) {
+ Strophe.Request.prototype._newXHR = function () {
+ var xhr = new flensed.flXHR({
+ autoUpdatePlayer: true,
+ instancePooling: true,
+ noCacheHeader: false});
+ xhr.onreadystatechange = this.func.prependArg(this);
+
+ return xhr;
+ };
+ } else {
+ Strophe.error("flXHR plugin loaded, but flXHR not found." +
+ " Falling back to native XHR implementation.");
+ }
+ }
+});
Please sign in to comment.
Something went wrong with that request. Please try again.