diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..35ab01b --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +all: p1pp.js + +JS_FILES=\ + src/p1pp_defs.js \ + src/flash-websocket/swfobject.js \ + src/flash-websocket/web_socket.js \ + src/strophe/strophe.js \ + src/strophe/strophe.bosh.js \ + src/strophe/strophe.pubsub.js \ + src/strophe/strophe.roster.js \ + src/strophe/strophe.websocket.js \ + src/p1pp.js + +GOOGLE_CC = compiler.jar +JAVA = java + +p1pp.js: $(JS_FILES) + @cat $(JS_FILES) > p1pp.js + +p1pp.js.min: p1pp.js + @$(JAVA) -jar $(GOOGLE_CC) p1pp.js >p1pp.js.min \ No newline at end of file diff --git a/WebSocketMain.swf b/WebSocketMain.swf new file mode 100644 index 0000000..1d272b3 Binary files /dev/null and b/WebSocketMain.swf differ diff --git a/p1pp.js b/p1pp.js new file mode 100644 index 0000000..dd7f0f2 --- /dev/null +++ b/p1pp.js @@ -0,0 +1,6519 @@ +var WEB_SOCKET_DEBUG = false; +var WEB_SOCKET_DISABLE_AUTO_INITIALIZATION = true; + +var P1PP = function(params){ + this.jid= null; //for non-anonymous connections + this.password= null; // + this.connection= null; // the strophe connection + this.params= null; // merge between default params and user provided params + this.timeout_id= null; // points to the timeout function triggering the BOSH connection + //if WS connection failed + this.retries=0; // How many retries already ? + this.closing=false; + this.defaults= { + flash_location: "WebSocketMain.swf", + domain: "p1pp.net", + ws_url: "ws://p1pp.net:5280/xmpp", + bosh_url: "ws://p1pp.net:5280/http-bind", + connect_timeout: 15000, //How long should we wait before trying BOSH ? + connect_delay: 0, //Connection will not be done before this number of ms + connect_retry: 10, //Connection max attempts + rebind: true, // attempt to reuse previous connection + debug: false, // Dump traffic in console + num_old: 0, // How many old items should be fetch ? + on_strophe_event: function(){}, // Connect callback. if additional XMPP exchanges are to be done with the server. + on_login_required: null, + publish: function(){}, // User provided call back.Called everytime an event is published. + retract: function(){}, // User provided call back. Called when an item is retracted. + on_disconnected: function(){}, // User Provided callback + on_connected: function(){}, + cookie_opts: {}, + nodes: [] + }; + var merge = function (o,ob) {var i = 0;for (var z in ob) {if (ob.hasOwnProperty(z)) {o[z] = ob[z];}}return o;} + this.params = merge(this.defaults, params); + if(!this.params.pubsub_domain){ + this.params.pubsub_domain = "pubsub."+this.params.domain; + } + + var nodes = this.params.nodes; + if(nodes.length > 0){ + this.scope = MD5.hexdigest(nodes.join("-")); + } + + if (!window.console || !window.console.log || !window.console.error) { + this.console = {log: function(){ }, error: function(){ }}; + } else { + if(this.params.debug){ + this.console = window.console; + } + } + if(this.params.debug){ + window.WEB_SOCKET_DEBUG = true; + } + window.WEB_SOCKET_SWF_LOCATION=this.params.flash_location; + //initializing flash websockets (if necessary) + if(window.WebSocket && window.WebSocket.__initialize){ + window.WebSocket.__initialize(); + } + return this; +} +/** + * Connects to server and subscribes to select channels. + * @param {Object} params JSON object with configuration options (see below for attributes) + * @returns {Object} the P1PP instance used for the connection + * + *