Is it possible to reopen closed NetConnection? - actionscript-3

I have an application that records camera and mic of users and saves it on Adobe Media Server.
The application itself works fine, but recently, I started having many cases in which the audio and video was being cut, and turns out that Flash is disconnecting from the server every once and while.
Due to how the application was designed, every time it detects a disconnection (NetConnection.Connect.Closed) that was not triggered by the user, it opens a new connections and starts recording again (using the same target file).
The problem with this workflow, is that during the period where there is no connection, nothing is recorded, causing a cut effect similar to what Youtube vloggers do.
Since I cannot migrate a stream from one connection to the other, I was thinking in calling netconnection.connect(url) to the same URL, but when I did it, nothing happened, no NetStatus event is triggered.
Is it possible to resume an interrupted recording without having to ask the user to patiently wait while a new connection is opened?
P.S.: This started be an issue recently on IE and Edge, every other browser works fine.

Yes, it is possible to reopen the connection, but that must be done outside the NetStatus event scope.
You can either use setTimeout(function(){reconnect()}, 100) or trigger another event that will do the reconnection.

Related

Using AS3 Timer & distriqt Notification ANE To Send Notifications While In Sleep Mode

I'm using the AS3 Timer class to sync data between a Flex Mobile app and a server ideally every 30 mins then send a local (distriqt) Notification to the user when action is required.
However, when the device goes into sleep / hibernate mode it seems to slow down, even stop the Timer. I've tried using a lower interval (5mins) but it still only works intermittently.
This is very hard to test as the behavior is different in debug / run modes.
Any suggestions?
Thanks.
Sounds like you might need to change your approach here. Background operation of applications is very different from the foreground.
Your application will run for a little while (depending on the current device memory load among other things) and will then enter a suspended mode, mainly to preserve the application's memory state.
There are some background mode exceptions to this, such as audio playback and location updates, however if you aren't performing these then Apple will most likely reject your application as part of the review process.
You can also investigate the executeInBackground flag on the NativeApplication. This allows a long running task to execute in the background, however this does not guarantee that the application would run in the background continuously.
You can read more here: http://blogs.adobe.com/airodynamics/2012/05/04/air-ios-background-behavior/
UIBackgroundModes: https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW22

Does Policy Request needs Delay?

My friend and i have been working on a multiplayer game in as3. Tests without policy request has successed on local, but at last we added it so we could test on the browser.
Weird stuff happened, because it managed to connect to the server, but it was needed to spam the connect button in order to start sending data.
With a timer the problem has been solved, but we dont want to wait 5 seconds in order to connect. I dont know what is wrong, and few information can be readed on the internet about this matter. Has someone experimented this issue?
It probably is because the flash game has to be loaded in the cache first from web. it may be dependent on the internet speed, the computers cache, the browser you are using , etc. same goes to every other document, flash, HTML, etc. , testing it locally gives you instant access, but opening it from web would take time
Policy request should not require you do add a delay manually, so there must be something else going on.
Even though the method is named Security.loadPolicyFile(), a policy
file isn’t loaded until a network call that requires a policy file is
issued. Calls to loadPolicyFile() simply tell Flash Player where to
look for policy files when they are needed.
You can’t receive notification of when a policy file request is
initiated or completed, and there is no reason to do so. Flash Player
performs policy checks asynchronously, and automatically waits to
initiate connections until after the policy file checks have
succeeded.
Source: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e08.html

In AS3 how can you detect if someone pulls their camera out of the USB port?

