Author: lindner Date: Fri Jan 1 18:56:18 2010 New Revision: 895054 URL: http://svn.apache.org/viewvc?rev=895054&view=rev Log: SHINDIG-1249 | Patch from Tim Thelin | Allow a container to publish messages to gadgets using pubsub
Added: incubator/shindig/trunk/javascript/samplecontainer/examples/ContainerPublish.xml Modified: incubator/shindig/trunk/features/src/main/javascript/features/pubsub/pubsub-router.js incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.html incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.js Modified: incubator/shindig/trunk/features/src/main/javascript/features/pubsub/pubsub-router.js URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/main/javascript/features/pubsub/pubsub-router.js?rev=895054&r1=895053&r2=895054&view=diff ============================================================================== --- incubator/shindig/trunk/features/src/main/javascript/features/pubsub/pubsub-router.js (original) +++ incubator/shindig/trunk/features/src/main/javascript/features/pubsub/pubsub-router.js Fri Jan 1 18:56:18 2010 @@ -37,7 +37,7 @@ function router(command, channel, message) { var gadgetId = this.f; - var sender = gadgetIdToSpecUrl(gadgetId); + var sender = gadgetId === '..' ? 'container' : gadgetIdToSpecUrl(gadgetId); if (sender) { switch (command) { case 'subscribe': @@ -101,6 +101,15 @@ } gadgetIdToSpecUrl = gadgetIdToSpecUrlHandler; gadgets.rpc.register('pubsub', router); + }, + + /** + * Publishes a message to a channel. + * @param {string} channel Channel name. + * @param {string} message Message to publish. + */ + publish: function(channel, message) { + router.call({f: '..'}, 'publish', channel, message); } }; }(); Added: incubator/shindig/trunk/javascript/samplecontainer/examples/ContainerPublish.xml URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/samplecontainer/examples/ContainerPublish.xml?rev=895054&view=auto ============================================================================== --- incubator/shindig/trunk/javascript/samplecontainer/examples/ContainerPublish.xml (added) +++ incubator/shindig/trunk/javascript/samplecontainer/examples/ContainerPublish.xml Fri Jan 1 18:56:18 2010 @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Module> + <ModulePrefs title="Container Publish Example"> + <Require feature="pubsub"></Require> + </ModulePrefs> + + <Content type="html" view="default"> + <![CDATA[ + <div>Container Message: <span id="message_display"></span></div> + + <script type="text/javascript"> + function handleHelloWorld(sender, message) { + document.getElementById('message_display').appendChild( + document.createTextNode(message)) + } + + gadgets.pubsub.subscribe('helloworld', handleHelloWorld); + </script> + ]]> + </Content> +</Module> Modified: incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.html URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.html?rev=895054&r1=895053&r2=895054&view=diff ============================================================================== --- incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.html (original) +++ incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.html Fri Jan 1 18:56:18 2010 @@ -51,7 +51,7 @@ </style> -<script type="text/javascript" src="../../js/core:rpc?debug=1"></script> +<script type="text/javascript" src="../../js/core:rpc:pubsub?c=1&debug=1"></script> <script type="text/javascript" src="../container/cookies.js"></script> <script type="text/javascript" src="../container/util.js"></script> <script type="text/javascript" src="../container/gadgets.js"></script> @@ -87,6 +87,7 @@ <input type="button" value="reset all" onclick="shindig.samplecontainer.changeGadgetUrl();"/> <input type="button" value="dump state" onclick="shindig.samplecontainer.dumpStateFile();"/> + <input type="button" value="Send Hello" onclick="shindig.samplecontainer.sendHello();"/> </div> <div style="clear:both; height: 1px;"> </div> </div> Modified: incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.js URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.js?rev=895054&r1=895053&r2=895054&view=diff ============================================================================== --- incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.js (original) +++ incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.js Fri Jan 1 18:56:18 2010 @@ -209,6 +209,7 @@ if (cacheUrlMatches && cacheUrlMatches[1] == "0") { document.getElementById("useCacheCheckbox").checked = false; } + gadgets.pubsubrouter.init(function() { return gadgetUrl; }); }; shindig.samplecontainer.initGadget = function() { @@ -273,6 +274,10 @@ ); }; + shindig.samplecontainer.sendHello = function() { + gadgets.pubsubrouter.publish('helloworld', 'hello from the container'); + }; + osapi.messages = {}; osapi.messages.requestSend = function(request, callback) { alert("osapi.messages.requestSend called");