10 Replies Latest reply on Aug 3, 2010 7:04 AM by michael.penwell

    OSMF, client/server NetStream communication

    mattparisi

      Hi, I'm currently using the OSMF framework with my video player.  I have a requirement that the server side NetStream object sends a custom message to the client side NetStream object using NetStream.send().  I'm not quite sure how this would be implemented using the framework.  Could someone offer any insights?

       

      Thanks!

       

      Matt

        • 1. Re: OSMF, client/server NetStream communication
          bringrags Level 4

          I believe you would need to subclass NetLoader, override createNetStream, and gain access to the NetStream there.  This would allow you to either call NetStream.send() or add a handler to the NetStream.  But this is at a high-level, there may be a better way depending on what you're trying to accomplish with NetStream.send().

          • 2. Re: OSMF, client/server NetStream communication
            mattparisi Level 1

            I'd like to add this functionality across the entire framework without using a plugin.  Is this the correct approach?  Should I be creating a plugin just for this functionality?  That doesn't seem feasible to me.  Here's a summary of what I'm trying to accomplish:

             

            We have a system where an audience member watches a presentation that consists of a video or audio stream along with powerpoint slides that get "flipped" at the discretion of a production team which manages the presentation.  When the production team clicks the "Push Slide" button, it triggers the NetStream object on the server to call send("FunctionName") and all subscribing clients should receive the message.

             

            If your approach is the correct approach, how would I ensure that all streaming protocols listen for this message?  Plugin?

             

            Thanks.

             

            matt

            • 3. Re: OSMF, client/server NetStream communication
              bringrags Level 4

              Whether to create a plugin or not depends on the overall requirements and design of your system.  Keep in mind that anything you can do with a plugin, you can also do in a standalone player.  For example, your plugin could use a NetLoader subclass to invoke NetStream.send(), or the player app could use the NetLoader subclass directly.  The former makes it easier for player integration, the latter would make sense if you're just trying to get it working your own player and don't care about distribution.

               

              As for the slide use case, it depends on what the clients need to do in response to the "flip" message.  When the client receives this event, do they need to take some action to fetch the next slide?  Or is the event solely informational?  Does the problem boil down to "how does my VideoElement subclass gain access to the NetStream so that it can add a handler for the send event"?  Is it sufficient for the client to gain access to the NetStream.client object (I don't know if the send event gets invoked on the client or on the NetStream)?

              • 4. Re: OSMF, client/server NetStream communication
                mattparisi Level 1

                Here's more specifically what needs to happen:

                 

                In VideoElement, there's a method processReadyState().  I would simply need to add 2 lines to this function:

                 

                NetClient(stream.client).addHandler("ScriptCommand", handleScriptCommand);

                NetClient(stream.client).addHandler("KillStream", handleKillStream);

                 

                and add the following handlers:

                 

                public function handleScriptCommand(cmd:String):void

                {

                     var cmd:String = obj.info["cmd"]

                     var event:DataEvent = new DataEvent("script.command" ,false,false,cmd);

                     dispatchEvent(event);

                 

                }

                public function handleKillStream(cmd:String):void

                {

                     _stream.close();

                }

                 

                The script.command event needs to be heard in my main controller, so i could probably just add an eventlistener on my MediaElement correct?  I'm still trying to wrap my head around the best approach.  I feel like it's too minor a change to be creating a plugin.  Does this code snip change anything about what you said earlier?

                • 5. Re: OSMF, client/server NetStream communication
                  bringrags Level 4

                  I would still create a subclass of VideoElement, override processReadyState, add the two statements you need, call super.processReadyState, and that' should do it.

                   

                  You can have the handlers dispatch a custom event if you know you'll be working with your VideoElement subclass directly (as opposed to a composite or proxy element that wraps up your class).

                  • 6. Re: OSMF, client/server NetStream communication
                    mattparisi Level 1

                    Thanks.  I still have one more question.  So, in the past I've only worked within a custom plugin, so my custom VideoElement was created and passed into the MediaFactoryItem class in my PluginInfo class.  I'm not sure how to go about this outside of a plugin..  Could you point me in the right direction.

                    • 7. Re: OSMF, client/server NetStream communication
                      bringrags Level 4

                      You can create a MediaFactoryItem and add it to MediaFactory (via addItem). Keep in mind that if you add it to a MediaFactory that already supports video (e.g. DefaultMediaFactory), then the MediaFactory will potentially pick the wrong one.  One way around this is to remove the existing one (via removeItem) so that there's no possibility of it being selected.

                       

                      Or even simpler, just directly instantiate your custom VideoElement (instead of calling MediaFactory.createMediaElement).

                      • 8. Re: OSMF, client/server NetStream communication
                        mattparisi Level 1

                        I thought the reason for using a MediaFactory is to let the framework decide which type of MediaElement to use?  If I directly instantiate my custom VideoElement, aren't I then forcing all requested media to use this custom VideoElement?  This isn't desired behavior.  Maybe I missed something...

                        • 9. Re: OSMF, client/server NetStream communication
                          bringrags Level 4

                          Yes, the MediaFactory allows the framework to decide which MediaElement best handles a resource.  If you want to support native VideoElements and your custom VideoElement, then you can add a separate MediaFactoryItem for your custom VideoElement.  (I thought you were just trying to replace the default.)  The key in this case is to specify something on the resource that will allow your item to know that its a video resource that it should handle.  There are quite a few ways to do this.

                          • 10. Re: OSMF, client/server NetStream communication
                            michael.penwell

                            Matt,

                             

                            Were you able to get this working? If so, any chance you could share a code sample of your subclassed VideoElement? We are trying to accomplish pretty much the same thing and I would like to see how you got this to work.

                             

                            Regards,

                            - michael

                             

                            UPDATE: I got this working. It was actually pretty straight forward with the help from above.