From 56ba83bb0c04d986a4577e7799a450dc5c920c5e Mon Sep 17 00:00:00 2001 From: Liong Sauw Ming Date: Fri, 12 Apr 2013 08:05:12 +0000 Subject: Re #1655: pjsua app CLI for iOS git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4464 74dad513-b988-da41-8d7b-12977e46ad98 --- .../src/pjsua/ios/ipjsua/Default-568h@2x.png | Bin 0 -> 18594 bytes pjsip-apps/src/pjsua/ios/ipjsua/Default.png | Bin 0 -> 6540 bytes pjsip-apps/src/pjsua/ios/ipjsua/Default@2x.png | Bin 0 -> 16107 bytes .../pjsua/ios/ipjsua/en.lproj/InfoPlist.strings | 2 + .../ipjsua/en.lproj/ipjsuaViewController_iPad.xib | 121 +++++++ .../en.lproj/ipjsuaViewController_iPhone.xib | 369 +++++++++++++++++++++ pjsip-apps/src/pjsua/ios/ipjsua/ipjsua-Info.plist | 46 +++ pjsip-apps/src/pjsua/ios/ipjsua/ipjsua-Prefix.pch | 14 + .../src/pjsua/ios/ipjsua/ipjsuaAppDelegate.h | 19 ++ .../src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m | 169 ++++++++++ .../src/pjsua/ios/ipjsua/ipjsuaViewController.h | 15 + .../src/pjsua/ios/ipjsua/ipjsuaViewController.m | 33 ++ pjsip-apps/src/pjsua/ios/ipjsua/main.m | 18 + pjsip-apps/src/pjsua/ios/ipjsua/pjsua.png | Bin 0 -> 10728 bytes 14 files changed, 806 insertions(+) create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/Default-568h@2x.png create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/Default.png create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/Default@2x.png create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/en.lproj/InfoPlist.strings create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/en.lproj/ipjsuaViewController_iPad.xib create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/en.lproj/ipjsuaViewController_iPhone.xib create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/ipjsua-Info.plist create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/ipjsua-Prefix.pch create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.h create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaViewController.h create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaViewController.m create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/main.m create mode 100644 pjsip-apps/src/pjsua/ios/ipjsua/pjsua.png (limited to 'pjsip-apps/src/pjsua/ios/ipjsua') diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/Default-568h@2x.png b/pjsip-apps/src/pjsua/ios/ipjsua/Default-568h@2x.png new file mode 100644 index 00000000..0891b7aa Binary files /dev/null and b/pjsip-apps/src/pjsua/ios/ipjsua/Default-568h@2x.png differ diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/Default.png b/pjsip-apps/src/pjsua/ios/ipjsua/Default.png new file mode 100644 index 00000000..4c8ca6f6 Binary files /dev/null and b/pjsip-apps/src/pjsua/ios/ipjsua/Default.png differ diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/Default@2x.png b/pjsip-apps/src/pjsua/ios/ipjsua/Default@2x.png new file mode 100644 index 00000000..35b84cff Binary files /dev/null and b/pjsip-apps/src/pjsua/ios/ipjsua/Default@2x.png differ diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/en.lproj/InfoPlist.strings b/pjsip-apps/src/pjsua/ios/ipjsua/en.lproj/InfoPlist.strings new file mode 100644 index 00000000..477b28ff --- /dev/null +++ b/pjsip-apps/src/pjsua/ios/ipjsua/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/en.lproj/ipjsuaViewController_iPad.xib b/pjsip-apps/src/pjsua/ios/ipjsua/en.lproj/ipjsuaViewController_iPad.xib new file mode 100644 index 00000000..4f574f69 --- /dev/null +++ b/pjsip-apps/src/pjsua/ios/ipjsua/en.lproj/ipjsuaViewController_iPad.xib @@ -0,0 +1,121 @@ + + + + 1536 + 12A206j + 2519 + 1172.1 + 613.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 1856 + + + IBProxyObject + IBUIView + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBIPadFramework + + + IBFirstResponder + IBIPadFramework + + + + 274 + {{0, 20}, {768, 1004}} + + + + 3 + MQA + + 2 + + + + 2 + + IBIPadFramework + + + + + + + view + + + + 3 + + + + + + 0 + + + + + + -1 + + + File's Owner + + + -2 + + + + + 2 + + + + + + + ipjsuaViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + 3 + + + + + ipjsuaViewController + UIViewController + + IBProjectSource + ./Classes/ipjsuaViewController.h + + + + + 0 + IBIPadFramework + YES + 3 + YES + 1856 + + diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/en.lproj/ipjsuaViewController_iPhone.xib b/pjsip-apps/src/pjsua/ios/ipjsua/en.lproj/ipjsuaViewController_iPhone.xib new file mode 100644 index 00000000..37bf20db --- /dev/null +++ b/pjsip-apps/src/pjsua/ios/ipjsua/en.lproj/ipjsuaViewController_iPhone.xib @@ -0,0 +1,369 @@ + + + + 1536 + 11G63b + 2840 + 1138.51 + 569.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 1926 + + + IBNSLayoutConstraint + IBProxyObject + IBUIImageView + IBUILabel + IBUIView + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 274 + + + + 292 + {320, 528} + + + + _NS:9 + + 3 + MAA + + 5 + NO + IBCocoaTouchFramework + + NSImage + pjsua.png + + + + + 292 + {{0, 527}, {328, 21}} + + + + _NS:9 + + NO + YES + 7 + NO + + IBCocoaTouchFramework + Telnet to IP:PORT + + 1 + MSAxIDEgMC42AA + lightTextColor + + + 0 + 1 + + 1 + 17 + + + Helvetica + 17 + 16 + + NO + + + {{0, 20}, {320, 548}} + + + + + 3 + MC43NQA + + 2 + + + NO + + + IBUIScreenMetrics + + YES + + + + + + {320, 568} + {568, 320} + + + IBCocoaTouchFramework + Retina 4 Full Screen + 2 + + IBCocoaTouchFramework + + + + + + + view + + + + 37 + + + + textLabel + + + + 38 + + + + + + 0 + + + + + + -1 + + + File's Owner + + + -2 + + + + + 6 + + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 4 + 0 + + 4 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 3 + 0 + + 3 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + + + + + 8 + + + + + 7 + 0 + + 0 + 1 + + 328 + + 1000 + + 3 + 9 + 1 + + + + + + 15 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + + 31 + + + + + 30 + + + + + + + ipjsuaViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + + + + + 45 + + + + + NSLayoutConstraint + NSObject + + IBProjectSource + ./Classes/NSLayoutConstraint.h + + + + ipjsuaViewController + UIViewController + + textLabel + UILabel + + + textLabel + + textLabel + UILabel + + + + IBProjectSource + ./Classes/ipjsuaViewController.h + + + + + 0 + IBCocoaTouchFramework + YES + 3 + + pjsua.png + {320, 528} + + YES + 1926 + + diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/ipjsua-Info.plist b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsua-Info.plist new file mode 100644 index 00000000..3811acf4 --- /dev/null +++ b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsua-Info.plist @@ -0,0 +1,46 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + com.teluu.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UIBackgroundModes + + audio + voip + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + + + diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/ipjsua-Prefix.pch b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsua-Prefix.pch new file mode 100644 index 00000000..352e6588 --- /dev/null +++ b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsua-Prefix.pch @@ -0,0 +1,14 @@ +// +// Prefix header for all source files of the 'ipjsua' target in the 'ipjsua' project +// + +#import + +#ifndef __IPHONE_4_0 +#warning "This project uses features only available in iOS SDK 4.0 and later." +#endif + +#ifdef __OBJC__ + #import + #import +#endif diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.h b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.h new file mode 100644 index 00000000..56e6d3ea --- /dev/null +++ b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.h @@ -0,0 +1,19 @@ +// +// ipjsuaAppDelegate.h +// ipjsua +// +// Created by Liong Sauw Ming on 13/3/13. +// Copyright (c) 2013 Teluu. All rights reserved. +// + +#import + +@class ipjsuaViewController; + +@interface ipjsuaAppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + +@property (strong, nonatomic) ipjsuaViewController *viewController; + +@end diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m new file mode 100644 index 00000000..f1775bc2 --- /dev/null +++ b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m @@ -0,0 +1,169 @@ +// +// ipjsuaAppDelegate.m +// ipjsua +// +// Created by Liong Sauw Ming on 13/3/13. +// Copyright (c) 2013 Teluu. All rights reserved. +// + +#import "ipjsuaAppDelegate.h" +#import +#import +#import +#include "../../pjsua_common.h" + +#import "ipjsuaViewController.h" + +@implementation ipjsuaAppDelegate + +#define KEEP_ALIVE_INTERVAL 600 + +static int _argc = 4; +static char *_argv[] = {"", + "--use-cli", + "--no-cli-console", + "--cli-telnet-port=6378" +}; + +ipjsuaAppDelegate *app; +extern pj_cli_telnet_on_started on_started_cb; +extern pj_cli_on_quit on_quit_cb; +extern pj_cli_on_destroy on_destroy_cb; +extern pj_cli_on_restart_pjsua on_restart_pjsua_cb; +static pj_thread_desc a_thread_desc; +static pj_thread_t *a_thread; + +int main_func(int argc, char *argv[]); + +static void cli_telnet_started(pj_cli_telnet_info *telnet_info) +{ + PJ_LOG(3,("ipjsua", "Telnet to %.*s:%d", + telnet_info->ip_address.slen, telnet_info->ip_address.ptr, + telnet_info->port)); + NSString *str = [NSString stringWithFormat:@"Telnet to %.*s:%d", + (int)telnet_info->ip_address.slen, + telnet_info->ip_address.ptr, + telnet_info->port]; + [app performSelectorOnMainThread:@selector(displayMsg:) withObject:str + waitUntilDone:NO]; +} + +static void cli_on_quit (pj_bool_t is_restarted) +{ + PJ_LOG(3,("ipjsua", "CLI quit, restart(%d)", is_restarted)); + if (!is_restarted) { + NSString *str = [NSString stringWithFormat:@"CLI quit, " + "telnet unavailable"]; + [app performSelectorOnMainThread:@selector(displayMsg:) withObject:str + waitUntilDone:NO]; + } +} + +- (void)displayMsg:(NSString *)str { + app.viewController.textLabel.text = str; +} + +- (void)start_app { + on_started_cb = &cli_telnet_started; + on_quit_cb = &cli_on_quit; + main_func(_argc, _argv); +} + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + // Override point for customization after application launch. + if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { + self.viewController = [[ipjsuaViewController alloc] initWithNibName:@"ipjsuaViewController_iPhone" bundle:nil]; + } else { + self.viewController = [[ipjsuaViewController alloc] initWithNibName:@"ipjsuaViewController_iPad" bundle:nil]; + } + self.window.rootViewController = self.viewController; + [self.window makeKeyAndVisible]; + + app = self; + + /* Start pjsua app thread */ + [NSThread detachNewThreadSelector:@selector(start_app) toTarget:self withObject:nil]; + + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application +{ + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. +} + +- (void)keepAlive { + int i, timeout = KEEP_ALIVE_INTERVAL; + + if (!pj_thread_is_registered()) + { + pj_thread_register("ipjsua", a_thread_desc, &a_thread); + } + + for (i = 0; i < (int)pjsua_acc_get_count(); ++i) { + if (pjsua_acc_is_valid(i)) { + pjsua_acc_config acc_cfg; + + pjsua_acc_get_config(i, &acc_cfg); + if (!acc_cfg.reg_uri.slen) + continue; + if (acc_cfg.reg_timeout < timeout) { + acc_cfg.reg_timeout = timeout; + pjsua_acc_modify(i, &acc_cfg); + } else { + pjsua_acc_set_registration(i, PJ_TRUE); + } + } + } +} + +- (void)applicationDidEnterBackground:(UIApplication *)application +{ + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES]; + [application setKeepAliveTimeout:KEEP_ALIVE_INTERVAL handler: ^{ + [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES]; + }]; +} + +- (void)applicationWillEnterForeground:(UIApplication *)application +{ + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. +} + +- (void)applicationDidBecomeActive:(UIApplication *)application +{ + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + +- (void)applicationWillTerminate:(UIApplication *)application +{ + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + + +pj_bool_t showNotification(pjsua_call_id call_id) +{ + // Create a new notification + UILocalNotification* alert = [[UILocalNotification alloc] init]; + if (alert) + { + alert.repeatInterval = 0; + alert.alertBody = @"Incoming call received..."; + /* This action just brings the app to the FG, it doesn't + * automatically answer the call (unless you specify the + * --auto-answer option). + */ + alert.alertAction = @"Activate app"; + + [[UIApplication sharedApplication] presentLocalNotificationNow:alert]; + } + + return PJ_FALSE; +} + +@end diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaViewController.h b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaViewController.h new file mode 100644 index 00000000..1b892756 --- /dev/null +++ b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaViewController.h @@ -0,0 +1,15 @@ +// +// ipjsuaViewController.h +// ipjsua +// +// Created by Liong Sauw Ming on 13/3/13. +// Copyright (c) 2013 Teluu. All rights reserved. +// + +#import + +@interface ipjsuaViewController : UIViewController + +@property (nonatomic, retain) IBOutlet UILabel *textLabel; + +@end diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaViewController.m b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaViewController.m new file mode 100644 index 00000000..44b335ee --- /dev/null +++ b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaViewController.m @@ -0,0 +1,33 @@ +// +// ipjsuaViewController.m +// ipjsua +// +// Created by Liong Sauw Ming on 13/3/13. +// Copyright (c) 2013 Teluu. All rights reserved. +// + +#import "ipjsuaViewController.h" + +@interface ipjsuaViewController () + +@end + +@implementation ipjsuaViewController + +@synthesize textLabel; + +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Do any additional setup after loading the view, typically from a nib. + + [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +@end diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/main.m b/pjsip-apps/src/pjsua/ios/ipjsua/main.m new file mode 100644 index 00000000..dc2242db --- /dev/null +++ b/pjsip-apps/src/pjsua/ios/ipjsua/main.m @@ -0,0 +1,18 @@ +// +// main.m +// ipjsua +// +// Created by Liong Sauw Ming on 13/3/13. +// Copyright (c) 2013 Teluu. All rights reserved. +// + +#import + +#import "ipjsuaAppDelegate.h" + +int main(int argc, char *argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([ipjsuaAppDelegate class])); + } +} diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/pjsua.png b/pjsip-apps/src/pjsua/ios/ipjsua/pjsua.png new file mode 100644 index 00000000..4ce4011e Binary files /dev/null and b/pjsip-apps/src/pjsua/ios/ipjsua/pjsua.png differ -- cgit v1.2.3