I had an idea for a simple PureMVC AIR utility that will send out a notification when your application is offline or online. I'm building my first offline-supported AIR PureMVC application so this is something of value to me. I would love to tap into a notification that is clear and simple: ONLINE or OFFLINE. I can simply register a command with this notification and I can do whatever work necessary when either online or offline. This is the main goal of the utility.
The utility has 2 commands and 1 proxy. The NetworkMonitorProxy to put it simply handles a URLMonitor instance. Once you tell it to start you have no other work to do. No need to add an event listener on NativeApplication.nativeApplication either! The NetworkMonitorProxy will listen for a status event on the URLMonitor instance and using its "available" property determines whether to send an ONLINE or OFFLINE notification. Simple.
Before being able to start the monitor you need to simply register this command:
registerCommand(NetworkMonitor.START_MONITOR, StartNetworkMonitorCommand);
To start the monitor send the following notification with a body being a URL to monitor:
sendNotification(NetworkMonitor.START_MONITOR, "
www.myservice.com");
You would follow the same procedures for stopping a monitor with the only difference being sending no body to fire off the command. Also as a helper NetworkMonitorProxy sends out to notifications when a monitor has started NetworkMonitor.MONITOR_STARTED and when it has stopped NetworkMonitor.MONITOR_STOPPED.
Basically all you are going to want to do is handle the following notification constants in your mediators or register it to fire off a custom command: NetworkMonitor.ONLINE or NetworkMonitor.OFFLINE depending on what you need. When these notifications are sent the notification body is the NetworkMonitorProxy instance. I did this since I have several properties you might want access too say for logging or other purposes. Those read-only properties include:
- online
- startedOn
- statusChangedOn
- url
I couldn't think of anymore to add in but if any of you have ideas let me know. I'd like to see what features you guys might need but I figure since this is pretty simple and straightforward much if not nothing at all else would be needed. I plan to share the code but I'm unfamiliar with procedure of getting a utility out as I would need to change the namespace for PureMVC first.
Cliff,
I've talked to you through email about creating PureMVC utilities and what their namespaces should be. I've completed this utility locally and would love to finally be able to offer something back to the PureMVC community. What do I need to do to get this submitted for approval? Just zip up and send you the code? Commit it to an SVN repo you create? Let me know.