[Xmpp4js-commit] SF.net SVN: xmpp4js:[743] trunk/src
Status: Beta
Brought to you by:
h-iverson
From: <h-i...@us...> - 2008-07-23 17:12:01
|
Revision: 743 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=743&view=rev Author: h-iverson Date: 2008-07-23 17:12:07 +0000 (Wed, 23 Jul 2008) Log Message: ----------- cleaned up the code a bit, added pause/resume listeners, updated example Modified Paths: -------------- trunk/src/main/javascript/XmppConnection.js trunk/src/main/javascript/transport/Base.js trunk/src/site/xdoc/code-samples.xml Modified: trunk/src/main/javascript/XmppConnection.js =================================================================== --- trunk/src/main/javascript/XmppConnection.js 2008-07-23 16:49:45 UTC (rev 742) +++ trunk/src/main/javascript/XmppConnection.js 2008-07-23 17:12:07 UTC (rev 743) @@ -54,7 +54,11 @@ * @param {String} title * @param {String} message */ - error: true + error: true, + + pause: true, + + resume: true }); /** @@ -107,7 +111,32 @@ termerror: this.onTerminalError, error: this.onError, beginsession: this.onBeginSession, - endsession: this.onEndSession + endsession: this.onEndSession, + pause: function(pauseStruct) { + // serialize our junk (domain is covered by transport) + pauseStruct.jid = this.jid; + + // stop doing stuff + // will this cause problems collecting any last packet? + this.connected = false; + this.transport.un("recv", this.onRecv, this ); + + this.fireEvent( "pause", pauseStruct ); + }, + resume: function(pauseStruct) { + // deserialize our junk + this.domain = pauseStruct.domain; + this.jid = pauseStruct.jid; + + // return to connected state + this.connected = true; + this.transport.on({ + scope: this, + recv: this.onRecv + }); + + this.fireEvent( "resume", pauseStruct ); + } // recv will be added in beginSession. } }); @@ -295,14 +324,6 @@ // serialize transport's junk var pauseStruct = this.transport.pause(time); - // serialize our junk (domain is covered by transport) - pauseStruct.jid = this.jid; - - // stop doing stuff - // will this cause problems collecting any last packet? - this.connected = false; - this.transport.un("recv", this.onRecv, this ); - return pauseStruct; }, @@ -317,17 +338,6 @@ // deserialize transport's junk this.transport.resume(pauseStruct); - - // deserialize our junk - this.domain = pauseStruct.domain; - this.jid = pauseStruct.jid; - - // return to connected state - this.connected = true; - this.transport.on({ - scope: this, - recv: this.onRecv - }); } } Modified: trunk/src/main/javascript/transport/Base.js =================================================================== --- trunk/src/main/javascript/transport/Base.js 2008-07-23 16:49:45 UTC (rev 742) +++ trunk/src/main/javascript/transport/Base.js 2008-07-23 17:12:07 UTC (rev 743) @@ -201,7 +201,11 @@ * Raised when the session has been closed (voluntarily). Client code * should remove any recv handlers here (should we forcibly remove all?). */ - endsession: true + endsession: true, + + pause: true, + + resume: true }); Xmpp4Js.Transport.Base.superclass.constructor.call( this, superConfig ); @@ -513,6 +517,9 @@ keySeqIdx: this.keySeq._idx }; + // give others an opportunity to serialize proprties + this.fireEvent( "pause", pauseStruct ); + return pauseStruct; }, @@ -535,6 +542,9 @@ this.keySeq._idx = pauseStruct.keySeqIdx; this.startup(); + + // give others an opportunity to deserialize properties + this.fireEvent( "resume", pauseStruct ); } } Modified: trunk/src/site/xdoc/code-samples.xml =================================================================== --- trunk/src/site/xdoc/code-samples.xml 2008-07-23 16:49:45 UTC (rev 742) +++ trunk/src/site/xdoc/code-samples.xml 2008-07-23 17:12:07 UTC (rev 743) @@ -49,31 +49,38 @@ <subsection name="Pause / Resume a connection"> <pre name="code" class="javascript"><![CDATA[ -// running all content at once will not work. I might update this to add listeners -// and the like someday. until then, use firebug's console and run these 1-by-1. -// 1, 6 +// setup +LOGIN = "test"; +PASSWORD = "test"; +SEND_MSG_TO = "ha...@so..."; +BOSH_TRANSPORT = Xmpp4Js.Transport.Script; +BOSH_ENDPOINT = "http://bosh*.soashable.com:7070/http-bind/"; + +// 1, 4 sp = new Xmpp4Js.Packet.StanzaProvider(); sp.registerDefaultProviders(); con = new Xmpp4Js.Connection({transport: {clazz: BOSH_TRANSPORT,endpoint:BOSH_ENDPOINT,useKeys:true},stanzaProvider:sp}); +con.on( "pause", function(pauseStruct) { ps = pauseStruct; console.dir( ps ); } ); +con.on( "resume", function(pauseStruct) { + con.send( new Xmpp4Js.Packet.Message( SEND_MSG_TO, "normal", "yoooo I'm alive" ) ); +}); +con.on( "connect", function() { + loginFlow = new Xmpp4Js.Workflow.Login({con:con}); + loginFlow.on("success", function() { + con.send( new Xmpp4Js.Packet.Presence() ); + } ); + loginFlow.start( "plaintext", LOGIN, PASSWORD ); +}); // 2 con.connect("soashable.com"); -// 3 -loginFlow = new Xmpp4Js.Workflow.Login({con:con});loginFlow.start( "plaintext", "test", "test" ); +// 3 - pause for up to 120 seconds +con.pause( 120 ); -// 4 -con.send( new Xmpp4Js.Packet.Presence() ); - -// 5 -ps = con.pause( 120 ); - -// 7 +// 5 - you should receive an IM con.resume( ps ); - -// 8 -con.send( new Xmpp4Js.Packet.Message( "ha...@so...", "normal", "yoooo I'm alive" ) ); ]]></pre> </subsection> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |