Expand my Community achievements bar.

Multiple CollectionNodes with one SharedID in one app....

Avatar

Former Community Member

I'm having trouble getting multiple CollectionNodes to use the same sharedID but different Nodes.

It looks like the first CollectionNode to try and create a node on a sharedID, succeeds and the rest fail. The documentation for SharedObject refers to "piggybacking", so it must be possible to do what I'm trying to do.

Any direction in helping me get this working would be greatly appreciated.

There's some sample code right here. (username/password redacted)

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <rtc:ConnectSessionContainer id="sessionContainer" width="100%" height="100%"
        roomURL="https://connectnow.acrobat.com/telecare/collectionNodeTest"
        xmlns:rtc="AfcsNameSpace">
        <rtc:authenticator>
            <rtc:AdobeHSAuthenticator userName="<username>" password="<password>" authenticationFailure="onAuthFailure(event)" authenticationSuccess="onAuthSuccess(event)"/>
        </rtc:authenticator>
    </rtc:ConnectSessionContainer>
   
    <mx:Script>
        <![CDATA[
            import com.adobe.rtc.sharedModel.CollectionNode;
            import com.adobe.rtc.events.CollectionNodeEvent;
            import com.adobe.rtc.messaging.NodeConfiguration;
            import com.adobe.rtc.messaging.UserRoles;
           
            private var _fooNode:CollectionNode;
            private var _barNode:CollectionNode;
           
            private var _sharedID:String = "CollectionNodeTest";
           
            private function onAuthFailure(event:Event) : void {
               
            }
            private function onAuthSuccess(event:Event) : void {
                subscribeFoo();
                subscribeBar();
            }
           
            private function subscribeBar() : void {
                _barNode = new CollectionNode();
                _barNode.sharedID = _sharedID ;
                _barNode.connectSession = sessionContainer;
                _barNode.addEventListener(CollectionNodeEvent.SYNCHRONIZATION_CHANGE, barSync);
                _barNode.subscribe();
            }
           
            private function barSync(event:CollectionNodeEvent) : void {
                if( _barNode.isSynchronized ) {
                    if( !_barNode.isNodeDefined("bar") ) {
                        var config:NodeConfiguration = new NodeConfiguration();
                        config.accessModel = UserRoles.VIEWER;
                        config.publishModel = UserRoles.VIEWER;
                        config.persistItems = true;
                        config.modifyAnyItem = true;
                        config.userDependentItems = false;
                        config.sessionDependentItems = false;
                        config.itemStorageScheme = NodeConfiguration.STORAGE_SCHEME_SINGLE_ITEM;
                        config.allowPrivateMessages = false;
                        _barNode.createNode("bar", config);
                    }
                }                                       
            }           
           
            private function subscribeFoo() : void {
                _fooNode = new CollectionNode();
                _fooNode.sharedID = _sharedID ;
                _fooNode.connectSession = sessionContainer;
                _fooNode.addEventListener(CollectionNodeEvent.SYNCHRONIZATION_CHANGE, fooSync);
                _fooNode.subscribe();
            }
           
            private function fooSync(event:CollectionNodeEvent) : void {
                if( _fooNode.isSynchronized ) {
                    if( !_fooNode.isNodeDefined("foo") ) {
                        var config:NodeConfiguration = new NodeConfiguration();
                        config.accessModel = UserRoles.VIEWER;
                        config.publishModel = UserRoles.VIEWER;
                        config.persistItems = true;
                        config.modifyAnyItem = true;
                        config.userDependentItems = false;
                        config.sessionDependentItems = false;
                        config.itemStorageScheme = NodeConfiguration.STORAGE_SCHEME_SINGLE_ITEM;
                        config.allowPrivateMessages = false;
                        _fooNode.createNode("foo", config);
                    }
                }                                       
            }
        ]]>
    </mx:Script>       
</mx:Application>

10 Replies

Avatar

Former Community Member

Hi there,

As you've discovered, having 2 collectionNodes in the player with the same

sharedID results in some funky behavior. We should likely add an RTE to make

this more clear. When we say "piggybacking", we mean you can pass a

reference to a pre-existing collectionNode to another class and have it use

that, which will work.

Could you expand on what you're trying to do? You'd like to subscribe one

node at a time from various different places? What's the broader idea?

thanks

nigel

Avatar

Former Community Member

Aha! That makes total sense now. It's the same problem I was having when trying to write to the same collection node as the WebCamera. I'm just trying to keep all my data organized.

I'm creating various pods. The pod superclass stores its location, visibility, etc... When I create a new type of pod, I make a class that inherits from the Pod class and it just adds what it needs to that Collection. In this way the super class adds a node called "pod", if it's a pod that represents a flashcard, the flashcards class might add the word or a picture to the "flashcard" node. So, I can easily add the CollectionNode to the superclass and just use it where I need to. Sometimes though, the Pod is just a container that contains other interactive elements, so I need to pass the CollectionNode around. Not a huge deal, but not ideal either.

It looks like my best solution might be to create a CollectionNodeManager to take care of these things. It would be a singleton and I'd request a CollectionNode like this: CollectionNodeManager.getNode(sharedID), and if it already exists, it will just give me the one that exists.

Which do you think is better, pass the CollectionNode object around or make a CollectionNodeManager?

(As an aside, a mechanism like this might be nice to introduce in later releases of the API, and it should be used in the existing PODS like the WebCamera pod so that developers can better utilize them.)

The general flex SDK docs are set up so I can add a comment to them. Is there a similar version of the API doc that I can add a note to?

You guys have been a huge help, I clearly owe you a beer or three.

-sandy

Avatar

Former Community Member

Hi Sandy,

A Singleton could work, although in general the pattern doesn't get much

love these days. You could always have each pod expose a "collectionNode"

property, and have whatever instantiates the pods pass them around - makes

your code easier to reuse in the long run not to depend on a singleton being

around.

nigel

Avatar

Former Community Member

hey Nigel,

Passing around the CollectionNode it is then. In the future is it possible to add a CollectionNode property the existing pods? (Like WebCamera and SimpleChat, etc...)

Thanks again,

-sandy

Avatar

Former Community Member

Dude, chill out.

It's super easy to stop the email.

Step 1) Go to the webpage with the conversation thread on it.

Step 2) Over there on the right, up near the top is a link that says something like, "Stop sending me email". Click the link.

Step 3) Exhale slowly, it's all over now. No more emails from this thread.