9 Replies Latest reply: May 27, 2010 1:04 AM by Authentic Sols RSS

    How to detect if any peer gets disconnected

    Authentic Sols

      Hi,

      When a subsribing peer tries to connect to the publishing peer to play the stream, the callback method "onPeerConnect" is executed automatically. But what if any peer (i.e. publishing or subscribing) gets disconnected due to any reason? is there any callback function that is triggered automatically in that case also?

       

      Thanks in advance.

        • 1. Re: How to detect if any peer gets disconnected
          RGBEFFECTS

          I had your same problem & this is how I solved it:

           

          Once the application is activated, each client (SWF) makes a call to the database every 10 seconds (you can decide your own timeframe) & updates their record with a fresh timeStamp. If the client stops making calls to the database, the timeStamp gets old & is cleared out by another job that runs every few minutes (you can decide your own timeframe) if its timeStamp is older than 2 minutes.

           

          This has been very effective for me & my team to keep an accurate listing of active user IDs.

           

          Hope this helps,

          RGB

          • 2. Re: How to detect if any peer gets disconnected
            Ethan Rom

            I've also been working on disconect detection and reconnection (where possible).

            I hope there's a way to detect a disconnect using only stratus.

             

            Here's what I have so far and I hope someone else can shed more light on this.

             

            It looks like a couple events get fired when a disconnect happens.

             

            NetStream.Connect.Closed

            if you have this set you will see it ...

            netConnection.addEventListener(NetStatusEvent.NET_STATUS,blahlbah

             

            and

             

            NetStream.Play.UnpublishNotify

            seems to fire when other peer's outNetStream closes

             

            I hope someone from Adobe can give us more info.

            A user disconnect event is about as basic as it gets for this kind of stuff.

            • 3. Re: How to detect if any peer gets disconnected
              Mahron Community Member

              Hi,

               

              you need to use the netstatus listener on the netconnection.

               

              "NetStream.Connect.Closed" is fired on disconnection.

               

              You can than check the farID with  -   info.stream.farID.

               

              You can also check if the netstream is the correct one by comparing the clients   -   if(event.info.stream.client==NetStrm.client){}

               

               

               

               

               

              netconnection.addEventListener(NetStatusEvent.NET_STATUS,OnStreamStatus,false,0,true)

               

              NetStrm = new NetStream(netconnection,peerid)

               

              public function OnStreamStatus(event:NetStatusEvent):void

              {

               

               

               

                   if(event.info.code=="NetStream.Connect.Closed")

                   {

                        if(event.info.stream.client==NetStrm.client)

                        {

                             CurrentPeerId = data.info.stream.farID

                             dispatchEvent(OnDisconnected)

                        }

               

                   }

               

               

              }

              • 4. Re: How to detect if any peer gets disconnected
                Ethan Rom Community Member

                That is how I'm doing it too.

                However it seems to be unreliable since sometimes after that event fires the two peers are still connected and can still send messages to each other.

                 

                For me it means that the peer "might" have disconnected so I need to ping it.

                 

                Does anyone know why that would fire that event when the peers are still connected?

                • 5. Re: How to detect if any peer gets disconnected
                  Mahron Community Member

                  Are you 100% sure that it is the correct netstream(with the farid of one of the  two peers) which is disconnected and not an other one using the same netconnection ?

                  • 6. Re: How to detect if any peer gets disconnected
                    FMSer.cn Community Member

                    Mahron is right.

                    • 7. Re: How to detect if any peer gets disconnected
                      Michael Thornburgh Adobe Employee

                      yes.  Mahron is correct.

                       

                      a NetStream.Connect.Closed NetStatusEvent.NET_STATUS event will be dispatched to the NetConnection.  event.info.stream will be the per-peer sub-NetStream for the specific peer that disconnected.  event.info.stream.farID is the peerID of that peer.

                      • 8. Re: How to detect if any peer gets disconnected
                        Ethan Rom Community Member

                        Here's is more detailed disconnection info I've found to work anecdotally.

                        Could someone from Adobe please confirm that this is correct.

                        I think this kind of disconnect/reconnect info should be in the NetStream/NetConnetion docs/tuts.

                         

                         

                        Each peer has an inStream and an outStream, I can detect the following 4 disconnection events:

                        a) My Peer's inStream has disconnected  : onInNetStreamStatus NetStream.Play.Stop

                        b) My Peer's outStream has disconnected : onOutNetStreamStatus NetStream.Play.Stop

                        c) Remote Peer's inStream has disconnected   :  onNetConnectionStatus NetStream.Connect.Closed //if(event.info.stream != inNetStream

                        d) Remote Peer's outStream has disconnected  : onNetConnectionStatus NetStream.Connect.Closed //if(event.info.stream == inNetStream

                        • 9. Re: How to detect if any peer gets disconnected
                          Authentic Sols Community Member

                          Well - neither the veents for NetConnection nor the Netstreams are fired when the user closes the browser or something like that. Then how to detect that the peer has gone away?