In AS3 if the SWF gets a hold of someone's camera successfully and they start streaming video across and everything, but then mid-stream, either they accidentally wiggle their camera out of the USB port, or the camera just sort of breaks down, or something else like that, how could you detect it from that user's side? I've tried using event listeners and also polling different variables every five seconds, but neither has worked; none of the public properties of Camera or its events seem to act funny at all when something like that happens. And apparently you can't just keep scanning the computer for devices (for good reason, I guess).
Is there something I'm missing here? Is there a way to detect from a user's copy of a SWF (FP or AIR, but much more importantly FP) when their camera has effectively stopped as the result of something going wrong, such as them wiggling it out of the computer by mistake? If so how? Thanks!
While you may have difficulty in detecting when the camera/microphone stops working or is deactivated, you can discern that something has gone wrong if you are publishing the video/audio to a server with a NetStream.
The NetStream has an info property which is a NetStreamInfo object. It will give you both a running total of bytes as well as a rate of bytes/second of data that the NetStream is sending to the server.
Running totals: byteCount, audioByteCount, videoByteCount
current rate in bytes/second: currentBytesPerSecond, audioBytesPerSecond, videoBytesPerSecond
If you use the running totals, you need to periodically check the byteCount and calculate your own rate. Or you can let Flash Player do all the work and use the rates that it's calculating. In the case of recording, these values give you an indication of how much data the NetStream is receiving from the camera/microphone (and going to send to the server).
We found that we could reliably determine on the client that something had gone wrong when the rate fell below 5 kilobits/second. We used the same threshold and similar calculations on an FMS server (w/custom server side Actionscript) as well.
I don't recall a proper "get camera status" call you can make on demand but you can try listening for the status event and hope there's one fired on disconnect.
If you haven't already done so, on you 5 second check try: if(myCameraObject == null) assuming var myCameraObject = Camera.GetCamera();
If you can't find a better solution, consider placing a "Detect camera" button behind the camera feed. If the camera disconnects then the user would see the button and could click it to reconnect.
You can check if the camera object is null as suggested by #ToddBFisher, check the Camera.names.length>0 or a few other properties of the camera instance (see the links below). But in each of them you'll want to check it at a regular interval.
Working with Cameras
Monitoring Camera Status

Flash crashing as VOIP client

I have a web application with three states.
Dial in — (basically, none of the below)
VOIP — Connected to a Freeswitch instance
Listen — this option is through a normal connection to an FMS instance (different server from #2).
The initial state is chosen via a pop-up when the user first enters the application. From then on, these are all controlled by a ComboBox. When it changes, the application checks for all open connections and then closes them. It then opens the appropriate new connection.
The problem is that sometimes this causes the application to freeze for 10-20 seconds, and sometimes it causes it to crash and I have no idea why. traces which should fire before the VOIP change only appear after the freeze (there will be a delay in the timestamps), but if I comment out the call to the change function, they appear in the order expected.
What is going on? Is this architecture simply not tenable? Is there a better way to do things?
Apparently... the connections were a red herring.
After looking at the results on the server, it became apparent that the problem was with placing the call to the processing functions inside of a Flex generated EventListener. The previous developer used the change="handler(event)" property which was causing the crash. When I switched over to <voip-drop-box>.addEventListener("change",function(e:Event):void{});, everything cleared up instantly.

Flash/Actionscript 3: When does flash stop rendering and how to keep active?

I have a flash/Actionscript 3 application (swf). This application sends a message to a server every 2 seconds. However, in some browsers/operating systems (for example, safari in mac), the moment the browser loses focus, it stops sending these messages.
I send these messages in a EVENT.ENTER_FRAME loop, so every time the application is rendered I have the chance to send a message. My theory is that some browsers apperantly stop callling this method/stop rendering for some reason, because it has lost focus. However, I want to keep sending these messages.
I already tried to use a Timer, an event that would be called every 2 seconds, but I read somewhere (and my tests seem to agree) that this timer is also connected to the rendering/frame entering, so that timed function will also not be executed.
Is there a way to do what I want?
You can use the MOUSE_LEAVE stage event to check when your swf has lost focus.
What I would recommend is using the ExternalInterface to establish a connection between the swf and javascript. As soon as the connection is done, have javascript call your server instead of flash, that may loose focus.
Out of curiosity, why would you need to poll the server every 2 seconds ?