0 Replies Latest reply on Aug 28, 2013 9:18 PM by ThuaChi

    I have problem with this script

    ThuaChi Level 1

      From AMS 5 extended license i put an application push RTMP to p2p.rtmfp.net

       

      then i play from player, it play just about 1 minutes.

       

      Any people tell me this happen?

       

      thanks

       

      Here is my code:

       

       

      application.onAppStart = function() {

          /**

           * Map of group to file name

           */

          application.startTimes = {};

      };

       

       

      application.onConnect = function(client) {

          client.startMatch = function(groupName, matchNo) {

             

          };

          application.acceptConnection(client);

      };

       

       

      application.onPublish = function(client, stream) {

          trace("Handing publish and record request for source stream: " +

                stream.name);

          var nc = new NetConnection();

          nc.onStatus = function(info) {

              netConnectionStatusHandler(nc, info, stream);

          };

          nc.connect("rtmfp://p2p.rtmfp.net/","0f2cce55809a179a454bedae-e99743f11ee7");

      };

       

       

      function netConnectionStatusHandler(nc, info, stream) {

          trace("Multicast NetConnection Status: " + info.code);

          switch (info.code) {

          case "NetConnection.Connect.Success":

              initMulticastNetStream(nc, info, stream);

              break;

          case "NetConnection.Connect.Failed":

          case "NetConnection.Connect.Rejected":

          case "NetConnection.Connect.AppShutdown":

              trace("Multicast publish error: " + info.code +

                    ", description: " + info.description);

              break;

          case "NetConnection.Connect.Closed":

              trace("Multicast publish closed: " + info.code +

                    ", description: " + info.description);

              break;

       

                case "NetStream.Connect.Success": // e.info.stream

       

                                                        case "NetStream.Connect.Rejected": // e.info.stream

                                                        case "NetStream.Connect.Failed": // e.info.stream

                                                        case "NetGroup.Connect.Success": // e.info.group

                                                        case "NetGroup.Connect.Rejected": // e.info.group

                                                        case "NetGroup.Connect.Failed": // e.info.group

                                                        case "NetGroup.Posting.Notify": // e.info.message, e.info.messageID

                                                        case "NetStream.MulticastStream.Reset":

                                                        case "NetStream.Buffer.Full":

                                                        case "NetGroup.SendTo.Notify": // e.info.message, e.info.from, e.info.fromLocal

                                                        case "NetGroup.LocalCoverage.Notify": //

                                                        case "NetGroup.Neighbor.Connect": // e.info.neighbor

                                                        case "NetGroup.Neighbor.Disconnect": // e.info.neighbor

                                                        case "NetGroup.MulticastStream.PublishNotify": // e.info.name

                                                        case "NetGroup.MulticastStream.UnpublishNotify": // e.info.name

                                                        case "NetGroup.Replication.Fetch.SendNotify": // e.info.index

                                                        case "NetGroup.Replication.Fetch.Failed": // e.info.index

                                                        case "NetGroup.Replication.Fetch.Result": // e.info.index, e.info.object

                                                        case "NetGroup.Replication.Request": // e.info.index, e.info.requestID

                                                        default:

                                                                  break;

        

          }

      }

       

       

      function initMulticastNetStream(nc, info, stream) {

          var groupSpec = new GroupSpecifier("com.onstream.p2p.0f2cce55809a179a454bedae-e99743f11ee7/"+stream.name);

          groupSpec.serverChannelEnabled = true;

          groupSpec.multicastEnabled = true;

                groupSpec.postingEnabled = true;

          var ns = new NetStream(nc, groupSpec.groupspecWithAuthorizations());

                ns.client = this;

                /*var netGroup = new NetGroup(nc, groupSpec.groupspecWithAuthorizations());*/

          ns.onStatus = function(info) {

              netStreamStatusHandler(info, stream, ns);

          }

      }

       

       

      function netStreamStatusHandler(info, stream, ns) {

          trace("NetStream status: " + info.code + " and stream name is " + stream.name);

          // TODO: maybe, uh, do different things here depending on value? who knows!

          if (info.code == "NetStream.Connect.Success") {

              trace('attaching and publishing stream.');

              if (!ns.attach(stream)) {

                  trace("Failed to attach to multicast");

                  return;

              }

       

              ns.publish("stream","live");

          }

      }

       

       

      /**

      * Parses the supplied query string, and if valid, returns an Object populated

      * with the name-value pairs contained in the query string. The simple processing

      * here does not preserve multiple name-value pairings having the same name; the

      * last value seen wins. Parameters with no value are mapped to "" (empty String)

      * in the returned Object.

      *

      * @param queryString - A query string portion of a URI, not including the leading

      *                     '?' character.

      * @return An Object containing a key-value mapping for each name-value parameter

      *         defined in the query string; Object is empty if the query string is

      *         invalid.

      */

      function parseQueryString(queryString) {

          var result = {};

          var decoded = "";

       

       

          try {

              decoded = decodeURIComponent(queryString);

          }

          catch (e) {

              return result;

          }

       

       

          if (decoded.length) {

              var params = decoded.split('&');

              for (var i in params) {

                  var pair = params[i];

                    var sepIndex = pair.indexOf('=');

                  if (sepIndex != -1) {

                      var name = pair.substr(0, sepIndex);

                      result[name] = pair.substr(sepIndex + 1);

                  }

                  else

                      result[pair] = "";

              }

          }

       

       

          return result;

      }