390 likes | 703 Views
APP-410T. Real time communication: keep your Metro style app connected whether it is running or suspended. Raghu Gatta Principal Development Lead Microsoft Corporation. Kamal Srinivasan Program Manager Microsoft Corporation. Agenda. Real Time Communication (RTC) app requirements
E N D
APP-410T Real time communication: keep your Metro style app connected whether it is running or suspended Raghu Gatta Principal Development Lead Microsoft Corporation Kamal Srinivasan Program Manager Microsoft Corporation
Agenda • Real Time Communication (RTC) app requirements • User in control of the RTC apps • Building your RTC app in Windows 8 You’ll leave knowing how to • Build communication apps that work 24x7
Customer promise in Windows 8 Longer battery life Always reachable apps
Review app process lifetime Running App Suspended App Terminated App Suspending Low Memory Resuming
What about RTC apps? VoIP IM Mail RTC apps that need to be always reachable
Windows enables you to develop apps that are always reachable!
The app lifecycle …with RTC apps Background Task Executes Background Task Executes Background Task Executes Running App Suspended App Terminated App Suspending Low Memory Resuming
demo Chat app (PingMe) Running an app in the background
RTC trigger APIs for your apps App OS VoIP IM Mail Network Trigger System Trigger Time Trigger Background Task Infrastructure
Building an IM app on Windows 8 System Trigger Network Trigger VoIP IM Mail Network Trigger System Trigger Time Trigger Receive an IM when app is in the background Background Task Infrastructure Receive an IM after user logs in
Execution Pattern App OS App registers for trigger OS waits Trigger fires Background task executes
Network Trigger Register for IM network trigger Open your socket usingWindows.Networking.Sockets; StreamSocket sock = newStreamSocket(); // Connect the streamsocket … Add Control Channel metadata // Create a Notification Channel with Push capability NotificationChannelnc = newNotificationChannel( "channelOne", “MyApp.Background.KeepAliveTask", “MyApp.Background.PushNotifyTask", ServerKATimeInMins); Register your socket // Associate the socket with the notification channel channelStatus = nc.UsingTransport(sock);
Network Trigger App execution upon receiving IM usingWindows.ApplicationModel.Background; publicsealedclassPushNotifyTask : IBackgroundTask{ publicvoidRun(IBackgroundTaskInstancetaskInstance) { // Handle Incoming message // Throwing a toast code } } } }
Keep Alive maintains your control channel Network Keep alive Interval Server Keep alive Interval
Network Trigger App execution on Keep Alive usingWindows.ApplicationModel.Background; publicsealedclassKeepAliveTask: IBackgroundTask{ publicvoidRun(IBackgroundTaskInstancetaskInstance) { // Send Keepalive message to remote server } }} } }
System Trigger Register on User Login Create user login trigger usingWindows.ApplicationModel.Background; // Specify the trigger IBackgroundTrigger trigger = newSystemTrigger(SystemTriggerType.SessionStart, false); Associate trigger with app code // Associate app code with the trigger BackgroundTaskBuildertaskBuilder = newBackgroundTaskBuilder(); taskBuilder.TaskEntryPoint = “MyApp.Background.RegisterForUserLogin"; taskBuilder.SetTrigger(trigger); taskBuilder.Name = “OnUserPresent"; Register trigger // Register the task for background execution IBackgroundTaskRegistrationtaskRegistration = taskBuilder.Register();
System Trigger App execution on User Login usingWindows.ApplicationModel.Background; publicsealedclassRegisterForUserLogin: IBackgroundTask{ publicvoidRun(IBackgroundTaskInstancetaskInstance) { // Your app code to create notification channel } }
demo Chat app (PingMe) Receive an IM when in “Connected Standby”
Always connected Mobile broadband (e.g. 3G, 4G, LTE, etc.) Network Connectivity
Building a POP mail app on Windows 8 VoIP IM Mail Time Trigger Network Trigger System Trigger Time Trigger Periodic Mail Sync Background Task Infrastructure
Time Trigger Register for Periodic Mail Sync Create time trigger usingWindows.ApplicationModel.Background; // Specify the trigger TimeTriggertrigger = newTimeTrigger(UpdateInterval, Periodic); Associate trigger with app code // Associate app code with the trigger BackgroundTaskBuildertaskBuilder = newBackgroundTaskBuilder(); taskBuilder.TaskEntryPoint = “MyApp.Background.UpdateEmailTask"; taskBuilder.SetTrigger(trigger); taskBuilder.Name = “TimerExpiry"; Register trigger // Register the task for background execution IBackgroundTaskRegistrationtaskRegistration = taskBuilder.Register();
Time Trigger App execution upon timer expiry usingWindows.ApplicationModel.Background; publicsealedclassUpdateEmailTask: IBackgroundTask{ publicvoidRun(IBackgroundTaskInstancetaskInstance) { // Your app code to update email } } }
Key points Longer Battery Life Always Reachable Apps
Write your RTC app code using background tasks. Key points Your app will be always reachable in connected standby.
Related sessions • [APP-409T] Fundamentals of Metro style apps: how and when your app will run • [HW-456T] Understanding Connected Standby • [HW-566T] Networking for connected standby • [PLAT-785T] Creating connected apps that work on today's networks • [APP-396T] Using tiles and notifications
Further reading and documentation • Introduction to Background Tasks • http://go.microsoft.com/fwlink/?LinkID=227329&clcid=0x409 • Contact info – AskRtcDev@microsoft.com (optional)
thank you Feedback and questions http://forums.dev.windows.com Session feedbackhttp://bldw.in/SessionFeedback
© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Lock Screen API sample voidAddToLockScreen() { IAsyncOperation<LockScreenState> operation = LockScreen.AddToLockScreenAsync(); operation.Completed = OnAddToLockScreenOperationCompleted; operation.Start(); } voidOnAddToLockScreenOperationCompleted(IAsyncOperation<LockScreenState> operation) { if (operation.Status == AsyncStatus.Completed) { LockScreenState result = operation.GetResults(); switch (result) { caseLockScreenState.NotOnLockScreen: break; caseLockScreenState.OnLockScreen: break; caseLockScreenState.DefaultNotOnLockScreen: break; } } else if (operation.Status == AsyncStatus.Error){ // Report error } }
System Event Registering for Network Change usingWindows.ApplicationModel.Background; // Specify the trigger IBackgroundTriggertrigger = newSystemTrigger(SystemTriggerType.NetworkStateChange, false); // Associate app code with the trigger BackgroundTaskBuildertaskBuilder= newBackgroundTaskBuilder(); taskBuilder.TaskEntryPoint= “MyAppBackground.NetworkStateChangeTask"; taskBuilder.SetTrigger(trigger); taskBuilder.Name= “OnNetworkStateChange"; // Register the task for background execution IBackgroundTaskRegistrationtaskRegistration= taskBuilder.Register();
System Event App execution upon network change using Windows.ApplicationModel.Background; publicsealedclassNetworkStateChangeTask: IBackgroundTask{ publicvoidRun(IBackgroundTaskInstancetaskInstance) { // Re-register Notification Channel } }