AMS does not receive the unpublished SOMETIMES over rtmpt command

I had at least a week. I am trying to record a video file in AMS. It works fine almost all the time, with the exception of 1 out of 10 or 15 recording sessions, I never get "NetStream.Unpublish.Success" in my network stream from AMS when I close the stream. I connect to AMS using rtmpt, when this happens, it seems to work fine on rtmp. Also, it looks like this only happens on Mac safari, but since it's so choppy, I don't believe it. Here is my main thread:

// just a way to use promises with netStatusEvents private function netListener(code:String, netObject:*):Promise { var deferred:Deferred = new Deferred(); var netStatusHandler:Function = function (event:NetStatusEvent):void { if (event.info.level == 'error') { deferred.reject(event); } else if (event.info.code == code) { deferred.resolve(netObject); // we want this to be a one time listener since the connection can swap between record/playback netObject.removeEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); } }; netObject.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); return deferred.promise; } // set up for recording private function initRecord():void { Settings.recordFile = Settings.uniquePrefix + (new Date()).getTime(); // detach any existing NetStream from the video _view.video.attachNetStream(null); // dispose of existing NetStream if (_videoStream) { _videoStream.dispose(); _videoStream = null; } // disconnect before connecting anew (_nc.connected ? netListener('NetConnection.Connect.Closed', _nc) : Promise.when(_nc)) .then(function (nc:NetConnection):void { netListener('NetConnection.Connect.Success', _nc) .then(function (nc:NetConnection):void { _view.video.attachCamera(_webcam); // get new NetStream _videoStream = getNetStream(_nc); ExternalInterface.call("CTplayer." + Settings.instanceName + ".onRecordReady", true); }, function(error:NetStatusEvent):void { ExternalInterface.call("CTplayer." + Settings.instanceName + ".onError", error.info); }); _nc.connect(Settings.recordServer); }); // end ncClose if (_nc.connected) _nc.close(); } // stop recording private function stop():void { netListener('NetStream.Unpublish.Success', _videoStream) .then(function (ns:NetStream):void { ExternalInterface.call("CTplayer." + Settings.instanceName + ".onRecordStop", Settings.recordFile); }); _videoStream.attachCamera(null); _videoStream.attachAudio(null); _videoStream.close(); } // start recording private function record():void { netListener('NetStream.Publish.Start', _videoStream) .then(function (ns:NetStream):void { ExternalInterface.call("CTplayer." + Settings.instanceName + ".onRecording"); }); _videoStream.attachCamera(_webcam); _videoStream.attachAudio(_microphone); _videoStream.publish(Settings.recordFile, "record"); // fires NetStream.Publish.Success } 

Update Now I use a new attempt to NetConnection for each connection, and also do not force port 80 (see My "answer" below). This did not solve my connection problems, only made cases more infrequent. Now, like every week or so, I still have a random ams or flash crash. Most recently, someone made a recording, and then the flash player was not able to download the video for playback. Ams logs show an attempt to connect, and then nothing. At the very least, there should be a replay event registered to load metadata. It is quite difficult and impossible to debug.

+6
source share
2 answers

I would try two different NetConnection objects, one for recording and one for playback. This will eliminate the difficulties associated with adding / removing listeners, connecting / reconnecting / disconnecting logic, and whether IMO will be cleaner. NetConnections is cheap, and I always used one on one task. Another advantage is that you can connect both at startup and the playback connection is ready instantly.

I have not seen the promises used here before, but I have no right to comment on whether this can cause a problem or not.

0
source

I think my problem is with port 80. Initially, it seemed to me that I needed to use port 80 with rtmpt, so I set the Settings.recordServer variable to rtmpt://myamsserver.net:80/app . Now I use the shotgun approach, where I immediately launch a group of ports / protocols and select the first one to connect. He almost always chooses port 443 compared to rtmpt, which looks much faster and more stable by only 80, and since then I have not had this problem. This could also be due to the fact that reusing the same NetConnection object as Stefan suggested is difficult to say.

0
source

Source: https://habr.com/ru/post/978649/


All Articles