[Xmpp4js-commit] SF.net SVN: xmpp4js:[745] trunk/src/site/xdoc/code-samples.xml
Status: Beta
Brought to you by:
h-iverson
From: <h-i...@us...> - 2008-07-25 03:14:51
|
Revision: 745 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=745&view=rev Author: h-iverson Date: 2008-07-25 03:15:00 +0000 (Fri, 25 Jul 2008) Log Message: ----------- added link to simpleclient and demo of chatmanager Modified Paths: -------------- trunk/src/site/xdoc/code-samples.xml Modified: trunk/src/site/xdoc/code-samples.xml =================================================================== --- trunk/src/site/xdoc/code-samples.xml 2008-07-23 17:54:32 UTC (rev 744) +++ trunk/src/site/xdoc/code-samples.xml 2008-07-25 03:15:00 UTC (rev 745) @@ -5,6 +5,14 @@ </properties> <body> + + <section name="Information"> + <p>In addition to these snippets, check out the SimpleClient demo in + the <a href="https://xmpp4js.svn.sourceforge.net/svnroot/xmpp4js/xmpp4js-launcher/">xmpp4js-launcher</a> project.</p> + + + </section> + <!-- The body of the document contains a number of sections --> <section name="Core"> @@ -47,6 +55,45 @@ ]]></pre> </subsection> +<subsection name="Use Chat Manager"> +<pre name="code" class="javascript"><![CDATA[ +var cm = Xmpp4Js.Chat.ChatManager.getInstanceFor( con ); + +cm.chatManager.setOptions({ + ignoreThread: true, // useful for legacy networks (AIM) + ignoreResource: true +}); + +cm.chatManager.on({ + scope : this, + chatStarted : onChatStarted, + messageReceived : onChatMessageReceived +}); + +function onChatStarted(chat) { + alert( "Chat with "+chat.getParticipant()+" started." +} + +function onChatMessageReceived(chat, messagePacket) { + alert( "New message from "+messagePacket.getFrom()+": "+messagePacket.getBody(); +} + +function sendMessage(to, message) { + var chat = null; + try { + chat = chatManager.findBestChat( to ); + } catch(e) { + chat = chatManager.createChat( to ); + } + + var messagePacket = new Xmpp4Js.Packet.Message( to, "normal", message ); + chat.sendMessage( messagePacket ); +} + +]]></pre> +</subsection> + + <subsection name="Pause / Resume a connection"> <pre name="code" class="javascript"><![CDATA[ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |