Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61b6e25a91 | ||
|
|
50cff820de | ||
|
|
4e586a28c8 | ||
|
|
0702b4ed57 | ||
|
|
4a2132a682 | ||
|
|
ba81d1d6a9 | ||
|
|
402ce4b3ec | ||
|
|
fc713453ad | ||
|
|
b222ccffbb | ||
|
|
56ce7329d2 | ||
|
|
99ab6db557 | ||
|
|
d7adf96f3a | ||
|
|
0ae58c61a9 | ||
|
|
2ec7d1d2f1 | ||
|
|
ad1b9059ee | ||
|
|
4439c7cce6 | ||
|
|
b8a4093c75 | ||
|
|
ec3748b26e | ||
|
|
1c1f22e047 | ||
|
|
9aa9b0fc5a | ||
|
|
f8e2ca8500 | ||
|
|
3076e29335 | ||
|
|
fe616d86c5 | ||
|
|
bfa4856bbe | ||
|
|
5ea92a7b48 | ||
|
|
4ba71db7b2 | ||
|
|
c1e6aeb43c | ||
|
|
e3ffb66ef0 | ||
|
|
5daa82b0ba | ||
|
|
a8bcc6afba | ||
|
|
e6aa16ad01 | ||
|
|
ad0705d126 | ||
|
|
2f31f93bf8 | ||
|
|
ea3be613c5 | ||
|
|
b495246f34 | ||
|
|
814470f4bf | ||
|
|
82293a08b6 | ||
|
|
20d66336a7 | ||
|
|
c8441ec9fa | ||
|
|
f72135c227 | ||
|
|
100e6e4ce8 | ||
|
|
ec8be20d62 | ||
|
|
55d48101ef | ||
|
|
c36f4c5f84 | ||
|
|
06289ac4d2 | ||
|
|
e6a2d5d425 | ||
|
|
ea8db9c4ea | ||
|
|
3773e841d1 | ||
|
|
ad1ddd04f3 | ||
|
|
67a8b232b9 | ||
|
|
5293c07fc0 | ||
|
|
e3a42db007 | ||
|
|
3b1462af22 | ||
|
|
74a0c5b1cd | ||
|
|
05a5e4fa64 | ||
|
|
b6445295a7 | ||
|
|
391605ef36 | ||
|
|
695499dea9 | ||
|
|
9ba7f35444 | ||
|
|
37dc00735b | ||
|
|
920cbadc91 | ||
|
|
bc53b4dc32 | ||
|
|
6015c38d17 | ||
|
|
4ea8694a7d | ||
|
|
00f01196fb | ||
|
|
543639c93e | ||
|
|
1da877fed7 | ||
|
|
396b5fc156 | ||
|
|
297dfd4159 | ||
|
|
23e9d48b0d | ||
|
|
9ec650a84f | ||
|
|
90bdbc4ae0 | ||
|
|
dd5f06723b | ||
|
|
55b2871b83 | ||
|
|
c8b13126d0 | ||
|
|
96cfe0b70d | ||
|
|
6dbb938368 | ||
|
|
46fe7a8aed | ||
|
|
3151ac6bf0 | ||
|
|
dc5210f691 | ||
|
|
1f02265003 | ||
|
|
e4af9032e2 | ||
|
|
e8650b2420 | ||
|
|
9c6b718be2 | ||
|
|
8f12114a56 | ||
|
|
dc6ebffab1 | ||
|
|
13e894e9a3 | ||
|
|
4c95773131 | ||
|
|
38776a01e4 | ||
|
|
b2563e534d | ||
|
|
37f25c1f97 | ||
|
|
642085ca32 | ||
|
|
5dee29a21c | ||
|
|
b01d13976b | ||
|
|
ae1c83a011 | ||
|
|
e5f962dc3f | ||
|
|
54dd79d2dd | ||
|
|
935fb6ffe3 | ||
|
|
48d1c1a080 | ||
|
|
2d02ce2a1b | ||
|
|
29fda59a72 | ||
|
|
05f0dfd4f5 | ||
|
|
0bdc5a83f1 | ||
|
|
8688bf1210 | ||
|
|
bf0858d57e | ||
|
|
8d4d391310 | ||
|
|
8fb15336c4 | ||
|
|
883385c42b | ||
|
|
6d1139796e | ||
|
|
e58eb5f56a | ||
|
|
2b0ce49646 | ||
|
|
73364127d2 | ||
|
|
84a986bc88 | ||
|
|
f13051aa31 | ||
|
|
6bb559303b | ||
|
|
b7324f9a44 | ||
|
|
c0b2bbe552 | ||
|
|
8c36cf40fd | ||
|
|
717296269f | ||
|
|
4be29abede | ||
|
|
528af9684e | ||
|
|
ff7a4ef190 | ||
|
|
99a2dbb956 | ||
|
|
280341791a | ||
|
|
1759565920 | ||
|
|
f57fa678f6 | ||
|
|
f8b5b16109 | ||
|
|
005a678089 | ||
|
|
315dd53dcb | ||
|
|
bb24495b3f | ||
|
|
b9f2764990 | ||
|
|
a9a00629b1 | ||
|
|
1223a9013f | ||
|
|
ab019eef0f |
No files matched your search
@@ -1,2 +1,3 @@
|
|||||||
**/xcuserdata/
|
**/xcuserdata/
|
||||||
|
**/Moonlight.xcscmblueprint
|
||||||
Build
|
Build
|
||||||
@@ -31,43 +31,44 @@ do
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "Compiling source for $ARCH in directory $OPUS_DIR"
|
echo "Compiling source for $ARCH in directory $OPUS_DIR"
|
||||||
|
echo "cd $OPUS_DIR"
|
||||||
cd $OPUS_DIR
|
cd $OPUS_DIR
|
||||||
|
|
||||||
DIST_DIR=$DIST_DIR_BASE-$ARCH
|
DIST_DIR=$DIST_DIR_BASE-$ARCH
|
||||||
|
echo "mkdir -p $DIST_DIR"
|
||||||
mkdir -p $DIST_DIR
|
mkdir -p $DIST_DIR
|
||||||
CFLAGS_ARCH=$ARCH
|
CFLAGS_ARCH=$ARCH
|
||||||
case $ARCH in
|
case $ARCH in
|
||||||
armv7)
|
armv7)
|
||||||
EXTRA_FLAGS="--with-pic --enable-fixed-point"
|
EXTRA_FLAGS="--with-pic --enable-fixed-point"
|
||||||
EXTRA_CFLAGS="-mcpu=cortex-a8 -mfpu=neon"
|
EXTRA_CFLAGS="-mcpu=cortex-a8 -mfpu=neon -miphoneos-version-min=7.1"
|
||||||
PLATFORM="${PLATFORMBASE}/iPhoneOS.platform"
|
PLATFORM="${PLATFORMBASE}/iPhoneOS.platform"
|
||||||
IOSSDK=iPhoneOS${IOSSDK_VER}
|
IOSSDK=iPhoneOS
|
||||||
;;
|
;;
|
||||||
armv7s)
|
armv7s)
|
||||||
EXTRA_FLAGS="--with-pic --enable-fixed-point"
|
EXTRA_FLAGS="--with-pic --enable-fixed-point"
|
||||||
EXTRA_CFLAGS="-mcpu=cortex-a9 -mfpu=neon -miphoneos-version-min=6.0"
|
EXTRA_CFLAGS="-mcpu=cortex-a9 -mfpu=neon -miphoneos-version-min=7.1"
|
||||||
PLATFORM="${PLATFORMBASE}/iPhoneOS.platform"
|
PLATFORM="${PLATFORMBASE}/iPhoneOS.platform"
|
||||||
IOSSDK=iPhoneOS${IOSSDK_VER}
|
IOSSDK=iPhoneOS
|
||||||
;;
|
;;
|
||||||
aarch64)
|
aarch64)
|
||||||
CFLAGS_ARCH="arm64"
|
CFLAGS_ARCH="arm64"
|
||||||
EXTRA_FLAGS="--with-pic --enable-fixed-point"
|
EXTRA_FLAGS="--with-pic --enable-fixed-point"
|
||||||
EXTRA_CFLAGS="-miphoneos-version-min=7.1"
|
EXTRA_CFLAGS="-miphoneos-version-min=7.1"
|
||||||
PLATFORM="${PLATFORMBASE}/iPhoneOS.platform"
|
PLATFORM="${PLATFORMBASE}/iPhoneOS.platform"
|
||||||
IOSSDK=iPhoneOS${IOSSDK_VER}
|
IOSSDK=iPhoneOS
|
||||||
;;
|
;;
|
||||||
x86_64)
|
x86_64)
|
||||||
EXTRA_FLAGS="--with-pic"
|
EXTRA_FLAGS="--with-pic"
|
||||||
EXTRA_CFLAGS="-miphoneos-version-min=7.1"
|
EXTRA_CFLAGS="-miphoneos-version-min=7.1"
|
||||||
PLATFORM="${PLATFORMBASE}/iPhoneSimulator.platform"
|
PLATFORM="${PLATFORMBASE}/iPhoneSimulator.platform"
|
||||||
IOSSDK=iPhoneSimulator${IOSSDK_VER}
|
IOSSDK=iPhoneSimulator
|
||||||
;;
|
;;
|
||||||
i386)
|
i386)
|
||||||
EXTRA_FLAGS="--with-pic"
|
EXTRA_FLAGS="--with-pic"
|
||||||
EXTRA_CFLAGS="-miphoneos-version-min=7.1"
|
EXTRA_CFLAGS="-miphoneos-version-min=7.1"
|
||||||
PLATFORM="${PLATFORMBASE}/iPhoneSimulator.platform"
|
PLATFORM="${PLATFORMBASE}/iPhoneSimulator.platform"
|
||||||
IOSSDK=iPhoneSimulator${IOSSDK_VER}
|
IOSSDK=iPhoneSimulator
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unsupported architecture ${ARCH}"
|
echo "Unsupported architecture ${ARCH}"
|
||||||
@@ -76,7 +77,7 @@ do
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
echo "Configuring opus for $ARCH..."
|
echo "Configuring opus for $ARCH..."
|
||||||
|
echo "./autogen.sh"
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
|
|
||||||
CFLAGS="-g -O2 -pipe -arch ${CFLAGS_ARCH} \
|
CFLAGS="-g -O2 -pipe -arch ${CFLAGS_ARCH} \
|
||||||
@@ -87,6 +88,9 @@ do
|
|||||||
-isysroot ${PLATFORM}/Developer/SDKs/${IOSSDK}.sdk \
|
-isysroot ${PLATFORM}/Developer/SDKs/${IOSSDK}.sdk \
|
||||||
-L${PLATFORM}/Developer/SDKs/${IOSSDK}.sdk/usr/lib"
|
-L${PLATFORM}/Developer/SDKs/${IOSSDK}.sdk/usr/lib"
|
||||||
|
|
||||||
|
echo "CFLAGS=$CFLAGS"
|
||||||
|
echo "LDFLAGS=$LDFLAGS"
|
||||||
|
|
||||||
export CFLAGS
|
export CFLAGS
|
||||||
export LDFLAGS
|
export LDFLAGS
|
||||||
|
|
||||||
@@ -100,6 +104,14 @@ do
|
|||||||
export NM="/usr/bin/nm"
|
export NM="/usr/bin/nm"
|
||||||
export RANLIB="/usr/bin/ranlib"
|
export RANLIB="/usr/bin/ranlib"
|
||||||
export STRIP="/usr/bin/strip"
|
export STRIP="/usr/bin/strip"
|
||||||
|
echo "./configure \
|
||||||
|
--prefix=$DIST_DIR \
|
||||||
|
--host=${ARCH}-apple-darwin \
|
||||||
|
--with-sysroot=${PLATFORM}/Developer/SDKs/${IOSSDK}.sdk \
|
||||||
|
--enable-static=yes \
|
||||||
|
--enable-shared=no \
|
||||||
|
--disable-doc \
|
||||||
|
${EXTRA_FLAGS}"
|
||||||
|
|
||||||
./configure \
|
./configure \
|
||||||
--prefix=$DIST_DIR \
|
--prefix=$DIST_DIR \
|
||||||
@@ -111,10 +123,14 @@ do
|
|||||||
${EXTRA_FLAGS}
|
${EXTRA_FLAGS}
|
||||||
|
|
||||||
echo "Installing opus for $ARCH..."
|
echo "Installing opus for $ARCH..."
|
||||||
|
echo "make clean"
|
||||||
make clean
|
make clean
|
||||||
|
echo "make -j$NJOB V=1"
|
||||||
make -j$NJOB V=1
|
make -j$NJOB V=1
|
||||||
|
echo "make install"
|
||||||
make install
|
make install
|
||||||
|
|
||||||
|
echo "cd $SCRIPT_DIR"
|
||||||
cd $SCRIPT_DIR
|
cd $SCRIPT_DIR
|
||||||
|
|
||||||
if [ -d $DIST_DIR/bin ]
|
if [ -d $DIST_DIR/bin ]
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ source config.sh
|
|||||||
SCRIPT_DIR=$( (cd -P $(dirname $0) && pwd) )
|
SCRIPT_DIR=$( (cd -P $(dirname $0) && pwd) )
|
||||||
DIST_DIR_BASE=${DIST_DIR_BASE:="$SCRIPT_DIR/dist"}
|
DIST_DIR_BASE=${DIST_DIR_BASE:="$SCRIPT_DIR/dist"}
|
||||||
|
|
||||||
git submodule update --init opus
|
|
||||||
cd opus
|
cd opus
|
||||||
git checkout master
|
git checkout master
|
||||||
git pull origin master
|
git pull origin master
|
||||||
|
|||||||
@@ -1,33 +1,51 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
|
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="15A279b" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
|
<deployment identifier="iOS"/>
|
||||||
|
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<objects>
|
<objects>
|
||||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||||
<view contentMode="scaleToFill" id="iN0-l3-epB">
|
<navigationController id="vV9-32-ww6">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
|
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<navigationBar key="navigationBar" contentMode="scaleToFill" id="y2P-aE-Haa">
|
||||||
<subviews>
|
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
|
||||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 Moonlight Stream. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
<rect key="frame" x="19" y="439" width="444" height="21"/>
|
<animations/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
<color key="barTintColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
|
||||||
<color key="textColor" red="0.72941176470000002" green="0.69411764710000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
</navigationBar>
|
||||||
<nil key="highlightedColor"/>
|
<viewControllers>
|
||||||
<variation key="widthClass=compact">
|
<viewController id="l6V-ue-5Om">
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="11"/>
|
<layoutGuides>
|
||||||
</variation>
|
<viewControllerLayoutGuide type="top" id="rEZ-vx-akr"/>
|
||||||
</label>
|
<viewControllerLayoutGuide type="bottom" id="gBD-cy-cth"/>
|
||||||
</subviews>
|
</layoutGuides>
|
||||||
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
<view key="view" contentMode="scaleToFill" id="6lF-fc-kpK">
|
||||||
<constraints>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Gnz-uJ-CDw"/>
|
<animations/>
|
||||||
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
|
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||||
</constraints>
|
</view>
|
||||||
<nil key="simulatedStatusBarMetrics"/>
|
<navigationItem key="navigationItem" id="rW0-BH-s7l">
|
||||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
<barButtonItem key="leftBarButtonItem" enabled="NO" id="d9R-Zo-Uml">
|
||||||
<point key="canvasLocation" x="404" y="445"/>
|
<button key="customView" opaque="NO" contentMode="center" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="9JC-B5-BAE">
|
||||||
</view>
|
<rect key="frame" x="-23" y="-15" width="46" height="30"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||||
|
<animations/>
|
||||||
|
<fontDescription key="fontDescription" type="system" pointSize="16"/>
|
||||||
|
<state key="normal" title="Moonlight" image="Logo">
|
||||||
|
<color key="titleColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
|
||||||
|
<color key="titleShadowColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
|
||||||
|
</state>
|
||||||
|
<variation key="widthClass=regular" preservesSuperviewLayoutMargins="NO"/>
|
||||||
|
</button>
|
||||||
|
</barButtonItem>
|
||||||
|
</navigationItem>
|
||||||
|
</viewController>
|
||||||
|
</viewControllers>
|
||||||
|
</navigationController>
|
||||||
</objects>
|
</objects>
|
||||||
|
<resources>
|
||||||
|
<image name="Logo" width="32" height="32"/>
|
||||||
|
</resources>
|
||||||
</document>
|
</document>
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
//
|
|
||||||
// App.h
|
|
||||||
// Moonlight
|
|
||||||
//
|
|
||||||
// Created by Diego Waxemberg on 10/22/14.
|
|
||||||
// Copyright (c) 2014 Moonlight Stream. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
|
|
||||||
@interface App : NSObject
|
|
||||||
|
|
||||||
@property NSString* appId;
|
|
||||||
@property NSString* appName;
|
|
||||||
@property UIImage* appImage;
|
|
||||||
@property BOOL isRunning;
|
|
||||||
|
|
||||||
@end
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
//
|
|
||||||
// App.m
|
|
||||||
// Moonlight
|
|
||||||
//
|
|
||||||
// Created by Diego Waxemberg on 10/22/14.
|
|
||||||
// Copyright (c) 2014 Moonlight Stream. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "App.h"
|
|
||||||
#import "HttpManager.h"
|
|
||||||
|
|
||||||
@implementation App
|
|
||||||
@synthesize appId, appName, appImage, isRunning;
|
|
||||||
|
|
||||||
@end
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// AppCollectionView.h
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Diego Waxemberg on 9/30/15.
|
||||||
|
// Copyright © 2015 Moonlight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
@interface AppCollectionView : UICollectionView
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// AppCollectionView.m
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Diego Waxemberg on 9/30/15.
|
||||||
|
// Copyright © 2015 Moonlight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "AppCollectionView.h"
|
||||||
|
|
||||||
|
@implementation AppCollectionView
|
||||||
|
|
||||||
|
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
|
||||||
|
if ([view isKindOfClass:[UIButton class]]) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
return [super touchesShouldCancelInContentView:view];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Only override drawRect: if you perform custom drawing.
|
||||||
|
// An empty implementation adversely affects performance during animation.
|
||||||
|
- (void)drawRect:(CGRect)rect {
|
||||||
|
// Drawing code
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -83,10 +83,7 @@ static NSOperationQueue* mainQueue;
|
|||||||
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
|
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
|
||||||
if (managedObjectContext != nil) {
|
if (managedObjectContext != nil) {
|
||||||
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
|
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
|
||||||
// Replace this implementation with code to handle the error appropriately.
|
Log(LOG_E, @"Critical database error: %@, %@", error, [error userInfo]);
|
||||||
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
|
|
||||||
Log(LOG_E, @"Unresolved error %@, %@", error, [error userInfo]);
|
|
||||||
abort();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,7 +100,7 @@ static NSOperationQueue* mainQueue;
|
|||||||
|
|
||||||
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
|
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
|
||||||
if (coordinator != nil) {
|
if (coordinator != nil) {
|
||||||
_managedObjectContext = [[NSManagedObjectContext alloc] init];
|
_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
|
||||||
[_managedObjectContext setPersistentStoreCoordinator:coordinator];
|
[_managedObjectContext setPersistentStoreCoordinator:coordinator];
|
||||||
}
|
}
|
||||||
return _managedObjectContext;
|
return _managedObjectContext;
|
||||||
@@ -136,31 +133,14 @@ static NSOperationQueue* mainQueue;
|
|||||||
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
|
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
|
||||||
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
|
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
|
||||||
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
|
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
|
||||||
/*
|
// Log the error
|
||||||
Replace this implementation with code to handle the error appropriately.
|
Log(LOG_E, @"Critical database error: %@, %@", error, [error userInfo]);
|
||||||
|
|
||||||
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
|
// Drop the database
|
||||||
|
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil];
|
||||||
|
|
||||||
Typical reasons for an error here include:
|
// Try again
|
||||||
* The persistent store is not accessible;
|
return [self persistentStoreCoordinator];
|
||||||
* The schema for the persistent store is incompatible with current managed object model.
|
|
||||||
Check the error message to determine what the actual problem was.
|
|
||||||
|
|
||||||
|
|
||||||
If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.
|
|
||||||
|
|
||||||
If you encounter schema incompatibility errors during development, you can reduce their frequency by:
|
|
||||||
* Simply deleting the existing store:
|
|
||||||
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]
|
|
||||||
|
|
||||||
* Performing automatic lightweight migration by passing the following dictionary as the options parameter:
|
|
||||||
@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}
|
|
||||||
|
|
||||||
Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.
|
|
||||||
|
|
||||||
*/
|
|
||||||
Log(LOG_E, @"Unresolved error %@, %@", error, [error userInfo]);
|
|
||||||
abort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _persistentStoreCoordinator;
|
return _persistentStoreCoordinator;
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// ComputerScrollView.h
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Diego Waxemberg on 9/30/15.
|
||||||
|
// Copyright © 2015 Moonlight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
@interface ComputerScrollView : UIScrollView
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// ComputerScrollView.m
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Diego Waxemberg on 9/30/15.
|
||||||
|
// Copyright © 2015 Moonlight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "ComputerScrollView.h"
|
||||||
|
|
||||||
|
@implementation ComputerScrollView
|
||||||
|
|
||||||
|
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
|
||||||
|
if ([view isKindOfClass:[UIButton class]]) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
return [super touchesShouldCancelInContentView:view];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Only override drawRect: if you perform custom drawing.
|
||||||
|
// An empty implementation adversely affects performance during animation.
|
||||||
|
- (void)drawRect:(CGRect)rect {
|
||||||
|
// Drawing code
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -11,11 +11,11 @@
|
|||||||
@interface CryptoManager : NSObject
|
@interface CryptoManager : NSObject
|
||||||
|
|
||||||
+ (void) generateKeyPairUsingSSl;
|
+ (void) generateKeyPairUsingSSl;
|
||||||
+ (NSString*) getUniqueID;
|
|
||||||
+ (NSData*) readCertFromFile;
|
+ (NSData*) readCertFromFile;
|
||||||
+ (NSData*) readKeyFromFile;
|
+ (NSData*) readKeyFromFile;
|
||||||
+ (NSData*) readP12FromFile;
|
+ (NSData*) readP12FromFile;
|
||||||
+ (NSData*) getSignatureFromCert:(NSData*)cert;
|
+ (NSData*) getSignatureFromCert:(NSData*)cert;
|
||||||
|
+ (NSData*) nullTerminateString:(NSData*)data;
|
||||||
|
|
||||||
- (NSData*) createAESKeyFromSalt:(NSData*)saltedPIN;
|
- (NSData*) createAESKeyFromSalt:(NSData*)saltedPIN;
|
||||||
- (NSData*) SHA1HashData:(NSData*)data;
|
- (NSData*) SHA1HashData:(NSData*)data;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#import "CryptoManager.h"
|
#import "CryptoManager.h"
|
||||||
#import "mkcert.h"
|
#import "mkcert.h"
|
||||||
#import <AdSupport/ASIdentifierManager.h>
|
|
||||||
|
|
||||||
#include <openssl/aes.h>
|
#include <openssl/aes.h>
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
@@ -76,8 +75,14 @@ static NSData* p12 = nil;
|
|||||||
return (((int)[data length] + 15) / 16) * 16;
|
return (((int)[data length] + 15) / 16) * 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (NSData*) nullTerminateString:(NSData*)data {
|
||||||
|
NSMutableData* mutData = [NSMutableData dataWithData:data];
|
||||||
|
[mutData appendBytes:"" length:1];
|
||||||
|
return mutData;
|
||||||
|
}
|
||||||
|
|
||||||
- (bool) verifySignature:(NSData *)data withSignature:(NSData*)signature andCert:(NSData*)cert {
|
- (bool) verifySignature:(NSData *)data withSignature:(NSData*)signature andCert:(NSData*)cert {
|
||||||
const char* buffer = [cert bytes];
|
const char* buffer = [[CryptoManager nullTerminateString:cert] bytes];
|
||||||
X509* x509;
|
X509* x509;
|
||||||
BIO* bio = BIO_new(BIO_s_mem());
|
BIO* bio = BIO_new(BIO_s_mem());
|
||||||
BIO_puts(bio, buffer);
|
BIO_puts(bio, buffer);
|
||||||
@@ -105,7 +110,7 @@ static NSData* p12 = nil;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (NSData *)signData:(NSData *)data withKey:(NSData *)key {
|
- (NSData *)signData:(NSData *)data withKey:(NSData *)key {
|
||||||
const char* buffer = [key bytes];
|
const char* buffer = [[CryptoManager nullTerminateString:key] bytes];
|
||||||
BIO* bio = BIO_new(BIO_s_mem());
|
BIO* bio = BIO_new(BIO_s_mem());
|
||||||
BIO_puts(bio, buffer);
|
BIO_puts(bio, buffer);
|
||||||
|
|
||||||
@@ -188,7 +193,7 @@ static NSData* p12 = nil;
|
|||||||
}
|
}
|
||||||
|
|
||||||
+ (NSData *)getSignatureFromCert:(NSData *)cert {
|
+ (NSData *)getSignatureFromCert:(NSData *)cert {
|
||||||
const char* buffer = [cert bytes];
|
const char* buffer = [[CryptoManager nullTerminateString:cert] bytes];
|
||||||
X509* x509;
|
X509* x509;
|
||||||
BIO* bio = BIO_new(BIO_s_mem());
|
BIO* bio = BIO_new(BIO_s_mem());
|
||||||
BIO_puts(bio, buffer);
|
BIO_puts(bio, buffer);
|
||||||
@@ -223,18 +228,4 @@ static NSData* p12 = nil;
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSString*) getUniqueID {
|
|
||||||
// generate a UUID
|
|
||||||
NSUUID* uuid = [ASIdentifierManager sharedManager].advertisingIdentifier;
|
|
||||||
NSString* idString = [NSString stringWithString:[uuid UUIDString]];
|
|
||||||
|
|
||||||
// we need a 16byte hex-string so we take the last 17 characters
|
|
||||||
// and remove the '-' to get a 16 character string
|
|
||||||
NSMutableString* uniqueId = [NSMutableString stringWithString:[idString substringFromIndex:19]];
|
|
||||||
[uniqueId deleteCharactersInRange:NSMakeRange(4, 1)];
|
|
||||||
|
|
||||||
//Log(LOG_D, @"Unique ID: %@", uniqueId);
|
|
||||||
return [NSString stringWithString:uniqueId];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
//
|
||||||
|
// IdManager.h
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Diego Waxemberg on 10/31/15.
|
||||||
|
// Copyright © 2015 Moonlight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
@interface IdManager : NSObject
|
||||||
|
|
||||||
|
+ (NSString*) getUniqueId;
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
//
|
||||||
|
// IdManager.m
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Diego Waxemberg on 10/31/15.
|
||||||
|
// Copyright © 2015 Moonlight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "IdManager.h"
|
||||||
|
#import "DataManager.h"
|
||||||
|
|
||||||
|
@implementation IdManager
|
||||||
|
|
||||||
|
+ (NSString*) getUniqueId {
|
||||||
|
DataManager* dataMan = [[DataManager alloc] init];
|
||||||
|
|
||||||
|
NSString* uniqueId = [dataMan getUniqueId];
|
||||||
|
if (uniqueId == nil) {
|
||||||
|
uniqueId = [IdManager generateUniqueId];
|
||||||
|
[dataMan updateUniqueId:uniqueId];
|
||||||
|
Log(LOG_I, @"No UUID found. Generated new UUID: %@", uniqueId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return uniqueId;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSString*) generateUniqueId {
|
||||||
|
UInt64 uuidLong = ((UInt64) arc4random() << 32) | arc4random();
|
||||||
|
return [NSString stringWithFormat:@"%016llx", uuidLong];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -85,7 +85,6 @@ int mkcert(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int years) {
|
|||||||
|
|
||||||
if (*pkeyp == NULL) {
|
if (*pkeyp == NULL) {
|
||||||
if ((pk=EVP_PKEY_new()) == NULL) {
|
if ((pk=EVP_PKEY_new()) == NULL) {
|
||||||
abort();
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -102,7 +101,6 @@ int mkcert(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int years) {
|
|||||||
|
|
||||||
rsa = RSA_generate_key(bits, RSA_F4, NULL, NULL);
|
rsa = RSA_generate_key(bits, RSA_F4, NULL, NULL);
|
||||||
if (!EVP_PKEY_assign_RSA(pk, rsa)) {
|
if (!EVP_PKEY_assign_RSA(pk, rsa)) {
|
||||||
abort();
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// App+CoreDataProperties.h
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Diego Waxemberg on 7/10/15.
|
||||||
|
// Copyright © 2015 Limelight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
// Delete this file and regenerate it using "Create NSManagedObject Subclass…"
|
||||||
|
// to keep your implementation up to date with your model.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "App.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface App (CoreDataProperties)
|
||||||
|
|
||||||
|
@property (nullable, nonatomic, retain) NSString *id;
|
||||||
|
@property (nullable, nonatomic, retain) NSData *image;
|
||||||
|
@property (nullable, nonatomic, retain) NSString *name;
|
||||||
|
@property (nullable, nonatomic, retain) Host *host;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// App.h
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Diego Waxemberg on 7/10/15.
|
||||||
|
// Copyright © 2015 Limelight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <CoreData/CoreData.h>
|
||||||
|
|
||||||
|
@class Host;
|
||||||
|
|
||||||
|
@interface App : NSManagedObject
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
#import "App+CoreDataProperties.h"
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// App.m
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Diego Waxemberg on 7/10/15.
|
||||||
|
// Copyright © 2015 Limelight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "App.h"
|
||||||
|
|
||||||
|
@implementation App
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -7,19 +7,25 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "Settings.h"
|
|
||||||
#import "AppDelegate.h"
|
#import "AppDelegate.h"
|
||||||
#import "Host.h"
|
#import "TemporaryHost.h"
|
||||||
|
#import "TemporaryApp.h"
|
||||||
|
#import "TemporarySettings.h"
|
||||||
|
|
||||||
@interface DataManager : NSObject
|
@interface DataManager : NSObject
|
||||||
|
|
||||||
@property (strong, nonatomic) AppDelegate* appDelegate;
|
|
||||||
|
|
||||||
- (void) saveSettingsWithBitrate:(NSInteger)bitrate framerate:(NSInteger)framerate height:(NSInteger)height width:(NSInteger)width onscreenControls:(NSInteger)onscreenControls;
|
- (void) saveSettingsWithBitrate:(NSInteger)bitrate framerate:(NSInteger)framerate height:(NSInteger)height width:(NSInteger)width onscreenControls:(NSInteger)onscreenControls;
|
||||||
- (Settings*) retrieveSettings;
|
|
||||||
- (NSArray*) retrieveHosts;
|
- (NSArray*) getHosts;
|
||||||
- (void) saveHosts;
|
- (void) updateHost:(TemporaryHost*)host;
|
||||||
- (Host*) createHost;
|
- (void) updateAppsForExistingHost:(TemporaryHost *)host;
|
||||||
- (void) removeHost:(Host*)host;
|
- (void) updateIconForExistingApp:(TemporaryApp*)app;
|
||||||
|
- (void) removeHost:(TemporaryHost*)host;
|
||||||
|
- (void) removeApp:(TemporaryApp*)app;
|
||||||
|
|
||||||
|
- (TemporarySettings*) getSettings;
|
||||||
|
|
||||||
|
- (void) updateUniqueId:(NSString*)uniqueId;
|
||||||
|
- (NSString*) getUniqueId;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -7,37 +7,132 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "DataManager.h"
|
#import "DataManager.h"
|
||||||
|
#import "TemporaryApp.h"
|
||||||
|
#import "TemporarySettings.h"
|
||||||
|
#import "Settings.h"
|
||||||
|
|
||||||
@implementation DataManager
|
@implementation DataManager {
|
||||||
|
NSManagedObjectContext *_managedObjectContext;
|
||||||
|
AppDelegate *_appDelegate;
|
||||||
|
}
|
||||||
|
|
||||||
- (id) init {
|
- (id) init {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
self.appDelegate = [[UIApplication sharedApplication] delegate];
|
|
||||||
|
_appDelegate = [[UIApplication sharedApplication] delegate];
|
||||||
|
_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
|
||||||
|
[_managedObjectContext setPersistentStoreCoordinator:_appDelegate.persistentStoreCoordinator];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) saveSettingsWithBitrate:(NSInteger)bitrate framerate:(NSInteger)framerate height:(NSInteger)height width:(NSInteger)width onscreenControls:(NSInteger)onscreenControls {
|
- (void) updateUniqueId:(NSString*)uniqueId {
|
||||||
Settings* settingsToSave = [self retrieveSettings];
|
[_managedObjectContext performBlockAndWait:^{
|
||||||
settingsToSave.framerate = [NSNumber numberWithInteger:framerate];
|
[self retrieveSettings].uniqueId = uniqueId;
|
||||||
// Bitrate is persisted in kbps
|
[self saveData];
|
||||||
settingsToSave.bitrate = [NSNumber numberWithInteger:bitrate];
|
}];
|
||||||
settingsToSave.height = [NSNumber numberWithInteger:height];
|
}
|
||||||
settingsToSave.width = [NSNumber numberWithInteger:width];
|
|
||||||
settingsToSave.onscreenControls = [NSNumber numberWithInteger:onscreenControls];
|
|
||||||
|
|
||||||
NSError* error;
|
- (NSString*) getUniqueId {
|
||||||
if (![[self.appDelegate managedObjectContext] save:&error]) {
|
__block NSString *uid;
|
||||||
Log(LOG_E, @"Unable to save settings to database: %@", error);
|
|
||||||
}
|
[_managedObjectContext performBlockAndWait:^{
|
||||||
[self.appDelegate saveContext];
|
uid = [self retrieveSettings].uniqueId;
|
||||||
|
}];
|
||||||
|
|
||||||
|
return uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) saveSettingsWithBitrate:(NSInteger)bitrate framerate:(NSInteger)framerate height:(NSInteger)height width:(NSInteger)width onscreenControls:(NSInteger)onscreenControls {
|
||||||
|
|
||||||
|
[_managedObjectContext performBlockAndWait:^{
|
||||||
|
Settings* settingsToSave = [self retrieveSettings];
|
||||||
|
settingsToSave.framerate = [NSNumber numberWithInteger:framerate];
|
||||||
|
// Bitrate is persisted in kbps
|
||||||
|
settingsToSave.bitrate = [NSNumber numberWithInteger:bitrate];
|
||||||
|
settingsToSave.height = [NSNumber numberWithInteger:height];
|
||||||
|
settingsToSave.width = [NSNumber numberWithInteger:width];
|
||||||
|
settingsToSave.onscreenControls = [NSNumber numberWithInteger:onscreenControls];
|
||||||
|
|
||||||
|
[self saveData];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) updateHost:(TemporaryHost *)host {
|
||||||
|
[_managedObjectContext performBlockAndWait:^{
|
||||||
|
// Add a new persistent managed object if one doesn't exist
|
||||||
|
Host* parent = [self getHostForTemporaryHost:host withHostRecords:[self fetchRecords:@"Host"]];
|
||||||
|
if (parent == nil) {
|
||||||
|
NSEntityDescription* entity = [NSEntityDescription entityForName:@"Host" inManagedObjectContext:_managedObjectContext];
|
||||||
|
parent = [[Host alloc] initWithEntity:entity insertIntoManagedObjectContext:_managedObjectContext];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push changes from the temp host to the persistent one
|
||||||
|
[host propagateChangesToParent:parent];
|
||||||
|
|
||||||
|
[self saveData];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) updateAppsForExistingHost:(TemporaryHost *)host {
|
||||||
|
[_managedObjectContext performBlockAndWait:^{
|
||||||
|
Host* parent = [self getHostForTemporaryHost:host withHostRecords:[self fetchRecords:@"Host"]];
|
||||||
|
if (parent == nil) {
|
||||||
|
// The host must exist to be updated
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSMutableSet *applist = [[NSMutableSet alloc] init];
|
||||||
|
NSArray *appRecords = [self fetchRecords:@"App"];
|
||||||
|
for (TemporaryApp* app in host.appList) {
|
||||||
|
// Add a new persistent managed object if one doesn't exist
|
||||||
|
App* parentApp = [self getAppForTemporaryApp:app withAppRecords:appRecords];
|
||||||
|
if (parentApp == nil) {
|
||||||
|
NSEntityDescription* entity = [NSEntityDescription entityForName:@"App" inManagedObjectContext:_managedObjectContext];
|
||||||
|
parentApp = [[App alloc] initWithEntity:entity insertIntoManagedObjectContext:_managedObjectContext];
|
||||||
|
}
|
||||||
|
|
||||||
|
[app propagateChangesToParent:parentApp withHost:parent];
|
||||||
|
|
||||||
|
[applist addObject:parentApp];
|
||||||
|
}
|
||||||
|
|
||||||
|
parent.appList = applist;
|
||||||
|
|
||||||
|
[self saveData];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) updateIconForExistingApp:(TemporaryApp*)app {
|
||||||
|
[_managedObjectContext performBlockAndWait:^{
|
||||||
|
App* parentApp = [self getAppForTemporaryApp:app withAppRecords:[self fetchRecords:@"App"]];
|
||||||
|
if (parentApp == nil) {
|
||||||
|
// The app must exist to be updated
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
parentApp.image = app.image;
|
||||||
|
|
||||||
|
[self saveData];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (TemporarySettings*) getSettings {
|
||||||
|
__block TemporarySettings *tempSettings;
|
||||||
|
|
||||||
|
[_managedObjectContext performBlockAndWait:^{
|
||||||
|
tempSettings = [[TemporarySettings alloc] initFromSettings:[self retrieveSettings]];
|
||||||
|
}];
|
||||||
|
|
||||||
|
return tempSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (Settings*) retrieveSettings {
|
- (Settings*) retrieveSettings {
|
||||||
NSArray* fetchedRecords = [self fetchRecords:@"Settings"];
|
NSArray* fetchedRecords = [self fetchRecords:@"Settings"];
|
||||||
if (fetchedRecords.count == 0) {
|
if (fetchedRecords.count == 0) {
|
||||||
// create a new settings object with the default values
|
// create a new settings object with the default values
|
||||||
NSEntityDescription* entity = [NSEntityDescription entityForName:@"Settings" inManagedObjectContext:[self.appDelegate managedObjectContext]];
|
NSEntityDescription* entity = [NSEntityDescription entityForName:@"Settings" inManagedObjectContext:_managedObjectContext];
|
||||||
Settings* settings = [[Settings alloc] initWithEntity:entity insertIntoManagedObjectContext:[self.appDelegate managedObjectContext]];
|
Settings* settings = [[Settings alloc] initWithEntity:entity insertIntoManagedObjectContext:_managedObjectContext];
|
||||||
|
|
||||||
return settings;
|
return settings;
|
||||||
} else {
|
} else {
|
||||||
@@ -46,40 +141,84 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (Host*) createHost {
|
- (void) removeApp:(TemporaryApp*)app {
|
||||||
NSEntityDescription* entity = [NSEntityDescription entityForName:@"Host" inManagedObjectContext:[self.appDelegate managedObjectContext]];
|
[_managedObjectContext performBlockAndWait:^{
|
||||||
Host* host = [[Host alloc] initWithEntity:entity insertIntoManagedObjectContext:[self.appDelegate managedObjectContext]];
|
App* managedApp = [self getAppForTemporaryApp:app withAppRecords:[self fetchRecords:@"App"]];
|
||||||
return host;
|
if (managedApp != nil) {
|
||||||
|
[_managedObjectContext deleteObject:managedApp];
|
||||||
|
[self saveData];
|
||||||
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeHost:(Host*)host {
|
- (void) removeHost:(TemporaryHost*)host {
|
||||||
[[self.appDelegate managedObjectContext] deleteObject:host];
|
[_managedObjectContext performBlockAndWait:^{
|
||||||
|
Host* managedHost = [self getHostForTemporaryHost:host withHostRecords:[self fetchRecords:@"Host"]];
|
||||||
|
if (managedHost != nil) {
|
||||||
|
[_managedObjectContext deleteObject:managedHost];
|
||||||
|
[self saveData];
|
||||||
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) saveHosts {
|
- (void) saveData {
|
||||||
NSError* error;
|
NSError* error;
|
||||||
if (![[self.appDelegate managedObjectContext] save:&error]) {
|
if (![_managedObjectContext save:&error]) {
|
||||||
Log(LOG_E, @"Unable to save hosts to database: %@", error);
|
Log(LOG_E, @"Unable to save hosts to database: %@", error);
|
||||||
}
|
}
|
||||||
[self.appDelegate saveContext];
|
|
||||||
|
[_appDelegate saveContext];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*) retrieveHosts {
|
- (NSArray*) getHosts {
|
||||||
return [self fetchRecords:@"Host"];
|
__block NSMutableArray *tempHosts = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
|
[_managedObjectContext performBlockAndWait:^{
|
||||||
|
NSArray *hosts = [self fetchRecords:@"Host"];
|
||||||
|
|
||||||
|
for (Host* host in hosts) {
|
||||||
|
[tempHosts addObject:[[TemporaryHost alloc] initFromHost:host]];
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
return tempHosts;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only call from within performBlockAndWait!!!
|
||||||
|
- (Host*) getHostForTemporaryHost:(TemporaryHost*)tempHost withHostRecords:(NSArray*)hosts {
|
||||||
|
for (Host* host in hosts) {
|
||||||
|
if ([tempHost.uuid isEqualToString:host.uuid]) {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only call from within performBlockAndWait!!!
|
||||||
|
- (App*) getAppForTemporaryApp:(TemporaryApp*)tempApp withAppRecords:(NSArray*)apps {
|
||||||
|
for (App* app in apps) {
|
||||||
|
if ([app.id isEqualToString:tempApp.id] &&
|
||||||
|
[app.host.uuid isEqualToString:app.host.uuid]) {
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*) fetchRecords:(NSString*)entityName {
|
- (NSArray*) fetchRecords:(NSString*)entityName {
|
||||||
|
NSArray* fetchedRecords;
|
||||||
|
|
||||||
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
|
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
|
||||||
NSEntityDescription* entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:[self.appDelegate managedObjectContext]];
|
NSEntityDescription* entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:_managedObjectContext];
|
||||||
[fetchRequest setEntity:entity];
|
[fetchRequest setEntity:entity];
|
||||||
[fetchRequest setAffectedStores:[NSArray arrayWithObjects:[[self.appDelegate persistentStoreCoordinator] persistentStoreForURL:[self.appDelegate getStoreURL]], nil]];
|
|
||||||
|
|
||||||
NSError* error;
|
NSError* error;
|
||||||
NSArray* fetchedRecords = [[self.appDelegate managedObjectContext] executeFetchRequest:fetchRequest error:&error];
|
fetchedRecords = [_managedObjectContext executeFetchRequest:fetchRequest error:&error];
|
||||||
//TODO: handle errors
|
//TODO: handle errors
|
||||||
|
|
||||||
return fetchedRecords;
|
return fetchedRecords;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
//
|
||||||
|
// Host+CoreDataProperties.h
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Diego Waxemberg on 7/10/15.
|
||||||
|
// Copyright © 2015 Limelight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
// Delete this file and regenerate it using "Create NSManagedObject Subclass…"
|
||||||
|
// to keep your implementation up to date with your model.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "Host.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface Host (CoreDataProperties)
|
||||||
|
|
||||||
|
@property (nullable, nonatomic, retain) NSString *address;
|
||||||
|
@property (nullable, nonatomic, retain) NSString *externalAddress;
|
||||||
|
@property (nullable, nonatomic, retain) NSString *localAddress;
|
||||||
|
@property (nullable, nonatomic, retain) NSString *mac;
|
||||||
|
@property (nullable, nonatomic, retain) NSString *name;
|
||||||
|
@property (nullable, nonatomic, retain) NSNumber *pairState;
|
||||||
|
@property (nullable, nonatomic, retain) NSString *uuid;
|
||||||
|
@property (nullable, nonatomic, retain) NSSet *appList;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface Host (CoreDataGeneratedAccessors)
|
||||||
|
|
||||||
|
- (void)addAppListObject:(NSManagedObject *)value;
|
||||||
|
- (void)removeAppListObject:(NSManagedObject *)value;
|
||||||
|
- (void)addAppList:(NSSet *)values;
|
||||||
|
- (void)removeAppList:(NSSet *)values;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
// Host.h
|
// Host.h
|
||||||
// Moonlight
|
// Moonlight
|
||||||
//
|
//
|
||||||
// Created by Diego Waxemberg on 10/28/14.
|
// Created by Diego Waxemberg on 7/10/15.
|
||||||
// Copyright (c) 2014 Moonlight Stream. All rights reserved.
|
// Copyright © 2015 Limelight Stream. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
@@ -12,13 +12,6 @@
|
|||||||
|
|
||||||
@interface Host : NSManagedObject
|
@interface Host : NSManagedObject
|
||||||
|
|
||||||
@property (nonatomic, retain) NSString * name;
|
|
||||||
@property (nonatomic, retain) NSString * address;
|
|
||||||
@property (nonatomic, retain) NSString * localAddress;
|
|
||||||
@property (nonatomic, retain) NSString * externalAddress;
|
|
||||||
@property (nonatomic, retain) NSString * uuid;
|
|
||||||
@property (nonatomic, retain) NSString * mac;
|
|
||||||
@property (nonatomic) BOOL online;
|
|
||||||
@property (nonatomic) PairState pairState;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
#import "Host+CoreDataProperties.h"
|
||||||
@@ -2,22 +2,12 @@
|
|||||||
// Host.m
|
// Host.m
|
||||||
// Moonlight
|
// Moonlight
|
||||||
//
|
//
|
||||||
// Created by Diego Waxemberg on 10/28/14.
|
// Created by Diego Waxemberg on 7/10/15.
|
||||||
// Copyright (c) 2014 Moonlight Stream. All rights reserved.
|
// Copyright © 2015 Limelight Stream. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "Host.h"
|
#import "Host.h"
|
||||||
|
|
||||||
|
|
||||||
@implementation Host
|
@implementation Host
|
||||||
|
|
||||||
@dynamic name;
|
|
||||||
@dynamic address;
|
|
||||||
@dynamic localAddress;
|
|
||||||
@dynamic externalAddress;
|
|
||||||
@dynamic uuid;
|
|
||||||
@dynamic mac;
|
|
||||||
@dynamic pairState;
|
|
||||||
@synthesize online;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -17,5 +17,6 @@
|
|||||||
@property (nonatomic, retain) NSNumber * height;
|
@property (nonatomic, retain) NSNumber * height;
|
||||||
@property (nonatomic, retain) NSNumber * width;
|
@property (nonatomic, retain) NSNumber * width;
|
||||||
@property (nonatomic, retain) NSNumber * onscreenControls;
|
@property (nonatomic, retain) NSNumber * onscreenControls;
|
||||||
|
@property (nonatomic, retain) NSString * uniqueId;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -16,5 +16,6 @@
|
|||||||
@dynamic height;
|
@dynamic height;
|
||||||
@dynamic width;
|
@dynamic width;
|
||||||
@dynamic onscreenControls;
|
@dynamic onscreenControls;
|
||||||
|
@dynamic uniqueId;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
//
|
||||||
|
// TemporaryApp.h
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Cameron Gutman on 9/30/15.
|
||||||
|
// Copyright © 2015 Moonlight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "TemporaryHost.h"
|
||||||
|
#import "App.h"
|
||||||
|
|
||||||
|
@interface TemporaryApp : NSObject
|
||||||
|
|
||||||
|
@property (nullable, nonatomic, retain) NSString *id;
|
||||||
|
@property (nullable, nonatomic, retain) NSData *image;
|
||||||
|
@property (nullable, nonatomic, retain) NSString *name;
|
||||||
|
@property (nonatomic) BOOL isRunning;
|
||||||
|
@property (nullable, nonatomic, retain) TemporaryHost *host;
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
- (id) initFromApp:(App*)app withTempHost:(TemporaryHost*)tempHost;
|
||||||
|
|
||||||
|
- (NSComparisonResult)compareName:(TemporaryApp *)other;
|
||||||
|
|
||||||
|
- (void) propagateChangesToParent:(App*)parent withHost:(Host*)host;
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
//
|
||||||
|
// TemporaryApp.m
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Cameron Gutman on 9/30/15.
|
||||||
|
// Copyright © 2015 Moonlight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "TemporaryApp.h"
|
||||||
|
#import "App.h"
|
||||||
|
|
||||||
|
@implementation TemporaryApp
|
||||||
|
|
||||||
|
- (id) initFromApp:(App*)app withTempHost:(TemporaryHost*)tempHost {
|
||||||
|
self = [self init];
|
||||||
|
|
||||||
|
self.id = app.id;
|
||||||
|
self.image = app.image;
|
||||||
|
self.name = app.name;
|
||||||
|
self.host = tempHost;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) propagateChangesToParent:(App*)parent withHost:(Host*)host {
|
||||||
|
parent.id = self.id;
|
||||||
|
parent.name = self.name;
|
||||||
|
parent.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSComparisonResult)compareName:(TemporaryApp *)other {
|
||||||
|
return [self.name caseInsensitiveCompare:other.name];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)hash {
|
||||||
|
return [self.host.uuid hash] * 31 + [self.id intValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isEqual:(id)object {
|
||||||
|
if (self == object) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (![object isKindOfClass:[App class]]) {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [self.host.uuid isEqualToString:((App*)object).host.uuid] &&
|
||||||
|
[self.id isEqualToString:((App*)object).id];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
//
|
||||||
|
// TemporaryHost.h
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Cameron Gutman on 12/1/15.
|
||||||
|
// Copyright © 2015 Moonlight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "Utils.h"
|
||||||
|
#import "Host.h"
|
||||||
|
|
||||||
|
@interface TemporaryHost : NSObject
|
||||||
|
|
||||||
|
@property (nonatomic) BOOL online;
|
||||||
|
@property (nonatomic) PairState pairState;
|
||||||
|
@property (nonatomic, nullable) NSString * activeAddress;
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@property (nonatomic, retain) NSString *address;
|
||||||
|
@property (nonatomic, retain) NSString *externalAddress;
|
||||||
|
@property (nonatomic, retain) NSString *localAddress;
|
||||||
|
@property (nonatomic, retain) NSString *mac;
|
||||||
|
@property (nonatomic, retain) NSString *name;
|
||||||
|
@property (nonatomic, retain) NSString *uuid;
|
||||||
|
@property (nonatomic, retain) NSMutableSet *appList;
|
||||||
|
|
||||||
|
- (id) initFromHost:(Host*)host;
|
||||||
|
|
||||||
|
- (NSComparisonResult)compareName:(TemporaryHost *)other;
|
||||||
|
|
||||||
|
- (void) propagateChangesToParent:(Host*)host;
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
//
|
||||||
|
// TemporaryHost.m
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Cameron Gutman on 12/1/15.
|
||||||
|
// Copyright © 2015 Moonlight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "DataManager.h"
|
||||||
|
#import "TemporaryHost.h"
|
||||||
|
#import "Host.h"
|
||||||
|
#import "TemporaryApp.h"
|
||||||
|
#import "App.h"
|
||||||
|
|
||||||
|
@implementation TemporaryHost
|
||||||
|
|
||||||
|
- (id) init {
|
||||||
|
self = [super init];
|
||||||
|
self.appList = [[NSMutableSet alloc] init];
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) initFromHost:(Host*)host {
|
||||||
|
self = [self init];
|
||||||
|
|
||||||
|
self.address = host.address;
|
||||||
|
self.externalAddress = host.externalAddress;
|
||||||
|
self.localAddress = host.localAddress;
|
||||||
|
self.mac = host.mac;
|
||||||
|
self.name = host.name;
|
||||||
|
self.uuid = host.uuid;
|
||||||
|
self.pairState = [host.pairState intValue];
|
||||||
|
|
||||||
|
NSMutableSet *appList = [[NSMutableSet alloc] init];
|
||||||
|
|
||||||
|
for (App* app in host.appList) {
|
||||||
|
TemporaryApp *tempApp = [[TemporaryApp alloc] initFromApp:app withTempHost:self];
|
||||||
|
[appList addObject:tempApp];
|
||||||
|
}
|
||||||
|
|
||||||
|
self.appList = appList;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) propagateChangesToParent:(Host*)parentHost {
|
||||||
|
parentHost.address = self.address;
|
||||||
|
parentHost.externalAddress = self.externalAddress;
|
||||||
|
parentHost.localAddress = self.localAddress;
|
||||||
|
parentHost.mac = self.mac;
|
||||||
|
parentHost.name = self.name;
|
||||||
|
parentHost.uuid = self.uuid;
|
||||||
|
parentHost.pairState = [NSNumber numberWithInt:self.pairState];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSComparisonResult)compareName:(TemporaryHost *)other {
|
||||||
|
return [self.name caseInsensitiveCompare:other.name];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)hash {
|
||||||
|
return [self.uuid hash];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isEqual:(id)object {
|
||||||
|
if (self == object) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (![object isKindOfClass:[Host class]]) {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [self.uuid isEqualToString:((Host*)object).uuid];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// TemporarySettings.h
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Cameron Gutman on 12/1/15.
|
||||||
|
// Copyright © 2015 Moonlight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "Settings.h"
|
||||||
|
|
||||||
|
@interface TemporarySettings : NSObject
|
||||||
|
|
||||||
|
@property (nonatomic, retain) Settings * parent;
|
||||||
|
|
||||||
|
@property (nonatomic, retain) NSNumber * bitrate;
|
||||||
|
@property (nonatomic, retain) NSNumber * framerate;
|
||||||
|
@property (nonatomic, retain) NSNumber * height;
|
||||||
|
@property (nonatomic, retain) NSNumber * width;
|
||||||
|
@property (nonatomic, retain) NSNumber * onscreenControls;
|
||||||
|
@property (nonatomic, retain) NSString * uniqueId;
|
||||||
|
|
||||||
|
- (id) initFromSettings:(Settings*)settings;
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// TemporarySettings.m
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Cameron Gutman on 12/1/15.
|
||||||
|
// Copyright © 2015 Moonlight Stream. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "TemporarySettings.h"
|
||||||
|
|
||||||
|
@implementation TemporarySettings
|
||||||
|
|
||||||
|
- (id) initFromSettings:(Settings*)settings {
|
||||||
|
self = [self init];
|
||||||
|
|
||||||
|
self.parent = settings;
|
||||||
|
|
||||||
|
self.bitrate = settings.bitrate;
|
||||||
|
self.framerate = settings.framerate;
|
||||||
|
self.height = settings.height;
|
||||||
|
self.width = settings.width;
|
||||||
|
self.onscreenControls = settings.onscreenControls;
|
||||||
|
self.uniqueId = settings.uniqueId;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -2,18 +2,17 @@
|
|||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "1x",
|
"filename" : "a_button_80x80@2x.png",
|
||||||
"filename" : "a_button_40x40@1x.png"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "2x",
|
"filename" : "a_button_120x120@3x.png",
|
||||||
"filename" : "a_button_80x80@2x.png"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "3x",
|
"scale" : "3x"
|
||||||
"filename" : "a_button_120x120@3x.png"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info" : {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 2.2 KiB |
@@ -71,6 +71,12 @@
|
|||||||
"idiom" : "ipad",
|
"idiom" : "ipad",
|
||||||
"filename" : "app_icon_152x152_@2x.png",
|
"filename" : "app_icon_152x152_@2x.png",
|
||||||
"scale" : "2x"
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size" : "83.5x83.5",
|
||||||
|
"idiom" : "ipad",
|
||||||
|
"filename" : "app_icon_167x167_@2x.png",
|
||||||
|
"scale" : "2x"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info" : {
|
||||||
|
|||||||
|
After Width: | Height: | Size: 59 KiB |
@@ -2,18 +2,17 @@
|
|||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "1x",
|
"filename" : "b_button_80x80@2x.png",
|
||||||
"filename" : "b_button_40x40@1x.png"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "2x",
|
"filename" : "b_button_120x120@3x.png",
|
||||||
"filename" : "b_button_80x80@2x.png"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "3x",
|
"scale" : "3x"
|
||||||
"filename" : "b_button_120x120@3x.png"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info" : {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 2.1 KiB |
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"info" : {
|
||||||
|
"version" : 1,
|
||||||
|
"author" : "xcode"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,18 +2,17 @@
|
|||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "1x",
|
"filename" : "down_61x75@2x.png",
|
||||||
"filename" : "down_31x38@1x.png"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "2x",
|
"filename" : "down_93x114@3x.png",
|
||||||
"filename" : "down_61x75@2x.png"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "3x",
|
"scale" : "3x"
|
||||||
"filename" : "down_93x114@3x.png"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info" : {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.2 KiB |
@@ -2,18 +2,17 @@
|
|||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "1x",
|
"filename" : "left_76x61@2x.png",
|
||||||
"filename" : "left_38x31@1x.png"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "2x",
|
"filename" : "left_114x92@3x.png",
|
||||||
"filename" : "left_76x61@2x.png"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "3x",
|
"scale" : "3x"
|
||||||
"filename" : "left_114x92@3x.png"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info" : {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 1.6 KiB |
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "2x",
|
||||||
|
"filename" : "play.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "3x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"version" : 1,
|
||||||
|
"author" : "xcode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 17 KiB |
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"filename" : "pull-arrow-light-14x31@1x.png",
|
||||||
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"filename" : "pull-arrow-light-28x61@2x.png",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"filename" : "pull-arrow-light-42x92@3x.png",
|
||||||
|
"scale" : "3x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"version" : 1,
|
||||||
|
"author" : "xcode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 901 B |
|
After Width: | Height: | Size: 812 B |
|
After Width: | Height: | Size: 1.5 KiB |
@@ -2,18 +2,17 @@
|
|||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "1x",
|
"filename" : "right_75x61@2x.png",
|
||||||
"filename" : "right_38x31@1x.png"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "2x",
|
"filename" : "right_114x93@3x.png",
|
||||||
"filename" : "right_75x61@2x.png"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "3x",
|
"scale" : "3x"
|
||||||
"filename" : "right_114x93@3x.png"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info" : {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.2 KiB |
@@ -2,18 +2,17 @@
|
|||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "1x",
|
"filename" : "up_61x76@2x.png",
|
||||||
"filename" : "up_31x39@1x.png"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "2x",
|
"filename" : "up_93x116@3x.png",
|
||||||
"filename" : "up_61x76@2x.png"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "3x",
|
"scale" : "3x"
|
||||||
"filename" : "up_93x116@3x.png"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info" : {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.3 KiB |
@@ -2,18 +2,17 @@
|
|||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "1x",
|
"filename" : "x_button_80x80@2x.png",
|
||||||
"filename" : "x_button_40x40@1x.png"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "2x",
|
"filename" : "x_button_120x120@3x.png",
|
||||||
"filename" : "x_button_80x80@2x.png"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "3x",
|
"scale" : "3x"
|
||||||
"filename" : "x_button_120x120@3x.png"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info" : {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 2.3 KiB |
@@ -2,18 +2,17 @@
|
|||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "1x",
|
"filename" : "y_button_80x80@2x.png",
|
||||||
"filename" : "y_button_40x40@1x.png"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "2x",
|
"filename" : "y_button_120x120@3x.png",
|
||||||
"filename" : "y_button_80x80@2x.png"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "3x",
|
"scale" : "3x"
|
||||||
"filename" : "y_button_120x120@3x.png"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info" : {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 2.1 KiB |
@@ -63,25 +63,30 @@
|
|||||||
BOOL l3Set;
|
BOOL l3Set;
|
||||||
BOOL r3Set;
|
BOOL r3Set;
|
||||||
|
|
||||||
|
BOOL _iPad;
|
||||||
|
CGRect _controlArea;
|
||||||
UIView* _view;
|
UIView* _view;
|
||||||
OnScreenControlsLevel _level;
|
OnScreenControlsLevel _level;
|
||||||
|
|
||||||
ControllerSupport *_controllerSupport;
|
ControllerSupport *_controllerSupport;
|
||||||
Controller *_controller;
|
Controller *_controller;
|
||||||
id<EdgeDetectionDelegate> _edgeDelegate;
|
id<EdgeDetectionDelegate> _edgeDelegate;
|
||||||
|
NSMutableArray* _deadTouches;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const float EDGE_WIDTH = .1;
|
static const float EDGE_WIDTH = .05;
|
||||||
|
|
||||||
//static const float BUTTON_SIZE = 50;
|
//static const float BUTTON_SIZE = 50;
|
||||||
static const float BUTTON_DIST = 20;
|
static const float BUTTON_DIST = 20;
|
||||||
static float BUTTON_CENTER_X;
|
static float BUTTON_CENTER_X;
|
||||||
static float BUTTON_CENTER_Y;
|
static float BUTTON_CENTER_Y;
|
||||||
|
|
||||||
static const float D_PAD_DIST = 15;
|
static const float D_PAD_DIST = 10;
|
||||||
static float D_PAD_CENTER_X;
|
static float D_PAD_CENTER_X;
|
||||||
static float D_PAD_CENTER_Y;
|
static float D_PAD_CENTER_Y;
|
||||||
|
|
||||||
|
static const float DEAD_ZONE_PADDING = 15;
|
||||||
|
|
||||||
static const double STICK_CLICK_RATE = 100;
|
static const double STICK_CLICK_RATE = 100;
|
||||||
static const float STICK_DEAD_ZONE = .1;
|
static const float STICK_DEAD_ZONE = .1;
|
||||||
static float STICK_INNER_SIZE;
|
static float STICK_INNER_SIZE;
|
||||||
@@ -117,6 +122,21 @@ static float L3_Y;
|
|||||||
_controller = [[Controller alloc] init];
|
_controller = [[Controller alloc] init];
|
||||||
_controller.playerIndex = 0;
|
_controller.playerIndex = 0;
|
||||||
_edgeDelegate = swipeDelegate;
|
_edgeDelegate = swipeDelegate;
|
||||||
|
_deadTouches = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
|
_iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
|
||||||
|
_controlArea = CGRectMake(0, 0, _view.frame.size.width, _view.frame.size.height);
|
||||||
|
if (_iPad)
|
||||||
|
{
|
||||||
|
// Cut down the control area on an iPad so the controls are more reachable
|
||||||
|
_controlArea.size.height = _view.frame.size.height / 2.0;
|
||||||
|
_controlArea.origin.y = _view.frame.size.height - _controlArea.size.height;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_controlArea.origin.x = _controlArea.size.width * EDGE_WIDTH;
|
||||||
|
_controlArea.size.width -= _controlArea.origin.x * 2;
|
||||||
|
}
|
||||||
|
|
||||||
_aButton = [CALayer layer];
|
_aButton = [CALayer layer];
|
||||||
_bButton = [CALayer layer];
|
_bButton = [CALayer layer];
|
||||||
@@ -167,10 +187,10 @@ static float L3_Y;
|
|||||||
|
|
||||||
[self hideButtons];
|
[self hideButtons];
|
||||||
[self hideBumpers];
|
[self hideBumpers];
|
||||||
|
[self hideL3R3];
|
||||||
[self drawTriggers];
|
[self drawTriggers];
|
||||||
[self drawStartSelect];
|
[self drawStartSelect];
|
||||||
[self drawSticks];
|
[self drawSticks];
|
||||||
[self drawL3R3];
|
|
||||||
break;
|
break;
|
||||||
case OnScreenControlsLevelAutoGCExtendedGamepad:
|
case OnScreenControlsLevelAutoGCExtendedGamepad:
|
||||||
// GCExtendedGamepad is missing R3, L3, and select
|
// GCExtendedGamepad is missing R3, L3, and select
|
||||||
@@ -219,8 +239,8 @@ static float L3_Y;
|
|||||||
// Start with the default complex layout
|
// Start with the default complex layout
|
||||||
[self setupComplexControls];
|
[self setupComplexControls];
|
||||||
|
|
||||||
START_Y = _view.frame.size.height * .9;
|
START_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
SELECT_Y = _view.frame.size.height * .9;
|
SELECT_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For GCGamepad controls we move triggers, start, and select
|
// For GCGamepad controls we move triggers, start, and select
|
||||||
@@ -229,7 +249,42 @@ static float L3_Y;
|
|||||||
// Start with the default complex layout
|
// Start with the default complex layout
|
||||||
[self setupComplexControls];
|
[self setupComplexControls];
|
||||||
|
|
||||||
// TODO
|
START_X = _controlArea.size.width * .6 + _controlArea.origin.x;
|
||||||
|
START_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
|
|
||||||
|
SELECT_X = _controlArea.size.width * .4 + _controlArea.origin.x;
|
||||||
|
SELECT_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
|
|
||||||
|
L2_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
|
L2_X = _controlArea.size.width * .1 + _controlArea.origin.x;
|
||||||
|
|
||||||
|
R2_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
|
R2_X = _controlArea.size.width * .9 + _controlArea.origin.x;
|
||||||
|
|
||||||
|
if (_iPad) {
|
||||||
|
START_X = _controlArea.size.width * .75 + _controlArea.origin.x;
|
||||||
|
START_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
|
|
||||||
|
SELECT_X = _controlArea.size.width * .25 + _controlArea.origin.x;
|
||||||
|
SELECT_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
|
|
||||||
|
// The analog sticks are kept closer to the sides on iPad
|
||||||
|
LS_CENTER_X = _controlArea.size.width * .18 + _controlArea.origin.x;
|
||||||
|
LS_CENTER_Y = _controlArea.size.height * .75 + _controlArea.origin.y;
|
||||||
|
RS_CENTER_X = _controlArea.size.width * .82 + _controlArea.origin.x;
|
||||||
|
RS_CENTER_Y = _controlArea.size.height * .75 + _controlArea.origin.y;
|
||||||
|
} else {
|
||||||
|
START_X = _controlArea.size.width * .6 + _controlArea.origin.x;
|
||||||
|
START_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
|
|
||||||
|
SELECT_X = _controlArea.size.width * .4 + _controlArea.origin.x;
|
||||||
|
SELECT_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
|
|
||||||
|
LS_CENTER_X = _controlArea.size.width * .25 + _controlArea.origin.x;
|
||||||
|
LS_CENTER_Y = _controlArea.size.height * .75 + _controlArea.origin.y;
|
||||||
|
RS_CENTER_X = _controlArea.size.width * .75 + _controlArea.origin.x;
|
||||||
|
RS_CENTER_Y = _controlArea.size.height * .75 + _controlArea.origin.y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For simple controls we move the triggers and buttons to the bottom
|
// For simple controls we move the triggers and buttons to the bottom
|
||||||
@@ -237,46 +292,59 @@ static float L3_Y;
|
|||||||
// Start with the default complex layout
|
// Start with the default complex layout
|
||||||
[self setupComplexControls];
|
[self setupComplexControls];
|
||||||
|
|
||||||
START_Y = _view.frame.size.height * .9;
|
START_X = _controlArea.size.width * .6 + _controlArea.origin.x;
|
||||||
SELECT_Y = _view.frame.size.height * .9;
|
START_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
|
|
||||||
L1_Y = _view.frame.size.height * .7;
|
SELECT_X = _controlArea.size.width * .4 + _controlArea.origin.x;
|
||||||
L2_Y = _view.frame.size.height * .9;
|
SELECT_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
L2_X = _view.frame.size.width * .1;
|
|
||||||
R1_Y = _view.frame.size.height * .7;
|
L2_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
R2_Y = _view.frame.size.height * .9;
|
L2_X = _controlArea.size.width * .1 + _controlArea.origin.x;
|
||||||
R2_X = _view.frame.size.width * .9;
|
|
||||||
|
R2_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
|
R2_X = _controlArea.size.width * .9 + _controlArea.origin.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setupComplexControls
|
- (void) setupComplexControls
|
||||||
{
|
{
|
||||||
D_PAD_CENTER_X = _view.frame.size.width * .15;
|
D_PAD_CENTER_X = _controlArea.size.width * .1 + _controlArea.origin.x;
|
||||||
D_PAD_CENTER_Y = _view.frame.size.height * .55;
|
D_PAD_CENTER_Y = _controlArea.size.height * .60 + _controlArea.origin.y;
|
||||||
BUTTON_CENTER_X = _view.frame.size.width * .85;
|
BUTTON_CENTER_X = _controlArea.size.width * .9 + _controlArea.origin.x;
|
||||||
BUTTON_CENTER_Y = _view.frame.size.height * .55;
|
BUTTON_CENTER_Y = _controlArea.size.height * .60 + _controlArea.origin.y;
|
||||||
|
|
||||||
LS_CENTER_X = _view.frame.size.width * .35;
|
if (_iPad)
|
||||||
LS_CENTER_Y = _view.frame.size.height * .75;
|
{
|
||||||
RS_CENTER_X = _view.frame.size.width * .65;
|
// The analog sticks are kept closer to the sides on iPad
|
||||||
RS_CENTER_Y = _view.frame.size.height * .75;
|
LS_CENTER_X = _controlArea.size.width * .22 + _controlArea.origin.x;
|
||||||
|
LS_CENTER_Y = _controlArea.size.height * .75 + _controlArea.origin.y;
|
||||||
|
RS_CENTER_X = _controlArea.size.width * .77 + _controlArea.origin.x;
|
||||||
|
RS_CENTER_Y = _controlArea.size.height * .75 + _controlArea.origin.y;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LS_CENTER_X = _controlArea.size.width * .35 + _controlArea.origin.x;
|
||||||
|
LS_CENTER_Y = _controlArea.size.height * .75 + _controlArea.origin.y;
|
||||||
|
RS_CENTER_X = _controlArea.size.width * .65 + _controlArea.origin.x;
|
||||||
|
RS_CENTER_Y = _controlArea.size.height * .75 + _controlArea.origin.y;
|
||||||
|
}
|
||||||
|
|
||||||
START_X = _view.frame.size.width * .6;
|
START_X = _controlArea.size.width * .9 + _controlArea.origin.x;
|
||||||
START_Y = _view.frame.size.height * .1;
|
START_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
SELECT_X = _view.frame.size.width * .4;
|
SELECT_X = _controlArea.size.width * .1 + _controlArea.origin.x;
|
||||||
SELECT_Y = _view.frame.size.height * .1;
|
SELECT_Y = _controlArea.size.height * .9 + _controlArea.origin.y;
|
||||||
|
|
||||||
L1_X = _view.frame.size.width * .15;
|
L1_X = _controlArea.size.width * .1 + _controlArea.origin.x;
|
||||||
L1_Y = _view.frame.size.height * .27;
|
L1_Y = _controlArea.size.height * .27 + _controlArea.origin.y;
|
||||||
L2_X = _view.frame.size.width * .15;
|
L2_X = _controlArea.size.width * .1 + _controlArea.origin.x;
|
||||||
L2_Y = _view.frame.size.height * .1;
|
L2_Y = _controlArea.size.height * .1 + _controlArea.origin.y;
|
||||||
R1_X = _view.frame.size.width * .85;
|
R1_X = _controlArea.size.width * .9 + _controlArea.origin.x;
|
||||||
R1_Y = _view.frame.size.height * .27;
|
R1_Y = _controlArea.size.height * .27 + _controlArea.origin.y;
|
||||||
R2_X = _view.frame.size.width * .85;
|
R2_X = _controlArea.size.width * .9 + _controlArea.origin.x;
|
||||||
R2_Y = _view.frame.size.height * .1;
|
R2_Y = _controlArea.size.height * .1 + _controlArea.origin.y;
|
||||||
L3_X = _view.frame.size.width * .25;
|
L3_X = _controlArea.size.width * .25 + _controlArea.origin.x;
|
||||||
L3_Y = _view.frame.size.height * .75;
|
L3_Y = _controlArea.size.height * .75 + _controlArea.origin.y;
|
||||||
R3_X = _view.frame.size.width * .75;
|
R3_X = _controlArea.size.width * .75 + _controlArea.origin.x;
|
||||||
R3_Y = _view.frame.size.height * .75;
|
R3_Y = _controlArea.size.height * .75 + _controlArea.origin.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) drawButtons {
|
- (void) drawButtons {
|
||||||
@@ -535,11 +603,14 @@ static float L3_Y;
|
|||||||
} else if (touch == _r3Touch) {
|
} else if (touch == _r3Touch) {
|
||||||
buttonTouch = true;
|
buttonTouch = true;
|
||||||
}
|
}
|
||||||
|
if ([_deadTouches containsObject:touch]) {
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (updated) {
|
if (updated) {
|
||||||
[_controllerSupport updateFinished:_controller];
|
[_controllerSupport updateFinished:_controller];
|
||||||
}
|
}
|
||||||
return updated || buttonTouch;
|
return updated || buttonTouch;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)handleTouchDownEvent:touches {
|
- (BOOL)handleTouchDownEvent:touches {
|
||||||
@@ -653,6 +724,10 @@ static float L3_Y;
|
|||||||
} else if ([_edge.presentationLayer hitTest:touchLocation]) {
|
} else if ([_edge.presentationLayer hitTest:touchLocation]) {
|
||||||
_edgeTouch = touch;
|
_edgeTouch = touch;
|
||||||
}
|
}
|
||||||
|
if (!updated && !stickTouch && [self isInDeadZone:touch]) {
|
||||||
|
[_deadTouches addObject:touch];
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (updated) {
|
if (updated) {
|
||||||
[_controllerSupport updateFinished:_controller];
|
[_controllerSupport updateFinished:_controller];
|
||||||
@@ -744,15 +819,123 @@ static float L3_Y;
|
|||||||
touched = true;
|
touched = true;
|
||||||
} else if (touch == _edgeTouch) {
|
} else if (touch == _edgeTouch) {
|
||||||
_edgeTouch = nil;
|
_edgeTouch = nil;
|
||||||
if (![_edge.presentationLayer hitTest:[touch locationInView:_view]]) {
|
if ([touch locationInView:_view].x >= _view.frame.size.width / 4) {
|
||||||
[_edgeDelegate edgeSwiped];
|
[_edgeDelegate edgeSwiped];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ([_deadTouches containsObject:touch]) {
|
||||||
|
[_deadTouches removeObject:touch];
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (updated) {
|
if (updated) {
|
||||||
[_controllerSupport updateFinished:_controller];
|
[_controllerSupport updateFinished:_controller];
|
||||||
}
|
}
|
||||||
|
|
||||||
return updated || touched;
|
return updated || touched;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL) isInDeadZone:(UITouch*) touch {
|
||||||
|
switch (_level) {
|
||||||
|
case OnScreenControlsLevelFull:
|
||||||
|
return [self isDpadDeadZone:touch]
|
||||||
|
|| [self isAbxyDeadZone:touch]
|
||||||
|
|| [self isTriggerDeadZone:touch]
|
||||||
|
|| [self isBumperDeadZone:touch]
|
||||||
|
|| [self isStartSelectDeadZone:touch];
|
||||||
|
case OnScreenControlsLevelSimple:
|
||||||
|
return [self isTriggerDeadZone:touch]
|
||||||
|
|| [self isStartSelectDeadZone:touch]
|
||||||
|
|| [self isL3R3DeadZone:touch];
|
||||||
|
case OnScreenControlsLevelAutoGCExtendedGamepad:
|
||||||
|
return [self isL3R3DeadZone:touch]
|
||||||
|
|| [self isStartSelectDeadZone:touch];
|
||||||
|
case OnScreenControlsLevelAutoGCGamepad:
|
||||||
|
return [self isTriggerDeadZone:touch]
|
||||||
|
|| [self isStartSelectDeadZone:touch];
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isDpadDeadZone:(UITouch*) touch {
|
||||||
|
return [self isDeadZone:touch
|
||||||
|
startX:_view.frame.origin.x
|
||||||
|
startY:_upButton.frame.origin.y
|
||||||
|
endX:_rightButton.frame.origin.x + _rightButton.frame.size.width
|
||||||
|
endY:_view.frame.origin.y + _view.frame.size.height];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isAbxyDeadZone:(UITouch*) touch {
|
||||||
|
return [self isDeadZone:touch
|
||||||
|
startX:_xButton.frame.origin.x
|
||||||
|
startY:_yButton.frame.origin.y
|
||||||
|
endX:_view.frame.origin.x + _view.frame.size.width
|
||||||
|
endY:_view.frame.origin.y + _view.frame.size.height];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isBumperDeadZone:(UITouch*) touch {
|
||||||
|
return [self isDeadZone:touch
|
||||||
|
startX:_view.frame.origin.x
|
||||||
|
startY:_l2Button.frame.origin.y + _l2Button.frame.size.height
|
||||||
|
endX:_l1Button.frame.origin.x + _l1Button.frame.size.width
|
||||||
|
endY:_upButton.frame.origin.y]
|
||||||
|
|| [self isDeadZone:touch
|
||||||
|
startX:_r2Button.frame.origin.x
|
||||||
|
startY:_r2Button.frame.origin.y + _r2Button.frame.size.height
|
||||||
|
endX:_view.frame.origin.x + _view.frame.size.width
|
||||||
|
endY:_yButton.frame.origin.y];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isTriggerDeadZone:(UITouch*) touch {
|
||||||
|
return [self isDeadZone:touch
|
||||||
|
startX:_view.frame.origin.x
|
||||||
|
startY:_l2Button.frame.origin.y
|
||||||
|
endX:_l2Button.frame.origin.x + _l2Button.frame.size.width
|
||||||
|
endY:_view.frame.origin.y + _view.frame.size.height]
|
||||||
|
|| [self isDeadZone:touch
|
||||||
|
startX:_r2Button.frame.origin.x
|
||||||
|
startY:_r2Button.frame.origin.y
|
||||||
|
endX:_view.frame.origin.x + _view.frame.size.width
|
||||||
|
endY:_view.frame.origin.y + _view.frame.size.height];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isL3R3DeadZone:(UITouch*) touch {
|
||||||
|
return [self isDeadZone:touch
|
||||||
|
startX:_view.frame.origin.x
|
||||||
|
startY:_l3Button.frame.origin.y
|
||||||
|
endX:_view.frame.origin.x
|
||||||
|
endY:_view.frame.origin.y + _view.frame.size.height]
|
||||||
|
|| [self isDeadZone:touch
|
||||||
|
startX:_r3Button.frame.origin.x
|
||||||
|
startY:_r3Button.frame.origin.y
|
||||||
|
endX:_view.frame.origin.x + _view.frame.size.width
|
||||||
|
endY:_view.frame.origin.y + _view.frame.size.height];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isStartSelectDeadZone:(UITouch*) touch {
|
||||||
|
return [self isDeadZone:touch
|
||||||
|
startX:_startButton.frame.origin.x
|
||||||
|
startY:_startButton.frame.origin.y
|
||||||
|
endX:_view.frame.origin.x + _view.frame.size.width
|
||||||
|
endY:_view.frame.origin.y + _view.frame.size.height]
|
||||||
|
|| [self isDeadZone:touch
|
||||||
|
startX:_view.frame.origin.x
|
||||||
|
startY:_selectButton.frame.origin.y
|
||||||
|
endX:_selectButton.frame.origin.x + _selectButton.frame.size.width
|
||||||
|
endY:_view.frame.origin.y + _view.frame.size.height];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isDeadZone:(UITouch*) touch startX:(float)deadZoneStartX startY:(float)deadZoneStartY endX:(float)deadZoneEndX endY:(float)deadZoneEndY {
|
||||||
|
deadZoneStartX -= DEAD_ZONE_PADDING;
|
||||||
|
deadZoneStartY -= DEAD_ZONE_PADDING;
|
||||||
|
deadZoneEndX += DEAD_ZONE_PADDING;
|
||||||
|
deadZoneEndY += DEAD_ZONE_PADDING;
|
||||||
|
|
||||||
|
CGPoint touchLocation = [touch locationInView:_view];
|
||||||
|
return (touchLocation.x > deadZoneStartX && touchLocation.x < deadZoneEndX
|
||||||
|
&& touchLocation.y > deadZoneStartY && touchLocation.y < deadZoneEndY);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
- (void) setupOnScreenControls:(ControllerSupport*)controllerSupport swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate {
|
- (void) setupOnScreenControls:(ControllerSupport*)controllerSupport swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate {
|
||||||
onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport swipeDelegate:swipeDelegate];
|
onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport swipeDelegate:swipeDelegate];
|
||||||
DataManager* dataMan = [[DataManager alloc] init];
|
DataManager* dataMan = [[DataManager alloc] init];
|
||||||
OnScreenControlsLevel level = (OnScreenControlsLevel)[[dataMan retrieveSettings].onscreenControls integerValue];
|
OnScreenControlsLevel level = (OnScreenControlsLevel)[[dataMan getSettings].onscreenControls integerValue];
|
||||||
|
|
||||||
if (level == OnScreenControlsLevelAuto) {
|
if (level == OnScreenControlsLevelAuto) {
|
||||||
[controllerSupport initAutoOnScreenControlMode:onScreenControls];
|
[controllerSupport initAutoOnScreenControlMode:onScreenControls];
|
||||||
@@ -67,10 +67,11 @@
|
|||||||
deltaX *= xDeltaFactor * screenFactor;
|
deltaX *= xDeltaFactor * screenFactor;
|
||||||
deltaY *= yDeltaFactor * screenFactor;
|
deltaY *= yDeltaFactor * screenFactor;
|
||||||
|
|
||||||
LiSendMouseMoveEvent(deltaX, deltaY);
|
if (deltaX != 0 || deltaY != 0) {
|
||||||
|
LiSendMouseMoveEvent(deltaX, deltaY);
|
||||||
touchMoved = true;
|
touchMoved = true;
|
||||||
touchLocation = currentLocation;
|
touchLocation = currentLocation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if ([[event allTouches] count] == 2) {
|
} else if ([[event allTouches] count] == 2) {
|
||||||
CGPoint firstLocation = [[[[event allTouches] allObjects] objectAtIndex:0] locationInView:self];
|
CGPoint firstLocation = [[[[event allTouches] allObjects] objectAtIndex:0] locationInView:self];
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>${EXECUTABLE_NAME}</string>
|
<string>${EXECUTABLE_NAME}</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
<string>com.moonlight-stream.$(PRODUCT_NAME:rfc1034identifier)</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
<string>6.0</string>
|
<string>6.0</string>
|
||||||
<key>CFBundleName</key>
|
<key>CFBundleName</key>
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>0.9.1</string>
|
<string>1.0.3</string>
|
||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
@@ -26,6 +26,11 @@
|
|||||||
<string>public.app-category.games</string>
|
<string>public.app-category.games</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>NSAppTransportSecurity</key>
|
||||||
|
<dict>
|
||||||
|
<key>NSAllowsArbitraryLoads</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
<key>UIAppFonts</key>
|
<key>UIAppFonts</key>
|
||||||
<array>
|
<array>
|
||||||
<string>Roboto-Black.ttf</string>
|
<string>Roboto-Black.ttf</string>
|
||||||
@@ -45,9 +50,9 @@
|
|||||||
<array>
|
<array>
|
||||||
<string>armv7</string>
|
<string>armv7</string>
|
||||||
</array>
|
</array>
|
||||||
<key>UIStatusBarHidden</key>
|
<key>UIRequiresFullScreen</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>UIStatusBarHidden~ipad</key>
|
<key>UIStatusBarHidden</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>UISupportedInterfaceOrientations</key>
|
<key>UISupportedInterfaceOrientations</key>
|
||||||
<array>
|
<array>
|
||||||
@@ -59,5 +64,7 @@
|
|||||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
</array>
|
</array>
|
||||||
|
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||||
|
<false/>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
@@ -3,6 +3,6 @@
|
|||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>_XCCurrentVersionName</key>
|
<key>_XCCurrentVersionName</key>
|
||||||
<string>Limelight 0.3.1.xcdatamodel</string>
|
<string>Moonlight v1.0-2.xcdatamodel</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="9057" systemVersion="15B42" minimumToolsVersion="Automatic">
|
||||||
|
<entity name="App" representedClassName="App" syncable="YES">
|
||||||
|
<attribute name="id" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="image" optional="YES" attributeType="Binary" allowsExternalBinaryDataStorage="YES" syncable="YES"/>
|
||||||
|
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
|
||||||
|
<relationship name="host" maxCount="1" deletionRule="Nullify" destinationEntity="Host" inverseName="appList" inverseEntity="Host" syncable="YES"/>
|
||||||
|
</entity>
|
||||||
|
<entity name="Host" representedClassName="Host" syncable="YES">
|
||||||
|
<attribute name="address" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="externalAddress" optional="YES" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="localAddress" optional="YES" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="mac" optional="YES" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="name" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="pairState" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
|
||||||
|
<attribute name="uuid" optional="YES" attributeType="String" syncable="YES"/>
|
||||||
|
<relationship name="appList" optional="YES" toMany="YES" deletionRule="Cascade" destinationEntity="App" inverseName="host" inverseEntity="App" syncable="YES"/>
|
||||||
|
</entity>
|
||||||
|
<entity name="Settings" representedClassName="Settings" syncable="YES">
|
||||||
|
<attribute name="bitrate" attributeType="Integer 32" defaultValueString="10000" syncable="YES"/>
|
||||||
|
<attribute name="framerate" attributeType="Integer 32" defaultValueString="60" syncable="YES"/>
|
||||||
|
<attribute name="height" attributeType="Integer 32" defaultValueString="720" syncable="YES"/>
|
||||||
|
<attribute name="onscreenControls" attributeType="Integer 32" defaultValueString="1" syncable="YES"/>
|
||||||
|
<attribute name="uniqueId" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="width" attributeType="Integer 32" defaultValueString="1280" syncable="YES"/>
|
||||||
|
</entity>
|
||||||
|
<elements>
|
||||||
|
<element name="App" positionX="0" positionY="54" width="128" height="105"/>
|
||||||
|
<element name="Host" positionX="0" positionY="0" width="128" height="163"/>
|
||||||
|
<element name="Settings" positionX="0" positionY="0" width="128" height="135"/>
|
||||||
|
</elements>
|
||||||
|
</model>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="9057" systemVersion="15B42" minimumToolsVersion="Automatic">
|
||||||
|
<entity name="App" representedClassName="App" syncable="YES">
|
||||||
|
<attribute name="id" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="image" optional="YES" attributeType="Binary" allowsExternalBinaryDataStorage="YES" syncable="YES"/>
|
||||||
|
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
|
||||||
|
<relationship name="host" maxCount="1" deletionRule="Nullify" destinationEntity="Host" inverseName="appList" inverseEntity="Host" syncable="YES"/>
|
||||||
|
</entity>
|
||||||
|
<entity name="Host" representedClassName="Host" syncable="YES">
|
||||||
|
<attribute name="address" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="externalAddress" optional="YES" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="localAddress" optional="YES" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="mac" optional="YES" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="name" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="pairState" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
|
||||||
|
<attribute name="uuid" optional="YES" attributeType="String" syncable="YES"/>
|
||||||
|
<relationship name="appList" optional="YES" toMany="YES" deletionRule="Cascade" destinationEntity="App" inverseName="host" inverseEntity="App" syncable="YES"/>
|
||||||
|
</entity>
|
||||||
|
<entity name="Settings" representedClassName="Settings" syncable="YES">
|
||||||
|
<attribute name="bitrate" attributeType="Integer 32" defaultValueString="10000" syncable="YES"/>
|
||||||
|
<attribute name="framerate" attributeType="Integer 32" defaultValueString="60" syncable="YES"/>
|
||||||
|
<attribute name="height" attributeType="Integer 32" defaultValueString="720" syncable="YES"/>
|
||||||
|
<attribute name="onscreenControls" attributeType="Integer 32" defaultValueString="1" syncable="YES"/>
|
||||||
|
<attribute name="uniqueId" optional="YES" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="width" attributeType="Integer 32" defaultValueString="1280" syncable="YES"/>
|
||||||
|
</entity>
|
||||||
|
<elements>
|
||||||
|
<element name="App" positionX="0" positionY="54" width="128" height="105"/>
|
||||||
|
<element name="Host" positionX="0" positionY="0" width="128" height="163"/>
|
||||||
|
<element name="Settings" positionX="0" positionY="0" width="128" height="135"/>
|
||||||
|
</elements>
|
||||||
|
</model>
|
||||||
@@ -7,20 +7,20 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "App.h"
|
#import "TemporaryApp.h"
|
||||||
#import "HttpManager.h"
|
#import "HttpManager.h"
|
||||||
#import "Host.h"
|
#import "TemporaryHost.h"
|
||||||
|
|
||||||
@protocol AppAssetCallback <NSObject>
|
@protocol AppAssetCallback <NSObject>
|
||||||
|
|
||||||
- (void) receivedAssetForApp:(App*)app;
|
- (void) receivedAssetForApp:(TemporaryApp*)app;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface AppAssetManager : NSObject
|
@interface AppAssetManager : NSObject
|
||||||
|
|
||||||
- (id) initWithCallback:(id<AppAssetCallback>)callback;
|
- (id) initWithCallback:(id<AppAssetCallback>)callback;
|
||||||
- (void) retrieveAssets:(NSArray*)appList fromHost:(Host*)host;
|
- (void) retrieveAssetsFromHost:(TemporaryHost*)host;
|
||||||
- (void) stopRetrieving;
|
- (void) stopRetrieving;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -15,8 +15,6 @@
|
|||||||
@implementation AppAssetManager {
|
@implementation AppAssetManager {
|
||||||
NSOperationQueue* _opQueue;
|
NSOperationQueue* _opQueue;
|
||||||
id<AppAssetCallback> _callback;
|
id<AppAssetCallback> _callback;
|
||||||
Host* _host;
|
|
||||||
NSMutableDictionary* _imageCache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const int MAX_REQUEST_COUNT = 4;
|
static const int MAX_REQUEST_COUNT = 4;
|
||||||
@@ -24,29 +22,22 @@ static const int MAX_REQUEST_COUNT = 4;
|
|||||||
- (id) initWithCallback:(id<AppAssetCallback>)callback {
|
- (id) initWithCallback:(id<AppAssetCallback>)callback {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
_callback = callback;
|
_callback = callback;
|
||||||
_imageCache = [[NSMutableDictionary alloc] init];
|
|
||||||
_opQueue = [[NSOperationQueue alloc] init];
|
_opQueue = [[NSOperationQueue alloc] init];
|
||||||
[_opQueue setMaxConcurrentOperationCount:MAX_REQUEST_COUNT];
|
[_opQueue setMaxConcurrentOperationCount:MAX_REQUEST_COUNT];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) retrieveAssets:(NSArray*)appList fromHost:(Host*)host {
|
- (void) retrieveAssetsFromHost:(TemporaryHost*)host {
|
||||||
Host* oldHost = _host;
|
for (TemporaryApp* app in host.appList) {
|
||||||
_host = host;
|
if (app.image == nil) {
|
||||||
BOOL useCache = [oldHost.uuid isEqualToString:_host.uuid];
|
AppAssetRetriever* retriever = [[AppAssetRetriever alloc] init];
|
||||||
Log(LOG_I, @"Using cached app images: %d", useCache);
|
retriever.app = app;
|
||||||
if (!useCache) {
|
retriever.host = host;
|
||||||
[_imageCache removeAllObjects];
|
retriever.callback = _callback;
|
||||||
}
|
|
||||||
for (App* app in appList) {
|
[_opQueue addOperation:retriever];
|
||||||
AppAssetRetriever* retriever = [[AppAssetRetriever alloc] init];
|
}
|
||||||
retriever.app = app;
|
|
||||||
retriever.host = _host;
|
|
||||||
retriever.callback = _callback;
|
|
||||||
retriever.cache = _imageCache;
|
|
||||||
retriever.useCache = useCache;
|
|
||||||
[_opQueue addOperation:retriever];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +45,7 @@ static const int MAX_REQUEST_COUNT = 4;
|
|||||||
[_opQueue cancelAllOperations];
|
[_opQueue cancelAllOperations];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) sendCallBackForApp:(App*)app {
|
- (void) sendCallBackForApp:(TemporaryApp*)app {
|
||||||
[_callback receivedAssetForApp:app];
|
[_callback receivedAssetForApp:app];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,16 +7,14 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "Host.h"
|
#import "TemporaryHost.h"
|
||||||
#import "App.h"
|
#import "TemporaryApp.h"
|
||||||
#import "AppAssetManager.h"
|
#import "AppAssetManager.h"
|
||||||
|
|
||||||
@interface AppAssetRetriever : NSOperation
|
@interface AppAssetRetriever : NSOperation
|
||||||
|
|
||||||
@property (nonatomic) Host* host;
|
@property (nonatomic) TemporaryHost* host;
|
||||||
@property (nonatomic) App* app;
|
@property (nonatomic) TemporaryApp* app;
|
||||||
@property (nonatomic) NSMutableDictionary* cache;
|
|
||||||
@property (nonatomic) id<AppAssetCallback> callback;
|
@property (nonatomic) id<AppAssetCallback> callback;
|
||||||
@property (nonatomic) BOOL useCache;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -11,45 +11,32 @@
|
|||||||
#import "CryptoManager.h"
|
#import "CryptoManager.h"
|
||||||
#import "AppAssetResponse.h"
|
#import "AppAssetResponse.h"
|
||||||
#import "HttpRequest.h"
|
#import "HttpRequest.h"
|
||||||
|
#import "IdManager.h"
|
||||||
|
|
||||||
@implementation AppAssetRetriever
|
@implementation AppAssetRetriever
|
||||||
static const double RETRY_DELAY = 2; // seconds
|
static const double RETRY_DELAY = 2; // seconds
|
||||||
static const int MAX_ATTEMPTS = 5;
|
static const int MAX_ATTEMPTS = 5;
|
||||||
|
|
||||||
|
|
||||||
- (void) main {
|
- (void) main {
|
||||||
UIImage* appImage = nil;
|
UIImage* appImage = nil;
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
while (![self isCancelled] && appImage == nil && attempts++ < MAX_ATTEMPTS) {
|
while (![self isCancelled] && appImage == nil && attempts++ < MAX_ATTEMPTS) {
|
||||||
if (self.useCache) {
|
|
||||||
@synchronized(self.cache) {
|
|
||||||
UIImage* cachedImage = [self.cache objectForKey:self.app.appId];
|
|
||||||
if (cachedImage != nil) {
|
|
||||||
appImage = cachedImage;
|
|
||||||
self.app.appImage = appImage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (appImage == nil) {
|
|
||||||
HttpManager* hMan = [[HttpManager alloc] initWithHost:_host.address uniqueId:[CryptoManager getUniqueID] deviceName:deviceName cert:[CryptoManager readCertFromFile]];
|
|
||||||
AppAssetResponse* appAssetResp = [[AppAssetResponse alloc] init];
|
|
||||||
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:appAssetResp withUrlRequest:[hMan newAppAssetRequestWithAppId:self.app.appId]]];
|
|
||||||
|
|
||||||
appImage = [UIImage imageWithData:appAssetResp.data];
|
HttpManager* hMan = [[HttpManager alloc] initWithHost:_host.activeAddress uniqueId:[IdManager getUniqueId] deviceName:deviceName cert:[CryptoManager readCertFromFile]];
|
||||||
self.app.appImage = appImage;
|
AppAssetResponse* appAssetResp = [[AppAssetResponse alloc] init];
|
||||||
if (appImage != nil) {
|
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:appAssetResp withUrlRequest:[hMan newAppAssetRequestWithAppId:self.app.id]]];
|
||||||
@synchronized(self.cache) {
|
|
||||||
[self.cache setObject:appImage forKey:self.app.appId];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[NSThread sleepForTimeInterval:RETRY_DELAY];
|
appImage = [UIImage imageWithData:appAssetResp.data];
|
||||||
|
self.app.image = UIImagePNGRepresentation(appImage);
|
||||||
|
|
||||||
|
if (![self isCancelled] && appImage == nil) {
|
||||||
|
[NSThread sleepForTimeInterval:RETRY_DELAY];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[self performSelectorOnMainThread:@selector(sendCallbackForApp:) withObject:self.app waitUntilDone:NO];
|
[self performSelectorOnMainThread:@selector(sendCallbackForApp:) withObject:self.app waitUntilDone:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) sendCallbackForApp:(App*)app {
|
- (void) sendCallbackForApp:(TemporaryApp*)app {
|
||||||
[self.callback receivedAssetForApp:app];
|
[self.callback receivedAssetForApp:app];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
@interface AppListResponse : NSObject <Response>
|
@interface AppListResponse : NSObject <Response>
|
||||||
|
|
||||||
- (void)populateWithData:(NSData *)data;
|
- (void)populateWithData:(NSData *)data;
|
||||||
- (NSArray*) getAppList;
|
- (NSSet*) getAppList;
|
||||||
- (BOOL) isStatusOk;
|
- (BOOL) isStatusOk;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -7,11 +7,12 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "AppListResponse.h"
|
#import "AppListResponse.h"
|
||||||
#import "App.h"
|
#import "TemporaryApp.h"
|
||||||
|
#import "DataManager.h"
|
||||||
#import <libxml2/libxml/xmlreader.h>
|
#import <libxml2/libxml/xmlreader.h>
|
||||||
|
|
||||||
@implementation AppListResponse {
|
@implementation AppListResponse {
|
||||||
NSMutableArray* _appList;
|
NSMutableSet* _appList;
|
||||||
}
|
}
|
||||||
@synthesize data, statusCode, statusMessage;
|
@synthesize data, statusCode, statusMessage;
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning";
|
|||||||
|
|
||||||
- (void)populateWithData:(NSData *)xml {
|
- (void)populateWithData:(NSData *)xml {
|
||||||
self.data = xml;
|
self.data = xml;
|
||||||
_appList = [[NSMutableArray alloc] init];
|
_appList = [[NSMutableSet alloc] init];
|
||||||
[self parseData];
|
[self parseData];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,8 +65,8 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning";
|
|||||||
//Log(LOG_D, @"node: %s", node->name);
|
//Log(LOG_D, @"node: %s", node->name);
|
||||||
if (!xmlStrcmp(node->name, (xmlChar*)TAG_APP)) {
|
if (!xmlStrcmp(node->name, (xmlChar*)TAG_APP)) {
|
||||||
xmlNodePtr appInfoNode = node->xmlChildrenNode;
|
xmlNodePtr appInfoNode = node->xmlChildrenNode;
|
||||||
NSString* appName;
|
NSString* appName = @"";
|
||||||
NSString* appId;
|
NSString* appId = nil;
|
||||||
BOOL appIsRunning = NO;
|
BOOL appIsRunning = NO;
|
||||||
while (appInfoNode != NULL) {
|
while (appInfoNode != NULL) {
|
||||||
if (!xmlStrcmp(appInfoNode->name, (xmlChar*)TAG_APP_TITLE)) {
|
if (!xmlStrcmp(appInfoNode->name, (xmlChar*)TAG_APP_TITLE)) {
|
||||||
@@ -93,11 +94,11 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning";
|
|||||||
}
|
}
|
||||||
appInfoNode = appInfoNode->next;
|
appInfoNode = appInfoNode->next;
|
||||||
}
|
}
|
||||||
App* app = [[App alloc] init];
|
if (appId != nil) {
|
||||||
app.appName = appName;
|
TemporaryApp* app = [[TemporaryApp alloc] init];
|
||||||
app.appId = appId;
|
app.name = appName;
|
||||||
app.isRunning = appIsRunning;
|
app.id = appId;
|
||||||
if (app.appId != nil) {
|
app.isRunning = appIsRunning;
|
||||||
[_appList addObject:app];
|
[_appList addObject:app];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,7 +108,7 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning";
|
|||||||
xmlFreeDoc(docPtr);
|
xmlFreeDoc(docPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*) getAppList {
|
- (NSSet*) getAppList {
|
||||||
return _appList;
|
return _appList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "MDNSManager.h"
|
#import "MDNSManager.h"
|
||||||
#import "Host.h"
|
#import "TemporaryHost.h"
|
||||||
|
|
||||||
@protocol DiscoveryCallback <NSObject>
|
@protocol DiscoveryCallback <NSObject>
|
||||||
|
|
||||||
@@ -22,8 +22,8 @@
|
|||||||
- (void) startDiscovery;
|
- (void) startDiscovery;
|
||||||
- (void) stopDiscovery;
|
- (void) stopDiscovery;
|
||||||
- (void) stopDiscoveryBlocking;
|
- (void) stopDiscoveryBlocking;
|
||||||
- (BOOL) addHostToDiscovery:(Host*)host;
|
- (BOOL) addHostToDiscovery:(TemporaryHost*)host;
|
||||||
- (void) removeHostFromDiscovery:(Host*)host;
|
- (void) removeHostFromDiscovery:(TemporaryHost*)host;
|
||||||
- (void) discoverHost:(NSString*)hostAddress withCallback:(void (^)(Host*, NSString*))callback;
|
- (void) discoverHost:(NSString*)hostAddress withCallback:(void (^)(TemporaryHost*, NSString*))callback;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -13,10 +13,10 @@
|
|||||||
#import "DataManager.h"
|
#import "DataManager.h"
|
||||||
#import "DiscoveryWorker.h"
|
#import "DiscoveryWorker.h"
|
||||||
#import "ServerInfoResponse.h"
|
#import "ServerInfoResponse.h"
|
||||||
|
#import "IdManager.h"
|
||||||
|
|
||||||
@implementation DiscoveryManager {
|
@implementation DiscoveryManager {
|
||||||
NSMutableArray* _hostQueue;
|
NSMutableArray* _hostQueue;
|
||||||
NSMutableArray* _discoveredHosts;
|
|
||||||
id<DiscoveryCallback> _callback;
|
id<DiscoveryCallback> _callback;
|
||||||
MDNSManager* _mdnsMan;
|
MDNSManager* _mdnsMan;
|
||||||
NSOperationQueue* _opQueue;
|
NSOperationQueue* _opQueue;
|
||||||
@@ -27,31 +27,38 @@
|
|||||||
|
|
||||||
- (id)initWithHosts:(NSArray *)hosts andCallback:(id<DiscoveryCallback>)callback {
|
- (id)initWithHosts:(NSArray *)hosts andCallback:(id<DiscoveryCallback>)callback {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
_hostQueue = [NSMutableArray arrayWithArray:hosts];
|
|
||||||
|
// Using addHostToDiscovery ensures no duplicates
|
||||||
|
// will make it into the list from the database
|
||||||
_callback = callback;
|
_callback = callback;
|
||||||
|
shouldDiscover = NO;
|
||||||
|
_hostQueue = [NSMutableArray array];
|
||||||
|
for (TemporaryHost* host in hosts)
|
||||||
|
{
|
||||||
|
[self addHostToDiscovery:host];
|
||||||
|
}
|
||||||
|
[_callback updateAllHosts:_hostQueue];
|
||||||
|
|
||||||
_opQueue = [[NSOperationQueue alloc] init];
|
_opQueue = [[NSOperationQueue alloc] init];
|
||||||
_mdnsMan = [[MDNSManager alloc] initWithCallback:self];
|
_mdnsMan = [[MDNSManager alloc] initWithCallback:self];
|
||||||
[CryptoManager generateKeyPairUsingSSl];
|
[CryptoManager generateKeyPairUsingSSl];
|
||||||
_uniqueId = [CryptoManager getUniqueID];
|
_uniqueId = [IdManager getUniqueId];
|
||||||
_cert = [CryptoManager readCertFromFile];
|
_cert = [CryptoManager readCertFromFile];
|
||||||
shouldDiscover = NO;
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) discoverHost:(NSString *)hostAddress withCallback:(void (^)(Host *, NSString*))callback {
|
- (void) discoverHost:(NSString *)hostAddress withCallback:(void (^)(TemporaryHost *, NSString*))callback {
|
||||||
HttpManager* hMan = [[HttpManager alloc] initWithHost:hostAddress uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
HttpManager* hMan = [[HttpManager alloc] initWithHost:hostAddress uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
||||||
ServerInfoResponse* serverInfoResponse = [[ServerInfoResponse alloc] init];
|
ServerInfoResponse* serverInfoResponse = [[ServerInfoResponse alloc] init];
|
||||||
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResponse withUrlRequest:[hMan newServerInfoRequest]]];
|
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResponse withUrlRequest:[hMan newServerInfoRequest] fallbackError:401 fallbackRequest:[hMan newHttpServerInfoRequest]]];
|
||||||
|
|
||||||
Host* host = nil;
|
TemporaryHost* host = nil;
|
||||||
if ([serverInfoResponse isStatusOk]) {
|
if ([serverInfoResponse isStatusOk]) {
|
||||||
DataManager* dataMan = [[DataManager alloc] init];
|
host = [[TemporaryHost alloc] init];
|
||||||
host = [dataMan createHost];
|
host.activeAddress = host.address = hostAddress;
|
||||||
host.address = hostAddress;
|
|
||||||
host.online = YES;
|
host.online = YES;
|
||||||
[serverInfoResponse populateHost:host];
|
[serverInfoResponse populateHost:host];
|
||||||
if (![self addHostToDiscovery:host]) {
|
if (![self addHostToDiscovery:host]) {
|
||||||
[dataMan removeHost:host];
|
|
||||||
callback(nil, @"Host already added");
|
callback(nil, @"Host already added");
|
||||||
} else {
|
} else {
|
||||||
callback(host, nil);
|
callback(host, nil);
|
||||||
@@ -66,7 +73,7 @@
|
|||||||
Log(LOG_I, @"Starting discovery");
|
Log(LOG_I, @"Starting discovery");
|
||||||
shouldDiscover = YES;
|
shouldDiscover = YES;
|
||||||
[_mdnsMan searchForHosts];
|
[_mdnsMan searchForHosts];
|
||||||
for (Host* host in _hostQueue) {
|
for (TemporaryHost* host in _hostQueue) {
|
||||||
[_opQueue addOperation:[self createWorkerForHost:host]];
|
[_opQueue addOperation:[self createWorkerForHost:host]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,7 +94,7 @@
|
|||||||
Log(LOG_I, @"All discovery workers stopped");
|
Log(LOG_I, @"All discovery workers stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) addHostToDiscovery:(Host *)host {
|
- (BOOL) addHostToDiscovery:(TemporaryHost *)host {
|
||||||
if (host.uuid.length > 0 && ![self isHostInDiscovery:host]) {
|
if (host.uuid.length > 0 && ![self isHostInDiscovery:host]) {
|
||||||
[_hostQueue addObject:host];
|
[_hostQueue addObject:host];
|
||||||
if (shouldDiscover) {
|
if (shouldDiscover) {
|
||||||
@@ -98,7 +105,7 @@
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeHostFromDiscovery:(Host *)host {
|
- (void) removeHostFromDiscovery:(TemporaryHost *)host {
|
||||||
for (DiscoveryWorker* worker in [_opQueue operations]) {
|
for (DiscoveryWorker* worker in [_opQueue operations]) {
|
||||||
if ([worker getHost] == host) {
|
if ([worker getHost] == host) {
|
||||||
[worker cancel];
|
[worker cancel];
|
||||||
@@ -110,9 +117,8 @@
|
|||||||
// Override from MDNSCallback
|
// Override from MDNSCallback
|
||||||
- (void)updateHosts:(NSArray *)hosts {
|
- (void)updateHosts:(NSArray *)hosts {
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
DataManager* dataMan = [[DataManager alloc] init];
|
|
||||||
// Discover the hosts before adding to eliminate duplicates
|
// Discover the hosts before adding to eliminate duplicates
|
||||||
for (Host* host in hosts) {
|
for (TemporaryHost* host in hosts) {
|
||||||
Log(LOG_I, @"Found host through MDNS: %@:", host.name);
|
Log(LOG_I, @"Found host through MDNS: %@:", host.name);
|
||||||
// Since this is on a background thread, we do not need to use the opQueue
|
// Since this is on a background thread, we do not need to use the opQueue
|
||||||
DiscoveryWorker* worker = (DiscoveryWorker*)[self createWorkerForHost:host];
|
DiscoveryWorker* worker = (DiscoveryWorker*)[self createWorkerForHost:host];
|
||||||
@@ -122,16 +128,14 @@
|
|||||||
[_callback updateAllHosts:_hostQueue];
|
[_callback updateAllHosts:_hostQueue];
|
||||||
} else {
|
} else {
|
||||||
Log(LOG_I, @"Not adding host to discovery: %@", host.name);
|
Log(LOG_I, @"Not adding host to discovery: %@", host.name);
|
||||||
[dataMan removeHost:host];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[dataMan saveHosts];
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isHostInDiscovery:(Host*)host {
|
- (BOOL) isHostInDiscovery:(TemporaryHost*)host {
|
||||||
for (int i = 0; i < _hostQueue.count; i++) {
|
for (int i = 0; i < _hostQueue.count; i++) {
|
||||||
Host* discoveredHost = [_hostQueue objectAtIndex:i];
|
TemporaryHost* discoveredHost = [_hostQueue objectAtIndex:i];
|
||||||
if (discoveredHost.uuid.length > 0 && [discoveredHost.uuid isEqualToString:host.uuid]) {
|
if (discoveredHost.uuid.length > 0 && [discoveredHost.uuid isEqualToString:host.uuid]) {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
@@ -139,7 +143,7 @@
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSOperation*) createWorkerForHost:(Host*)host {
|
- (NSOperation*) createWorkerForHost:(TemporaryHost*)host {
|
||||||
DiscoveryWorker* worker = [[DiscoveryWorker alloc] initWithHost:host uniqueId:_uniqueId cert:_cert];
|
DiscoveryWorker* worker = [[DiscoveryWorker alloc] initWithHost:host uniqueId:_uniqueId cert:_cert];
|
||||||
return worker;
|
return worker;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,12 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "Host.h"
|
#import "TemporaryHost.h"
|
||||||
|
|
||||||
@interface DiscoveryWorker : NSOperation
|
@interface DiscoveryWorker : NSOperation
|
||||||
|
|
||||||
- (id) initWithHost:(Host*)host uniqueId:(NSString*)uniqueId cert:(NSData*)cert;
|
- (id) initWithHost:(TemporaryHost*)host uniqueId:(NSString*)uniqueId cert:(NSData*)cert;
|
||||||
- (void) discoverHost;
|
- (void) discoverHost;
|
||||||
- (Host*) getHost;
|
- (TemporaryHost*) getHost;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -11,16 +11,17 @@
|
|||||||
#import "HttpManager.h"
|
#import "HttpManager.h"
|
||||||
#import "ServerInfoResponse.h"
|
#import "ServerInfoResponse.h"
|
||||||
#import "HttpRequest.h"
|
#import "HttpRequest.h"
|
||||||
|
#import "DataManager.h"
|
||||||
|
|
||||||
@implementation DiscoveryWorker {
|
@implementation DiscoveryWorker {
|
||||||
Host* _host;
|
TemporaryHost* _host;
|
||||||
NSString* _uniqueId;
|
NSString* _uniqueId;
|
||||||
NSData* _cert;
|
NSData* _cert;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const float POLL_RATE = 2.0f; // Poll every 2 seconds
|
static const float POLL_RATE = 2.0f; // Poll every 2 seconds
|
||||||
|
|
||||||
- (id) initWithHost:(Host*)host uniqueId:(NSString*)uniqueId cert:(NSData*)cert {
|
- (id) initWithHost:(TemporaryHost*)host uniqueId:(NSString*)uniqueId cert:(NSData*)cert {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
_host = host;
|
_host = host;
|
||||||
_uniqueId = uniqueId;
|
_uniqueId = uniqueId;
|
||||||
@@ -28,7 +29,7 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (Host*) getHost {
|
- (TemporaryHost*) getHost {
|
||||||
return _host;
|
return _host;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,23 +42,88 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSArray*) getHostAddressList {
|
||||||
|
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:3];
|
||||||
|
|
||||||
|
if (_host.localAddress != nil) {
|
||||||
|
[array addObject:_host.localAddress];
|
||||||
|
}
|
||||||
|
if (_host.externalAddress != nil) {
|
||||||
|
[array addObject:_host.externalAddress];
|
||||||
|
}
|
||||||
|
if (_host.address != nil) {
|
||||||
|
[array addObject:_host.address];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove duplicate addresses from the list.
|
||||||
|
// This is done using an array rather than a set
|
||||||
|
// to preserve insertion order of addresses.
|
||||||
|
for (int i = 0; i < [array count]; i++) {
|
||||||
|
NSString *addr1 = [array objectAtIndex:i];
|
||||||
|
|
||||||
|
for (int j = 1; j < [array count]; j++) {
|
||||||
|
if (i == j) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *addr2 = [array objectAtIndex:j];
|
||||||
|
|
||||||
|
if ([addr1 isEqualToString:addr2]) {
|
||||||
|
// Remove the last address
|
||||||
|
[array removeObjectAtIndex:j];
|
||||||
|
|
||||||
|
// Begin searching again from the start
|
||||||
|
i = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) discoverHost {
|
- (void) discoverHost {
|
||||||
BOOL receivedResponse = NO;
|
BOOL receivedResponse = NO;
|
||||||
if (!self.cancelled && _host.localAddress != nil) {
|
NSArray *addresses = [self getHostAddressList];
|
||||||
ServerInfoResponse* serverInfoResp = [self requestInfoAtAddress:_host.localAddress];
|
|
||||||
receivedResponse = [self checkResponse:serverInfoResp];
|
Log(LOG_D, @"%@ has %d unique addresses", _host.name, [addresses count]);
|
||||||
}
|
|
||||||
if (!self.cancelled && !receivedResponse && _host.externalAddress != nil) {
|
// Give the PC 3 tries to respond before declaring it offline
|
||||||
ServerInfoResponse* serverInfoResp = [self requestInfoAtAddress:_host.externalAddress];
|
for (int i = 0; i < 3; i++) {
|
||||||
receivedResponse = [self checkResponse:serverInfoResp];
|
for (NSString *address in addresses) {
|
||||||
}
|
if (self.cancelled) {
|
||||||
if (!self.cancelled && !receivedResponse && _host.address != nil) {
|
// Get out without updating the status because
|
||||||
ServerInfoResponse* serverInfoResp = [self requestInfoAtAddress:_host.address];
|
// it might not have finished checking the various
|
||||||
receivedResponse = [self checkResponse:serverInfoResp];
|
// addresses
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerInfoResponse* serverInfoResp = [self requestInfoAtAddress:address];
|
||||||
|
receivedResponse = [self checkResponse:serverInfoResp];
|
||||||
|
if (receivedResponse) {
|
||||||
|
[serverInfoResp populateHost:_host];
|
||||||
|
_host.activeAddress = address;
|
||||||
|
|
||||||
|
// Update the database using the response
|
||||||
|
DataManager *dataManager = [[DataManager alloc] init];
|
||||||
|
[dataManager updateHost:_host];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (receivedResponse) {
|
||||||
|
Log(LOG_I, @"Received serverinfo response on try %d", i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Wait for one second then retry
|
||||||
|
[NSThread sleepForTimeInterval:1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_host.online = receivedResponse;
|
_host.online = receivedResponse;
|
||||||
if (receivedResponse) {
|
if (receivedResponse) {
|
||||||
Log(LOG_D, @"Received response from: %@\n{\n\t address:%@ \n\t localAddress:%@ \n\t externalAddress:%@ \n\t uuid:%@ \n\t mac:%@ \n\t pairState:%d \n\t online:%d \n}", _host.name, _host.address, _host.localAddress, _host.externalAddress, _host.uuid, _host.mac, _host.pairState, _host.online);
|
Log(LOG_D, @"Received response from: %@\n{\n\t address:%@ \n\t localAddress:%@ \n\t externalAddress:%@ \n\t uuid:%@ \n\t mac:%@ \n\t pairState:%d \n\t online:%d \n\t activeAddress:%@ \n}", _host.name, _host.address, _host.localAddress, _host.externalAddress, _host.uuid, _host.mac, _host.pairState, _host.online, _host.activeAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +134,8 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds
|
|||||||
cert:_cert];
|
cert:_cert];
|
||||||
ServerInfoResponse* response = [[ServerInfoResponse alloc] init];
|
ServerInfoResponse* response = [[ServerInfoResponse alloc] init];
|
||||||
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:response
|
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:response
|
||||||
withUrlRequest:[hMan newServerInfoRequest]]];
|
withUrlRequest:[hMan newServerInfoRequest]
|
||||||
|
fallbackError:401 fallbackRequest:[hMan newHttpServerInfoRequest]]];
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +143,6 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds
|
|||||||
if ([response isStatusOk]) {
|
if ([response isStatusOk]) {
|
||||||
// If the response is from a different host then do not update this host
|
// If the response is from a different host then do not update this host
|
||||||
if ((_host.uuid == nil || [[response getStringTag:TAG_UNIQUE_ID] isEqualToString:_host.uuid])) {
|
if ((_host.uuid == nil || [[response getStringTag:TAG_UNIQUE_ID] isEqualToString:_host.uuid])) {
|
||||||
[response populateHost:_host];
|
|
||||||
return YES;
|
return YES;
|
||||||
} else {
|
} else {
|
||||||
Log(LOG_I, @"Received response from incorrect host: %@ expected: %@", [response getStringTag:TAG_UNIQUE_ID], _host.uuid);
|
Log(LOG_I, @"Received response from incorrect host: %@ expected: %@", [response getStringTag:TAG_UNIQUE_ID], _host.uuid);
|
||||||
|
|||||||
@@ -7,11 +7,10 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "Host.h"
|
|
||||||
#import "HttpResponse.h"
|
#import "HttpResponse.h"
|
||||||
#import "HttpRequest.h"
|
#import "HttpRequest.h"
|
||||||
|
|
||||||
@interface HttpManager : NSObject <NSURLConnectionDelegate, NSURLConnectionDataDelegate>
|
@interface HttpManager : NSObject <NSURLSessionDelegate>
|
||||||
|
|
||||||
- (id) initWithHost:(NSString*) host uniqueId:(NSString*) uniqueId deviceName:(NSString*) deviceName cert:(NSData*) cert;
|
- (id) initWithHost:(NSString*) host uniqueId:(NSString*) uniqueId deviceName:(NSString*) deviceName cert:(NSData*) cert;
|
||||||
- (NSURLRequest*) newPairRequest:(NSData*)salt;
|
- (NSURLRequest*) newPairRequest:(NSData*)salt;
|
||||||
@@ -22,12 +21,12 @@
|
|||||||
- (NSURLRequest*) newPairChallenge;
|
- (NSURLRequest*) newPairChallenge;
|
||||||
- (NSURLRequest*) newAppListRequest;
|
- (NSURLRequest*) newAppListRequest;
|
||||||
- (NSURLRequest*) newServerInfoRequest;
|
- (NSURLRequest*) newServerInfoRequest;
|
||||||
|
- (NSURLRequest*) newHttpServerInfoRequest;
|
||||||
- (NSURLRequest*) newLaunchRequest:(NSString*)appId width:(int)width height:(int)height refreshRate:(int)refreshRate rikey:(NSString*)rikey rikeyid:(int)rikeyid;
|
- (NSURLRequest*) newLaunchRequest:(NSString*)appId width:(int)width height:(int)height refreshRate:(int)refreshRate rikey:(NSString*)rikey rikeyid:(int)rikeyid;
|
||||||
- (NSURLRequest*) newResumeRequestWithRiKey:(NSString*)riKey riKeyId:(int)riKeyId;
|
- (NSURLRequest*) newResumeRequestWithRiKey:(NSString*)riKey riKeyId:(int)riKeyId;
|
||||||
- (NSURLRequest*) newQuitAppRequest;
|
- (NSURLRequest*) newQuitAppRequest;
|
||||||
- (NSURLRequest*) newAppAssetRequestWithAppId:(NSString*)appId;
|
- (NSURLRequest*) newAppAssetRequestWithAppId:(NSString*)appId;
|
||||||
- (void) executeRequestSynchronously:(HttpRequest*)request;
|
- (void) executeRequestSynchronously:(HttpRequest*)request;
|
||||||
- (void) executeRequest:(HttpRequest*)request;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,15 @@
|
|||||||
#import "HttpManager.h"
|
#import "HttpManager.h"
|
||||||
#import "HttpRequest.h"
|
#import "HttpRequest.h"
|
||||||
#import "CryptoManager.h"
|
#import "CryptoManager.h"
|
||||||
#import "App.h"
|
#import "TemporaryApp.h"
|
||||||
|
|
||||||
#include <libxml2/libxml/xmlreader.h>
|
#include <libxml2/libxml/xmlreader.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@implementation HttpManager {
|
@implementation HttpManager {
|
||||||
NSString* _baseURL;
|
NSURLSession* _urlSession;
|
||||||
|
NSString* _baseHTTPURL;
|
||||||
|
NSString* _baseHTTPSURL;
|
||||||
NSString* _host;
|
NSString* _host;
|
||||||
NSString* _uniqueId;
|
NSString* _uniqueId;
|
||||||
NSString* _deviceName;
|
NSString* _deviceName;
|
||||||
@@ -27,7 +29,8 @@
|
|||||||
BOOL _errorOccurred;
|
BOOL _errorOccurred;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const NSString* PORT = @"47984";
|
static const NSString* HTTP_PORT = @"47989";
|
||||||
|
static const NSString* HTTPS_PORT = @"47984";
|
||||||
|
|
||||||
+ (NSData*) fixXmlVersion:(NSData*) xmlData {
|
+ (NSData*) fixXmlVersion:(NSData*) xmlData {
|
||||||
NSString* dataString = [[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding];
|
NSString* dataString = [[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding];
|
||||||
@@ -42,38 +45,63 @@ static const NSString* PORT = @"47984";
|
|||||||
_uniqueId = uniqueId;
|
_uniqueId = uniqueId;
|
||||||
_deviceName = deviceName;
|
_deviceName = deviceName;
|
||||||
_cert = cert;
|
_cert = cert;
|
||||||
_baseURL = [[NSString stringWithFormat:@"https://%@:%@", host, PORT]
|
_baseHTTPURL = [NSString stringWithFormat:@"http://%@:%@", host, HTTP_PORT];
|
||||||
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
_baseHTTPSURL = [NSString stringWithFormat:@"https://%@:%@", host, HTTPS_PORT];
|
||||||
_requestLock = dispatch_semaphore_create(0);
|
_requestLock = dispatch_semaphore_create(0);
|
||||||
_respData = [[NSMutableData alloc] init];
|
_respData = [[NSMutableData alloc] init];
|
||||||
|
NSURLSessionConfiguration* config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
|
||||||
|
_urlSession = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) executeRequestSynchronously:(HttpRequest*)request {
|
- (void) executeRequestSynchronously:(HttpRequest*)request {
|
||||||
Log(LOG_D, @"Making Request: %@", request);
|
Log(LOG_D, @"Making Request: %@", request);
|
||||||
[_respData setLength:0];
|
[_respData setLength:0];
|
||||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
[[_urlSession dataTaskWithRequest:request.request completionHandler:^(NSData * __nullable data, NSURLResponse * __nullable response, NSError * __nullable error) {
|
||||||
[NSURLConnection connectionWithRequest:request.request delegate:self];
|
|
||||||
});
|
if (error != NULL) {
|
||||||
|
Log(LOG_D, @"Connection error: %@", error);
|
||||||
|
_errorOccurred = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log(LOG_D, @"Received response: %@", response);
|
||||||
|
|
||||||
|
if (data != NULL) {
|
||||||
|
Log(LOG_D, @"\n\nReceived data: %@\n\n", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
|
||||||
|
[_respData appendData:data];
|
||||||
|
if ([[NSString alloc] initWithData:_respData encoding:NSUTF8StringEncoding] != nil) {
|
||||||
|
_requestResp = [HttpManager fixXmlVersion:_respData];
|
||||||
|
} else {
|
||||||
|
_requestResp = _respData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch_semaphore_signal(_requestLock);
|
||||||
|
}] resume];
|
||||||
dispatch_semaphore_wait(_requestLock, DISPATCH_TIME_FOREVER);
|
dispatch_semaphore_wait(_requestLock, DISPATCH_TIME_FOREVER);
|
||||||
|
|
||||||
if (!_errorOccurred && request.response) {
|
if (!_errorOccurred && request.response) {
|
||||||
[request.response populateWithData:_requestResp];
|
[request.response populateWithData:_requestResp];
|
||||||
|
|
||||||
|
// If the fallback error code was detected, issue the fallback request
|
||||||
|
if (request.response.statusCode == request.fallbackError && request.fallbackRequest != NULL) {
|
||||||
|
Log(LOG_D, @"Request failed with fallback error code: %d", request.fallbackError);
|
||||||
|
request.request = request.fallbackRequest;
|
||||||
|
request.fallbackError = 0;
|
||||||
|
request.fallbackRequest = NULL;
|
||||||
|
[self executeRequestSynchronously:request];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_errorOccurred = false;
|
_errorOccurred = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) executeRequest:(HttpRequest*)request {
|
|
||||||
[NSURLConnection connectionWithRequest:request.request delegate:self];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSURLRequest*) createRequestFromString:(NSString*) urlString enableTimeout:(BOOL)normalTimeout {
|
- (NSURLRequest*) createRequestFromString:(NSString*) urlString enableTimeout:(BOOL)normalTimeout {
|
||||||
NSString* escapedUrl = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
NSURL* url = [[NSURL alloc] initWithString:urlString];
|
||||||
NSURL* url = [[NSURL alloc] initWithString:escapedUrl];
|
|
||||||
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
|
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
|
||||||
if (normalTimeout) {
|
if (normalTimeout) {
|
||||||
// Timeout the request after 5 seconds
|
// Timeout the request after 7 seconds
|
||||||
[request setTimeoutInterval:5];
|
[request setTimeoutInterval:7];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Timeout the request after 60 seconds
|
// Timeout the request after 60 seconds
|
||||||
@@ -84,67 +112,72 @@ static const NSString* PORT = @"47984";
|
|||||||
|
|
||||||
- (NSURLRequest*) newPairRequest:(NSData*)salt {
|
- (NSURLRequest*) newPairRequest:(NSData*)salt {
|
||||||
NSString* urlString = [NSString stringWithFormat:@"%@/pair?uniqueid=%@&devicename=%@&updateState=1&phrase=getservercert&salt=%@&clientcert=%@",
|
NSString* urlString = [NSString stringWithFormat:@"%@/pair?uniqueid=%@&devicename=%@&updateState=1&phrase=getservercert&salt=%@&clientcert=%@",
|
||||||
_baseURL, _uniqueId, _deviceName, [self bytesToHex:salt], [self bytesToHex:_cert]];
|
_baseHTTPSURL, _uniqueId, _deviceName, [self bytesToHex:salt], [self bytesToHex:_cert]];
|
||||||
// This call blocks while waiting for the user to input the PIN on the PC
|
// This call blocks while waiting for the user to input the PIN on the PC
|
||||||
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURLRequest*) newUnpairRequest {
|
- (NSURLRequest*) newUnpairRequest {
|
||||||
NSString* urlString = [NSString stringWithFormat:@"%@/unpair?uniqueid=%@", _baseURL, _uniqueId];
|
NSString* urlString = [NSString stringWithFormat:@"%@/unpair?uniqueid=%@", _baseHTTPSURL, _uniqueId];
|
||||||
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURLRequest*) newChallengeRequest:(NSData*)challenge {
|
- (NSURLRequest*) newChallengeRequest:(NSData*)challenge {
|
||||||
NSString* urlString = [NSString stringWithFormat:@"%@/pair?uniqueid=%@&devicename=%@&updateState=1&clientchallenge=%@",
|
NSString* urlString = [NSString stringWithFormat:@"%@/pair?uniqueid=%@&devicename=%@&updateState=1&clientchallenge=%@",
|
||||||
_baseURL, _uniqueId, _deviceName, [self bytesToHex:challenge]];
|
_baseHTTPSURL, _uniqueId, _deviceName, [self bytesToHex:challenge]];
|
||||||
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURLRequest*) newChallengeRespRequest:(NSData*)challengeResp {
|
- (NSURLRequest*) newChallengeRespRequest:(NSData*)challengeResp {
|
||||||
NSString* urlString = [NSString stringWithFormat:@"%@/pair?uniqueid=%@&devicename=%@&updateState=1&serverchallengeresp=%@",
|
NSString* urlString = [NSString stringWithFormat:@"%@/pair?uniqueid=%@&devicename=%@&updateState=1&serverchallengeresp=%@",
|
||||||
_baseURL, _uniqueId, _deviceName, [self bytesToHex:challengeResp]];
|
_baseHTTPSURL, _uniqueId, _deviceName, [self bytesToHex:challengeResp]];
|
||||||
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURLRequest*) newClientSecretRespRequest:(NSString*)clientPairSecret {
|
- (NSURLRequest*) newClientSecretRespRequest:(NSString*)clientPairSecret {
|
||||||
NSString* urlString = [NSString stringWithFormat:@"%@/pair?uniqueid=%@&devicename=%@&updateState=1&clientpairingsecret=%@", _baseURL, _uniqueId, _deviceName, clientPairSecret];
|
NSString* urlString = [NSString stringWithFormat:@"%@/pair?uniqueid=%@&devicename=%@&updateState=1&clientpairingsecret=%@", _baseHTTPSURL, _uniqueId, _deviceName, clientPairSecret];
|
||||||
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURLRequest*) newPairChallenge {
|
- (NSURLRequest*) newPairChallenge {
|
||||||
NSString* urlString = [NSString stringWithFormat:@"%@/pair?uniqueid=%@&devicename=%@&updateState=1&phrase=pairchallenge", _baseURL, _uniqueId, _deviceName];
|
NSString* urlString = [NSString stringWithFormat:@"%@/pair?uniqueid=%@&devicename=%@&updateState=1&phrase=pairchallenge", _baseHTTPSURL, _uniqueId, _deviceName];
|
||||||
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURLRequest *)newAppListRequest {
|
- (NSURLRequest *)newAppListRequest {
|
||||||
NSString* urlString = [NSString stringWithFormat:@"%@/applist?uniqueid=%@", _baseURL, _uniqueId];
|
NSString* urlString = [NSString stringWithFormat:@"%@/applist?uniqueid=%@", _baseHTTPSURL, _uniqueId];
|
||||||
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURLRequest *)newServerInfoRequest {
|
- (NSURLRequest *)newServerInfoRequest {
|
||||||
NSString* urlString = [NSString stringWithFormat:@"%@/serverinfo?uniqueid=%@", _baseURL, _uniqueId];
|
NSString* urlString = [NSString stringWithFormat:@"%@/serverinfo?uniqueid=%@", _baseHTTPSURL, _uniqueId];
|
||||||
|
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSURLRequest *)newHttpServerInfoRequest {
|
||||||
|
NSString* urlString = [NSString stringWithFormat:@"%@/serverinfo", _baseHTTPURL];
|
||||||
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
return [self createRequestFromString:urlString enableTimeout:TRUE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURLRequest*) newLaunchRequest:(NSString*)appId width:(int)width height:(int)height refreshRate:(int)refreshRate rikey:(NSString*)rikey rikeyid:(int)rikeyid {
|
- (NSURLRequest*) newLaunchRequest:(NSString*)appId width:(int)width height:(int)height refreshRate:(int)refreshRate rikey:(NSString*)rikey rikeyid:(int)rikeyid {
|
||||||
NSString* urlString = [NSString stringWithFormat:@"%@/launch?uniqueid=%@&appid=%@&mode=%dx%dx%d&additionalStates=1&sops=1&rikey=%@&rikeyid=%d", _baseURL, _uniqueId, appId, width, height, refreshRate, rikey, rikeyid];
|
NSString* urlString = [NSString stringWithFormat:@"%@/launch?uniqueid=%@&appid=%@&mode=%dx%dx%d&additionalStates=1&sops=1&rikey=%@&rikeyid=%d", _baseHTTPSURL, _uniqueId, appId, width, height, refreshRate, rikey, rikeyid];
|
||||||
// This blocks while the app is launching
|
// This blocks while the app is launching
|
||||||
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURLRequest*) newResumeRequestWithRiKey:(NSString*)riKey riKeyId:(int)riKeyId {
|
- (NSURLRequest*) newResumeRequestWithRiKey:(NSString*)riKey riKeyId:(int)riKeyId {
|
||||||
NSString* urlString = [NSString stringWithFormat:@"%@/resume?uniqueid=%@&rikey=%@&rikeyid=%d", _baseURL, _uniqueId, riKey, riKeyId];
|
NSString* urlString = [NSString stringWithFormat:@"%@/resume?uniqueid=%@&rikey=%@&rikeyid=%d", _baseHTTPSURL, _uniqueId, riKey, riKeyId];
|
||||||
// This blocks while the app is resuming
|
// This blocks while the app is resuming
|
||||||
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURLRequest*) newQuitAppRequest {
|
- (NSURLRequest*) newQuitAppRequest {
|
||||||
NSString* urlString = [NSString stringWithFormat:@"%@/cancel?uniqueid=%@", _baseURL, _uniqueId];
|
NSString* urlString = [NSString stringWithFormat:@"%@/cancel?uniqueid=%@", _baseHTTPSURL, _uniqueId];
|
||||||
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURLRequest*) newAppAssetRequestWithAppId:(NSString *)appId {
|
- (NSURLRequest*) newAppAssetRequestWithAppId:(NSString *)appId {
|
||||||
NSString* urlString = [NSString stringWithFormat:@"%@/appasset?uniqueid=%@&appid=%@&AssetType=2&AssetIdx=0", _baseURL, _uniqueId, appId];
|
NSString* urlString = [NSString stringWithFormat:@"%@/appasset?uniqueid=%@&appid=%@&AssetType=2&AssetIdx=0", _baseHTTPSURL, _uniqueId, appId];
|
||||||
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,33 +190,6 @@ static const NSString* PORT = @"47984";
|
|||||||
return hex;
|
return hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
|
|
||||||
Log(LOG_D, @"Received response: %@", response);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
|
|
||||||
Log(LOG_D, @"\n\nReceived data: %@\n\n", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
|
|
||||||
[_respData appendData:data];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
|
|
||||||
if ([[NSString alloc] initWithData:_respData encoding:NSUTF8StringEncoding] != nil) {
|
|
||||||
_requestResp = [HttpManager fixXmlVersion:_respData];
|
|
||||||
} else {
|
|
||||||
_requestResp = _respData;
|
|
||||||
}
|
|
||||||
dispatch_semaphore_signal(_requestLock);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
|
|
||||||
SecIdentityRef identity = [self getClientCertificate];
|
|
||||||
NSArray *certArray = [self getCertificate:identity];
|
|
||||||
|
|
||||||
NSURLCredential *newCredential = [NSURLCredential credentialWithIdentity:identity certificates:certArray persistence:NSURLCredentialPersistencePermanent];
|
|
||||||
|
|
||||||
[challenge.sender useCredential:newCredential forAuthenticationChallenge:challenge];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns an array containing the certificate
|
// Returns an array containing the certificate
|
||||||
- (NSArray*)getCertificate:(SecIdentityRef) identity {
|
- (NSArray*)getCertificate:(SecIdentityRef) identity {
|
||||||
SecCertificateRef certificate = nil;
|
SecCertificateRef certificate = nil;
|
||||||
@@ -219,10 +225,25 @@ static const NSString* PORT = @"47984";
|
|||||||
return identityApp;
|
return identityApp;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
|
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(nonnull void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * __nullable))completionHandler {
|
||||||
Log(LOG_D, @"connection error: %@", error);
|
// Allow untrusted server certificates
|
||||||
_errorOccurred = true;
|
if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
|
||||||
dispatch_semaphore_signal(_requestLock);
|
{
|
||||||
|
completionHandler(NSURLSessionAuthChallengeUseCredential,
|
||||||
|
[NSURLCredential credentialForTrust: challenge.protectionSpace.serverTrust]);
|
||||||
|
}
|
||||||
|
// Respond to client certificate challenge with our certificate
|
||||||
|
else if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodClientCertificate])
|
||||||
|
{
|
||||||
|
SecIdentityRef identity = [self getClientCertificate];
|
||||||
|
NSArray* certArray = [self getCertificate:identity];
|
||||||
|
NSURLCredential* newCredential = [NSURLCredential credentialWithIdentity:identity certificates:certArray persistence:NSURLCredentialPersistencePermanent];
|
||||||
|
completionHandler(NSURLSessionAuthChallengeUseCredential, newCredential);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -13,7 +13,10 @@
|
|||||||
|
|
||||||
@property (nonatomic) id<Response> response;
|
@property (nonatomic) id<Response> response;
|
||||||
@property (nonatomic) NSURLRequest* request;
|
@property (nonatomic) NSURLRequest* request;
|
||||||
|
@property (nonatomic) int fallbackError;
|
||||||
|
@property (nonatomic) NSURLRequest* fallbackRequest;
|
||||||
|
|
||||||
|
+ (instancetype) requestForResponse:(id<Response>)response withUrlRequest:(NSURLRequest*)req fallbackError:(int)error fallbackRequest:(NSURLRequest*) fallbackReq;
|
||||||
+ (instancetype) requestForResponse:(id<Response>)response withUrlRequest:(NSURLRequest*)req;
|
+ (instancetype) requestForResponse:(id<Response>)response withUrlRequest:(NSURLRequest*)req;
|
||||||
+ (instancetype) requestWithUrlRequest:(NSURLRequest*)req;
|
+ (instancetype) requestWithUrlRequest:(NSURLRequest*)req;
|
||||||
|
|
||||||
|
|||||||
@@ -25,4 +25,13 @@
|
|||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (HttpRequest*) requestForResponse:(id<Response>)response withUrlRequest:(NSURLRequest*)req fallbackError:(int)error fallbackRequest:(NSURLRequest*) fallbackReq {
|
||||||
|
HttpRequest* request = [[HttpRequest alloc] init];
|
||||||
|
request.request = req;
|
||||||
|
request.response = response;
|
||||||
|
request.fallbackError = error;
|
||||||
|
request.fallbackRequest = fallbackReq;
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -7,7 +7,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "Host.h"
|
|
||||||
|
|
||||||
static NSString* TAG_STATUS_CODE = @"status_code";
|
static NSString* TAG_STATUS_CODE = @"status_code";
|
||||||
static NSString* TAG_STATUS_MESSAGE = @"status_message";
|
static NSString* TAG_STATUS_MESSAGE = @"status_message";
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "HttpResponse.h"
|
#import "HttpResponse.h"
|
||||||
#import "App.h"
|
#import "TemporaryApp.h"
|
||||||
#import <libxml2/libxml/xmlreader.h>
|
#import <libxml2/libxml/xmlreader.h>
|
||||||
|
|
||||||
@implementation HttpResponse {
|
@implementation HttpResponse {
|
||||||
|
|||||||
@@ -7,8 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "MDNSManager.h"
|
#import "MDNSManager.h"
|
||||||
#import "Host.h"
|
#import "TemporaryHost.h"
|
||||||
#import "DataManager.h"
|
|
||||||
|
|
||||||
@implementation MDNSManager {
|
@implementation MDNSManager {
|
||||||
NSNetServiceBrowser* mDNSBrowser;
|
NSNetServiceBrowser* mDNSBrowser;
|
||||||
@@ -47,11 +46,10 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
|||||||
|
|
||||||
- (NSArray*) getFoundHosts {
|
- (NSArray*) getFoundHosts {
|
||||||
NSMutableArray* hosts = [[NSMutableArray alloc] init];
|
NSMutableArray* hosts = [[NSMutableArray alloc] init];
|
||||||
DataManager* dataMan = [[DataManager alloc] init];
|
|
||||||
for (NSNetService* service in services) {
|
for (NSNetService* service in services) {
|
||||||
if (service.hostName != nil) {
|
if (service.hostName != nil) {
|
||||||
Host* host = [dataMan createHost];
|
TemporaryHost* host = [[TemporaryHost alloc] init];
|
||||||
host.address = service.hostName;
|
host.activeAddress = host.address = service.hostName;
|
||||||
host.name = host.address;
|
host.name = host.address;
|
||||||
[hosts addObject:host];
|
[hosts addObject:host];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,13 +31,14 @@
|
|||||||
|
|
||||||
- (void) main {
|
- (void) main {
|
||||||
ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init];
|
ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init];
|
||||||
[_httpManager executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[_httpManager newServerInfoRequest]]];
|
[_httpManager executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[_httpManager newServerInfoRequest]
|
||||||
|
fallbackError:401 fallbackRequest:[_httpManager newHttpServerInfoRequest]]];
|
||||||
if (serverInfoResp == nil) {
|
if (serverInfoResp == nil) {
|
||||||
[_callback pairFailed:@"Unable to connect to PC"];
|
[_callback pairFailed:@"Unable to connect to PC"];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ([serverInfoResp isStatusOk]) {
|
if ([serverInfoResp isStatusOk]) {
|
||||||
if (![[serverInfoResp getStringTag:@"currentgame"] isEqual:@"0"]) {
|
if (![[serverInfoResp getStringTag:@"state"] hasSuffix:@"_SERVER_AVAILABLE"]) {
|
||||||
[_callback pairFailed:@"You must stop streaming before attempting to pair."];
|
[_callback pairFailed:@"You must stop streaming before attempting to pair."];
|
||||||
} else if (![[serverInfoResp getStringTag:@"PairStatus"] isEqual:@"1"]) {
|
} else if (![[serverInfoResp getStringTag:@"PairStatus"] isEqual:@"1"]) {
|
||||||
[self initiatePair];
|
[self initiatePair];
|
||||||
@@ -60,7 +61,7 @@
|
|||||||
}
|
}
|
||||||
NSInteger pairedStatus;
|
NSInteger pairedStatus;
|
||||||
if (![pairResp getIntTag:@"paired" value:&pairedStatus] || !pairedStatus) {
|
if (![pairResp getIntTag:@"paired" value:&pairedStatus] || !pairedStatus) {
|
||||||
[_httpManager executeRequest:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
[_httpManager executeRequestSynchronously:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
||||||
[_callback pairFailed:@"Pairing was declined by the target."];
|
[_callback pairFailed:@"Pairing was declined by the target."];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -78,8 +79,8 @@
|
|||||||
if (![self verifyResponseStatus:challengeResp]) {
|
if (![self verifyResponseStatus:challengeResp]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (![challengeResp getIntTag:@"paired" value:&pairedStatus] || !pairedStatus) {
|
if (![challengeResp getIntTag:@"paired" value:&pairedStatus] || pairedStatus != 1) {
|
||||||
[_httpManager executeRequest:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
[_httpManager executeRequestSynchronously:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
||||||
[_callback pairFailed:@"Pairing stage #2 failed"];
|
[_callback pairFailed:@"Pairing stage #2 failed"];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -99,8 +100,8 @@
|
|||||||
if (![self verifyResponseStatus:secretResp]) {
|
if (![self verifyResponseStatus:secretResp]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (![secretResp getIntTag:@"paired" value:&pairedStatus] || !pairedStatus) {
|
if (![secretResp getIntTag:@"paired" value:&pairedStatus] || pairedStatus != 1) {
|
||||||
[_httpManager executeRequest:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
[_httpManager executeRequestSynchronously:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
||||||
[_callback pairFailed:@"Pairing stage #3 failed"];
|
[_callback pairFailed:@"Pairing stage #3 failed"];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -110,14 +111,14 @@
|
|||||||
NSData* serverSignature = [serverSecretResp subdataWithRange:NSMakeRange(16, 256)];
|
NSData* serverSignature = [serverSecretResp subdataWithRange:NSMakeRange(16, 256)];
|
||||||
|
|
||||||
if (![cryptoMan verifySignature:serverSecret withSignature:serverSignature andCert:[Utils hexToBytes:plainCert]]) {
|
if (![cryptoMan verifySignature:serverSecret withSignature:serverSignature andCert:[Utils hexToBytes:plainCert]]) {
|
||||||
[_httpManager executeRequest:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
[_httpManager executeRequestSynchronously:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
||||||
[_callback pairFailed:@"Server certificate invalid"];
|
[_callback pairFailed:@"Server certificate invalid"];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSData* serverChallengeRespHash = [cryptoMan SHA1HashData:[self concatData:[self concatData:randomChallenge with:[CryptoManager getSignatureFromCert:[Utils hexToBytes:plainCert]]] with:serverSecret]];
|
NSData* serverChallengeRespHash = [cryptoMan SHA1HashData:[self concatData:[self concatData:randomChallenge with:[CryptoManager getSignatureFromCert:[Utils hexToBytes:plainCert]]] with:serverSecret]];
|
||||||
if (![serverChallengeRespHash isEqual:serverResponse]) {
|
if (![serverChallengeRespHash isEqual:serverResponse]) {
|
||||||
[_httpManager executeRequest:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
[_httpManager executeRequestSynchronously:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
||||||
[_callback pairFailed:@"Incorrect PIN"];
|
[_callback pairFailed:@"Incorrect PIN"];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -128,8 +129,8 @@
|
|||||||
if (![self verifyResponseStatus:clientSecretResp]) {
|
if (![self verifyResponseStatus:clientSecretResp]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (![clientSecretResp getIntTag:@"paired" value:&pairedStatus] || !pairedStatus) {
|
if (![clientSecretResp getIntTag:@"paired" value:&pairedStatus] || pairedStatus != 1) {
|
||||||
[_httpManager executeRequest:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
[_httpManager executeRequestSynchronously:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
||||||
[_callback pairFailed:@"Pairing stage #4 failed"];
|
[_callback pairFailed:@"Pairing stage #4 failed"];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -139,8 +140,8 @@
|
|||||||
if (![self verifyResponseStatus:clientPairChallengeResp]) {
|
if (![self verifyResponseStatus:clientPairChallengeResp]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (![clientPairChallengeResp getIntTag:@"paired" value:&pairedStatus] || !pairedStatus) {
|
if (![clientPairChallengeResp getIntTag:@"paired" value:&pairedStatus] || pairedStatus != 1) {
|
||||||
[_httpManager executeRequest:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
[_httpManager executeRequestSynchronously:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
||||||
[_callback pairFailed:@"Pairing stage #5 failed"];
|
[_callback pairFailed:@"Pairing stage #5 failed"];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -149,11 +150,11 @@
|
|||||||
|
|
||||||
- (BOOL) verifyResponseStatus:(HttpResponse*)resp {
|
- (BOOL) verifyResponseStatus:(HttpResponse*)resp {
|
||||||
if (resp == nil) {
|
if (resp == nil) {
|
||||||
[_httpManager executeRequest:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
[_httpManager executeRequestSynchronously:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
||||||
[_callback pairFailed:@"Network error occured."];
|
[_callback pairFailed:@"Network error occured."];
|
||||||
return false;
|
return false;
|
||||||
} else if (![resp isStatusOk]) {
|
} else if (![resp isStatusOk]) {
|
||||||
[_httpManager executeRequest:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
[_httpManager executeRequestSynchronously:[HttpRequest requestWithUrlRequest:[_httpManager newUnpairRequest]]];
|
||||||
[_callback pairFailed:resp.statusMessage];
|
[_callback pairFailed:resp.statusMessage];
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "HttpResponse.h"
|
#import "HttpResponse.h"
|
||||||
|
#import "TemporaryHost.h"
|
||||||
|
|
||||||
#define TAG_HOSTNAME @"hostname"
|
#define TAG_HOSTNAME @"hostname"
|
||||||
#define TAG_EXTERNAL_IP @"ExternalIP"
|
#define TAG_EXTERNAL_IP @"ExternalIP"
|
||||||
@@ -18,7 +19,7 @@
|
|||||||
@interface ServerInfoResponse : HttpResponse <Response>
|
@interface ServerInfoResponse : HttpResponse <Response>
|
||||||
|
|
||||||
- (void) populateWithData:(NSData *)data;
|
- (void) populateWithData:(NSData *)data;
|
||||||
- (void) populateHost:(Host*)host;
|
- (void) populateHost:(TemporaryHost*)host;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
[super parseData];
|
[super parseData];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) populateHost:(Host*)host {
|
- (void) populateHost:(TemporaryHost*)host {
|
||||||
host.name = [[self getStringTag:TAG_HOSTNAME] trim];
|
host.name = [[self getStringTag:TAG_HOSTNAME] trim];
|
||||||
host.externalAddress = [[self getStringTag:TAG_EXTERNAL_IP] trim];
|
host.externalAddress = [[self getStringTag:TAG_EXTERNAL_IP] trim];
|
||||||
host.localAddress = [[self getStringTag:TAG_LOCAL_IP] trim];
|
host.localAddress = [[self getStringTag:TAG_LOCAL_IP] trim];
|
||||||
|
|||||||
@@ -7,10 +7,10 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "Host.h"
|
#import "TemporaryHost.h"
|
||||||
|
|
||||||
@interface WakeOnLanManager : NSObject
|
@interface WakeOnLanManager : NSObject
|
||||||
|
|
||||||
+ (void) wakeHost:(Host*)host;
|
+ (void) wakeHost:(TemporaryHost*)host;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
static const int numPorts = 5;
|
static const int numPorts = 5;
|
||||||
static const int ports[numPorts] = {7, 9, 47998, 47999, 48000};
|
static const int ports[numPorts] = {7, 9, 47998, 47999, 48000};
|
||||||
|
|
||||||
+ (void) wakeHost:(Host*)host {
|
+ (void) wakeHost:(TemporaryHost*)host {
|
||||||
NSData* wolPayload = [WakeOnLanManager createPayload:host];
|
NSData* wolPayload = [WakeOnLanManager createPayload:host];
|
||||||
CFDataRef dataPayload = CFDataCreate(kCFAllocatorDefault, [wolPayload bytes], [wolPayload length]);
|
CFDataRef dataPayload = CFDataCreate(kCFAllocatorDefault, [wolPayload bytes], [wolPayload length]);
|
||||||
CFSocketRef wolSocket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_DGRAM, IPPROTO_UDP, 0, NULL, NULL);
|
CFSocketRef wolSocket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_DGRAM, IPPROTO_UDP, 0, NULL, NULL);
|
||||||
@@ -56,7 +56,7 @@ static const int ports[numPorts] = {7, 9, 47998, 47999, 48000};
|
|||||||
CFRelease(dataPayload);
|
CFRelease(dataPayload);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSData*) createPayload:(Host*)host {
|
+ (NSData*) createPayload:(TemporaryHost*)host {
|
||||||
NSMutableData* payload = [[NSMutableData alloc] initWithCapacity:102];
|
NSMutableData* payload = [[NSMutableData alloc] initWithCapacity:102];
|
||||||
|
|
||||||
// 6 bytes of FF
|
// 6 bytes of FF
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
#include "opus.h"
|
#include "opus.h"
|
||||||
|
|
||||||
@implementation Connection {
|
@implementation Connection {
|
||||||
IP_ADDRESS _host;
|
const char* _host;
|
||||||
STREAM_CONFIGURATION _streamConfig;
|
STREAM_CONFIGURATION _streamConfig;
|
||||||
CONNECTION_LISTENER_CALLBACKS _clCallbacks;
|
CONNECTION_LISTENER_CALLBACKS _clCallbacks;
|
||||||
DECODER_RENDERER_CALLBACKS _drCallbacks;
|
DECODER_RENDERER_CALLBACKS _drCallbacks;
|
||||||
@@ -65,11 +65,16 @@ int DrSubmitDecodeUnit(PDECODE_UNIT decodeUnit)
|
|||||||
return [renderer submitDecodeBuffer:data length:decodeUnit->fullLength];
|
return [renderer submitDecodeBuffer:data length:decodeUnit->fullLength];
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArInit(void)
|
void ArInit(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
opusDecoder = opus_decoder_create(48000, 2, &err);
|
// We only support stereo for now
|
||||||
|
assert(audioConfiguration == AUDIO_CONFIGURATION_STEREO);
|
||||||
|
|
||||||
|
opusDecoder = opus_decoder_create(opusConfig->sampleRate,
|
||||||
|
opusConfig->channelCount,
|
||||||
|
&err);
|
||||||
|
|
||||||
audioLock = [[NSLock alloc] init];
|
audioLock = [[NSLock alloc] init];
|
||||||
|
|
||||||
@@ -77,9 +82,9 @@ void ArInit(void)
|
|||||||
NSError *audioSessionError = nil;
|
NSError *audioSessionError = nil;
|
||||||
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
|
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
|
||||||
|
|
||||||
[audioSession setPreferredSampleRate:48000.0 error:&audioSessionError];
|
[audioSession setPreferredSampleRate:opusConfig->sampleRate error:&audioSessionError];
|
||||||
[audioSession setCategory: AVAudioSessionCategoryPlayback error: &audioSessionError];
|
[audioSession setCategory: AVAudioSessionCategoryPlayback error: &audioSessionError];
|
||||||
[audioSession setPreferredOutputNumberOfChannels:2 error:&audioSessionError];
|
[audioSession setPreferredOutputNumberOfChannels:opusConfig->channelCount error:&audioSessionError];
|
||||||
[audioSession setPreferredIOBufferDuration:0.005 error:&audioSessionError];
|
[audioSession setPreferredIOBufferDuration:0.005 error:&audioSessionError];
|
||||||
[audioSession setActive: YES error: &audioSessionError];
|
[audioSession setActive: YES error: &audioSessionError];
|
||||||
|
|
||||||
@@ -99,11 +104,11 @@ void ArInit(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AudioStreamBasicDescription audioFormat = {0};
|
AudioStreamBasicDescription audioFormat = {0};
|
||||||
audioFormat.mSampleRate = 48000;
|
audioFormat.mSampleRate = opusConfig->sampleRate;
|
||||||
audioFormat.mBitsPerChannel = 16;
|
audioFormat.mBitsPerChannel = 16;
|
||||||
audioFormat.mFormatID = kAudioFormatLinearPCM;
|
audioFormat.mFormatID = kAudioFormatLinearPCM;
|
||||||
audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
|
audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
|
||||||
audioFormat.mChannelsPerFrame = 2;
|
audioFormat.mChannelsPerFrame = opusConfig->channelCount;
|
||||||
audioFormat.mBytesPerFrame = audioFormat.mChannelsPerFrame * (audioFormat.mBitsPerChannel / 8);
|
audioFormat.mBytesPerFrame = audioFormat.mChannelsPerFrame * (audioFormat.mBitsPerChannel / 8);
|
||||||
audioFormat.mBytesPerPacket = audioFormat.mBytesPerFrame;
|
audioFormat.mBytesPerPacket = audioFormat.mBytesPerFrame;
|
||||||
audioFormat.mFramesPerPacket = audioFormat.mBytesPerPacket / audioFormat.mBytesPerFrame;
|
audioFormat.mFramesPerPacket = audioFormat.mBytesPerPacket / audioFormat.mBytesPerFrame;
|
||||||
@@ -137,16 +142,26 @@ void ArInit(void)
|
|||||||
if (status) {
|
if (status) {
|
||||||
Log(LOG_E, @"Unable to initialize audioUnit: %d", (int32_t)status);
|
Log(LOG_E, @"Unable to initialize audioUnit: %d", (int32_t)status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status = AudioOutputUnitStart(audioUnit);
|
||||||
|
if (status) {
|
||||||
|
Log(LOG_E, @"Unable to start audioUnit: %d", (int32_t)status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArRelease(void)
|
void ArCleanup(void)
|
||||||
{
|
{
|
||||||
if (opusDecoder != NULL) {
|
if (opusDecoder != NULL) {
|
||||||
opus_decoder_destroy(opusDecoder);
|
opus_decoder_destroy(opusDecoder);
|
||||||
opusDecoder = NULL;
|
opusDecoder = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
OSStatus status = AudioUnitUninitialize(audioUnit);
|
OSStatus status = AudioOutputUnitStop(audioUnit);
|
||||||
|
if (status) {
|
||||||
|
Log(LOG_E, @"Unable to stop audioUnit: %d", (int32_t)status);
|
||||||
|
}
|
||||||
|
|
||||||
|
status = AudioUnitUninitialize(audioUnit);
|
||||||
if (status) {
|
if (status) {
|
||||||
Log(LOG_E, @"Unable to uninitialize audioUnit: %d", (int32_t)status);
|
Log(LOG_E, @"Unable to uninitialize audioUnit: %d", (int32_t)status);
|
||||||
}
|
}
|
||||||
@@ -166,22 +181,6 @@ void ArRelease(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArStart(void)
|
|
||||||
{
|
|
||||||
OSStatus status = AudioOutputUnitStart(audioUnit);
|
|
||||||
if (status) {
|
|
||||||
Log(LOG_E, @"Unable to start audioUnit: %d", (int32_t)status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ArStop(void)
|
|
||||||
{
|
|
||||||
OSStatus status = AudioOutputUnitStop(audioUnit);
|
|
||||||
if (status) {
|
|
||||||
Log(LOG_E, @"Unable to stop audioUnit: %d", (int32_t)status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ArDecodeAndPlaySample(char* sampleData, int sampleLength)
|
void ArDecodeAndPlaySample(char* sampleData, int sampleLength)
|
||||||
{
|
{
|
||||||
int decodedLength = opus_decode(opusDecoder, (unsigned char*)sampleData, sampleLength, decodedPcmBuffer, PCM_BUFFER_SIZE / 2, 0);
|
int decodedLength = opus_decode(opusDecoder, (unsigned char*)sampleData, sampleLength, decodedPcmBuffer, PCM_BUFFER_SIZE / 2, 0);
|
||||||
@@ -282,10 +281,12 @@ void ClDisplayTransientMessage(char* message)
|
|||||||
-(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer connectionCallbacks:(id<ConnectionCallbacks>)callbacks serverMajorVersion:(int)serverMajorVersion
|
-(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer connectionCallbacks:(id<ConnectionCallbacks>)callbacks serverMajorVersion:(int)serverMajorVersion
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
_host = config.hostAddr;
|
_host = [config.host cStringUsingEncoding:NSUTF8StringEncoding];
|
||||||
renderer = myRenderer;
|
renderer = myRenderer;
|
||||||
_callbacks = callbacks;
|
_callbacks = callbacks;
|
||||||
_serverMajorVersion = serverMajorVersion;
|
_serverMajorVersion = serverMajorVersion;
|
||||||
|
|
||||||
|
LiInitializeStreamConfiguration(&_streamConfig);
|
||||||
_streamConfig.width = config.width;
|
_streamConfig.width = config.width;
|
||||||
_streamConfig.height = config.height;
|
_streamConfig.height = config.height;
|
||||||
_streamConfig.fps = config.frameRate;
|
_streamConfig.fps = config.frameRate;
|
||||||
@@ -299,18 +300,15 @@ void ClDisplayTransientMessage(char* message)
|
|||||||
int riKeyId = htonl(config.riKeyId);
|
int riKeyId = htonl(config.riKeyId);
|
||||||
memcpy(_streamConfig.remoteInputAesIv, &riKeyId, sizeof(riKeyId));
|
memcpy(_streamConfig.remoteInputAesIv, &riKeyId, sizeof(riKeyId));
|
||||||
|
|
||||||
_drCallbacks.setup = NULL;
|
LiInitializeVideoCallbacks(&_drCallbacks);
|
||||||
_drCallbacks.start = NULL;
|
|
||||||
_drCallbacks.stop = NULL;
|
|
||||||
_drCallbacks.release = NULL;
|
|
||||||
_drCallbacks.submitDecodeUnit = DrSubmitDecodeUnit;
|
_drCallbacks.submitDecodeUnit = DrSubmitDecodeUnit;
|
||||||
|
|
||||||
|
LiInitializeAudioCallbacks(&_arCallbacks);
|
||||||
_arCallbacks.init = ArInit;
|
_arCallbacks.init = ArInit;
|
||||||
_arCallbacks.start = ArStart;
|
_arCallbacks.cleanup = ArCleanup;
|
||||||
_arCallbacks.stop = ArStop;
|
|
||||||
_arCallbacks.release = ArRelease;
|
|
||||||
_arCallbacks.decodeAndPlaySample = ArDecodeAndPlaySample;
|
_arCallbacks.decodeAndPlaySample = ArDecodeAndPlaySample;
|
||||||
|
|
||||||
|
LiInitializeConnectionCallbacks(&_clCallbacks);
|
||||||
_clCallbacks.stageStarting = ClStageStarting;
|
_clCallbacks.stageStarting = ClStageStarting;
|
||||||
_clCallbacks.stageComplete = ClStageComplete;
|
_clCallbacks.stageComplete = ClStageComplete;
|
||||||
_clCallbacks.stageFailed = ClStageFailed;
|
_clCallbacks.stageFailed = ClStageFailed;
|
||||||
@@ -410,7 +408,6 @@ static OSStatus playbackCallback(void *inRefCon,
|
|||||||
&_clCallbacks,
|
&_clCallbacks,
|
||||||
&_drCallbacks,
|
&_drCallbacks,
|
||||||
&_arCallbacks,
|
&_arCallbacks,
|
||||||
NULL,
|
|
||||||
NULL, 0, _serverMajorVersion);
|
NULL, 0, _serverMajorVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
@property NSString* host;
|
@property NSString* host;
|
||||||
@property NSString* appID;
|
@property NSString* appID;
|
||||||
@property int hostAddr;
|
|
||||||
@property int width;
|
@property int width;
|
||||||
@property int height;
|
@property int height;
|
||||||
@property int frameRate;
|
@property int frameRate;
|
||||||
|
|||||||
@@ -9,5 +9,5 @@
|
|||||||
#import "StreamConfiguration.h"
|
#import "StreamConfiguration.h"
|
||||||
|
|
||||||
@implementation StreamConfiguration
|
@implementation StreamConfiguration
|
||||||
@synthesize host, appID, hostAddr, width, height, frameRate, bitRate, riKeyId, riKey;
|
@synthesize host, appID, width, height, frameRate, bitRate, riKeyId, riKey;
|
||||||
@end
|
@end
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
#import "ServerInfoResponse.h"
|
#import "ServerInfoResponse.h"
|
||||||
#import "HttpResponse.h"
|
#import "HttpResponse.h"
|
||||||
#import "HttpRequest.h"
|
#import "HttpRequest.h"
|
||||||
|
#import "IdManager.h"
|
||||||
|
|
||||||
@implementation StreamManager {
|
@implementation StreamManager {
|
||||||
StreamConfiguration* _config;
|
StreamConfiguration* _config;
|
||||||
@@ -36,7 +37,7 @@
|
|||||||
|
|
||||||
- (void)main {
|
- (void)main {
|
||||||
[CryptoManager generateKeyPairUsingSSl];
|
[CryptoManager generateKeyPairUsingSSl];
|
||||||
NSString* uniqueId = [CryptoManager getUniqueID];
|
NSString* uniqueId = [IdManager getUniqueId];
|
||||||
NSData* cert = [CryptoManager readCertFromFile];
|
NSData* cert = [CryptoManager readCertFromFile];
|
||||||
|
|
||||||
HttpManager* hMan = [[HttpManager alloc] initWithHost:_config.host
|
HttpManager* hMan = [[HttpManager alloc] initWithHost:_config.host
|
||||||
@@ -45,12 +46,12 @@
|
|||||||
cert:cert];
|
cert:cert];
|
||||||
|
|
||||||
ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init];
|
ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init];
|
||||||
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[hMan newServerInfoRequest]]];
|
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[hMan newServerInfoRequest]
|
||||||
NSString* currentGame = [serverInfoResp getStringTag:@"currentgame"];
|
fallbackError:401 fallbackRequest:[hMan newHttpServerInfoRequest]]];
|
||||||
NSString* pairStatus = [serverInfoResp getStringTag:@"PairStatus"];
|
NSString* pairStatus = [serverInfoResp getStringTag:@"PairStatus"];
|
||||||
NSString* currentClient = [serverInfoResp getStringTag:@"CurrentClient"];
|
|
||||||
NSString* appversion = [serverInfoResp getStringTag:@"appversion"];
|
NSString* appversion = [serverInfoResp getStringTag:@"appversion"];
|
||||||
if (![serverInfoResp isStatusOk] || currentGame == NULL || pairStatus == NULL || appversion == NULL) {
|
NSString* serverState = [serverInfoResp getStringTag:@"state"];
|
||||||
|
if (![serverInfoResp isStatusOk] || pairStatus == NULL || appversion == NULL || serverState == NULL) {
|
||||||
[_callbacks launchFailed:@"Failed to connect to PC"];
|
[_callbacks launchFailed:@"Failed to connect to PC"];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -62,12 +63,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// resumeApp and launchApp handle calling launchFailed
|
// resumeApp and launchApp handle calling launchFailed
|
||||||
if (![currentGame isEqualToString:@"0"]) {
|
if ([serverState hasSuffix:@"_SERVER_BUSY"]) {
|
||||||
if (![currentClient isEqualToString:@"1"]) {
|
|
||||||
// The server is streaming to someone else
|
|
||||||
[_callbacks launchFailed:@"There is another stream in progress"];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// App already running, resume it
|
// App already running, resume it
|
||||||
if (![self resumeApp:hMan]) {
|
if (![self resumeApp:hMan]) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -7,17 +7,17 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#import "App.h"
|
#import "TemporaryApp.h"
|
||||||
|
|
||||||
@protocol AppCallback <NSObject>
|
@protocol AppCallback <NSObject>
|
||||||
|
|
||||||
- (void) appClicked:(App*) app;
|
- (void) appClicked:(TemporaryApp*) app;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface UIAppView : UIView
|
@interface UIAppView : UIView
|
||||||
|
|
||||||
- (id) initWithApp:(App*)app andCallback:(id<AppCallback>)callback;
|
- (id) initWithApp:(TemporaryApp*)app cache:(NSCache*)cache andCallback:(id<AppCallback>)callback;
|
||||||
- (void) updateAppImage;
|
- (void) updateAppImage;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -9,38 +9,45 @@
|
|||||||
#import "UIAppView.h"
|
#import "UIAppView.h"
|
||||||
|
|
||||||
@implementation UIAppView {
|
@implementation UIAppView {
|
||||||
App* _app;
|
TemporaryApp* _app;
|
||||||
UIButton* _appButton;
|
UIButton* _appButton;
|
||||||
UILabel* _appLabel;
|
UILabel* _appLabel;
|
||||||
|
UIImageView* _appOverlay;
|
||||||
|
NSCache* _artCache;
|
||||||
id<AppCallback> _callback;
|
id<AppCallback> _callback;
|
||||||
}
|
}
|
||||||
static int LABEL_DY = 20;
|
|
||||||
|
|
||||||
- (id) initWithApp:(App*)app andCallback:(id<AppCallback>)callback {
|
static UIImage* noImage;
|
||||||
|
|
||||||
|
- (id) initWithApp:(TemporaryApp*)app cache:(NSCache*)cache andCallback:(id<AppCallback>)callback {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
_app = app;
|
_app = app;
|
||||||
_callback = callback;
|
_callback = callback;
|
||||||
|
_artCache = cache;
|
||||||
|
|
||||||
|
// Cache the NoAppImage ourselves to avoid
|
||||||
|
// having to load it each time
|
||||||
|
if (noImage == nil) {
|
||||||
|
noImage = [UIImage imageNamed:@"NoAppImage"];
|
||||||
|
}
|
||||||
|
|
||||||
_appButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
_appButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||||
UIImage* noImage = [UIImage imageNamed:@"NoAppImage"];
|
|
||||||
[_appButton setBackgroundImage:noImage forState:UIControlStateNormal];
|
[_appButton setBackgroundImage:noImage forState:UIControlStateNormal];
|
||||||
[_appButton setContentEdgeInsets:UIEdgeInsetsMake(0, 4, 0, 4)];
|
[_appButton setContentEdgeInsets:UIEdgeInsetsMake(0, 4, 0, 4)];
|
||||||
[_appButton sizeToFit];
|
[_appButton sizeToFit];
|
||||||
[_appButton addTarget:self action:@selector(appClicked) forControlEvents:UIControlEventTouchUpInside];
|
[_appButton addTarget:self action:@selector(appClicked) forControlEvents:UIControlEventTouchUpInside];
|
||||||
|
|
||||||
[self addSubview:_appButton];
|
[self addSubview:_appButton];
|
||||||
[self sizeToFit];
|
[self sizeToFit];
|
||||||
|
|
||||||
_appButton.frame = CGRectMake(0, 0, noImage.size.width, noImage.size.height);
|
_appButton.frame = CGRectMake(0, 0, noImage.size.width, noImage.size.height);
|
||||||
self.frame = CGRectMake(0, 0, noImage.size.width, noImage.size.height);
|
self.frame = CGRectMake(0, 0, noImage.size.width, noImage.size.height);
|
||||||
|
|
||||||
return self;
|
// Rasterizing the cell layer increases rendering performance by quite a bit
|
||||||
}
|
self.layer.shouldRasterize = YES;
|
||||||
|
self.layer.rasterizationScale = [UIScreen mainScreen].scale;
|
||||||
|
|
||||||
- (void) updateBounds {
|
return self;
|
||||||
float x = _appButton.frame.origin.x < _appLabel.frame.origin.x ? _appButton.frame.origin.x : _appLabel.frame.origin.x;
|
|
||||||
float y = _appButton.frame.origin.y < _appLabel.frame.origin.y ? _appButton.frame.origin.y : _appLabel.frame.origin.y;
|
|
||||||
self.bounds = CGRectMake(x , y, _appButton.frame.size.width > _appLabel.frame.size.width ? _appButton.frame.size.width : _appLabel.frame.size.width, _appButton.frame.size.height + _appLabel.frame.size.height + LABEL_DY / 2);
|
|
||||||
self.frame = CGRectMake(x , y, _appButton.frame.size.width > _appLabel.frame.size.width ? _appButton.frame.size.width : _appLabel.frame.size.width, _appButton.frame.size.height + _appLabel.frame.size.height + LABEL_DY / 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) appClicked {
|
- (void) appClicked {
|
||||||
@@ -48,15 +55,54 @@ static int LABEL_DY = 20;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void) updateAppImage {
|
- (void) updateAppImage {
|
||||||
if (_app.appImage != nil) {
|
if (_appOverlay != nil) {
|
||||||
_appButton.frame = CGRectMake(0, 0, _app.appImage.size.width / 2, _app.appImage.size.height / 2);
|
[_appOverlay removeFromSuperview];
|
||||||
self.frame = CGRectMake(0, 0, _app.appImage.size.width / 2, _app.appImage.size.height / 2);
|
_appOverlay = nil;
|
||||||
[_appButton setBackgroundImage:_app.appImage forState:UIControlStateNormal];
|
}
|
||||||
[self setNeedsDisplay];
|
|
||||||
|
if (_app.isRunning) {
|
||||||
|
// Only create the app overlay if needed
|
||||||
|
_appOverlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Play"]];
|
||||||
|
_appOverlay.layer.shadowColor = [UIColor blackColor].CGColor;
|
||||||
|
_appOverlay.layer.shadowOffset = CGSizeMake(0, 0);
|
||||||
|
_appOverlay.layer.shadowOpacity = 1;
|
||||||
|
_appOverlay.layer.shadowRadius = 2.0;
|
||||||
|
|
||||||
|
[self addSubview:_appOverlay];
|
||||||
|
|
||||||
|
_appOverlay.frame = CGRectMake(0, 0, noImage.size.width / 2.f, noImage.size.height / 4.f);
|
||||||
|
[_appOverlay setCenter:CGPointMake(self.frame.size.width/2, self.frame.size.height/6)];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Improve no-app image detection
|
// TODO: Improve no-app image detection
|
||||||
if (_app.appImage == nil || (_app.appImage.size.width == 130.f && _app.appImage.size.height == 180.f)) { // This size of image might be blank image received from GameStream.
|
BOOL noAppImage = false;
|
||||||
|
|
||||||
|
if (_app.image != nil) {
|
||||||
|
// Load the decoded image from the cache
|
||||||
|
UIImage* appImage = [_artCache objectForKey:_app];
|
||||||
|
if (appImage == nil) {
|
||||||
|
// Not cached; we have to decode this now
|
||||||
|
appImage = [UIImage imageWithData:_app.image];
|
||||||
|
[_artCache setObject:appImage forKey:_app];
|
||||||
|
}
|
||||||
|
|
||||||
|
// This size of image might be blank image received from GameStream.
|
||||||
|
if (!(appImage.size.width == 130.f && appImage.size.height == 180.f)) {
|
||||||
|
_appButton.frame = CGRectMake(0, 0, appImage.size.width / 2, appImage.size.height / 2);
|
||||||
|
self.frame = CGRectMake(0, 0, appImage.size.width / 2, appImage.size.height / 2);
|
||||||
|
_appOverlay.frame = CGRectMake(0, 0, self.frame.size.width / 2.f, self.frame.size.height / 4.f);
|
||||||
|
_appOverlay.layer.shadowRadius = 4.0;
|
||||||
|
[_appOverlay setCenter:CGPointMake(self.frame.size.width/2, self.frame.size.height/6)];
|
||||||
|
[_appButton setBackgroundImage:appImage forState:UIControlStateNormal];
|
||||||
|
[self setNeedsDisplay];
|
||||||
|
} else {
|
||||||
|
noAppImage = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
noAppImage = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (noAppImage) {
|
||||||
_appLabel = [[UILabel alloc] init];
|
_appLabel = [[UILabel alloc] init];
|
||||||
CGFloat padding = 4.f;
|
CGFloat padding = 4.f;
|
||||||
[_appLabel setFrame: CGRectMake(padding, padding, _appButton.frame.size.width - 2 * padding, _appButton.frame.size.height - 2 * padding)];
|
[_appLabel setFrame: CGRectMake(padding, padding, _appButton.frame.size.width - 2 * padding, _appButton.frame.size.height - 2 * padding)];
|
||||||
@@ -66,18 +112,10 @@ static int LABEL_DY = 20;
|
|||||||
[_appLabel setTextAlignment:NSTextAlignmentCenter];
|
[_appLabel setTextAlignment:NSTextAlignmentCenter];
|
||||||
[_appLabel setLineBreakMode:NSLineBreakByWordWrapping];
|
[_appLabel setLineBreakMode:NSLineBreakByWordWrapping];
|
||||||
[_appLabel setNumberOfLines:0];
|
[_appLabel setNumberOfLines:0];
|
||||||
[_appLabel setText:_app.appName];
|
[_appLabel setText:_app.name];
|
||||||
[_appButton addSubview:_appLabel];
|
[_appButton addSubview:_appLabel];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// Only override drawRect: if you perform custom drawing.
|
|
||||||
// An empty implementation adversely affects performance during animation.
|
|
||||||
- (void)drawRect:(CGRect)rect {
|
|
||||||
// Drawing code
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -7,19 +7,19 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#import "Host.h"
|
#import "TemporaryHost.h"
|
||||||
|
|
||||||
@protocol HostCallback <NSObject>
|
@protocol HostCallback <NSObject>
|
||||||
|
|
||||||
- (void) hostClicked:(Host*)host;
|
- (void) hostClicked:(TemporaryHost*)host view:(UIView*)view;
|
||||||
- (void) hostLongClicked:(Host*)host view:(UIView*)view;
|
- (void) hostLongClicked:(TemporaryHost*)host view:(UIView*)view;
|
||||||
- (void) addHostClicked;
|
- (void) addHostClicked;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface UIComputerView : UIView
|
@interface UIComputerView : UIView
|
||||||
|
|
||||||
- (id) initWithComputer:(Host*)host andCallback:(id<HostCallback>)callback;
|
- (id) initWithComputer:(TemporaryHost*)host andCallback:(id<HostCallback>)callback;
|
||||||
- (id) initForAddWithCallback:(id<HostCallback>)callback;
|
- (id) initForAddWithCallback:(id<HostCallback>)callback;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
#import "UIComputerView.h"
|
#import "UIComputerView.h"
|
||||||
|
|
||||||
@implementation UIComputerView {
|
@implementation UIComputerView {
|
||||||
Host* _host;
|
TemporaryHost* _host;
|
||||||
UIButton* _hostButton;
|
UIButton* _hostButton;
|
||||||
UILabel* _hostLabel;
|
UILabel* _hostLabel;
|
||||||
UILabel* _hostStatus;
|
UILabel* _hostStatus;
|
||||||
@@ -72,7 +72,7 @@ static const int LABEL_DY = 20;
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithComputer:(Host*)host andCallback:(id<HostCallback>)callback {
|
- (id) initWithComputer:(TemporaryHost*)host andCallback:(id<HostCallback>)callback {
|
||||||
self = [self init];
|
self = [self init];
|
||||||
_host = host;
|
_host = host;
|
||||||
_callback = callback;
|
_callback = callback;
|
||||||
@@ -123,7 +123,7 @@ static const int LABEL_DY = 20;
|
|||||||
self.frame = CGRectMake(x, y, width, height);
|
self.frame = CGRectMake(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) updateContentsForHost:(Host*)host {
|
- (void) updateContentsForHost:(TemporaryHost*)host {
|
||||||
_hostLabel.text = _host.name;
|
_hostLabel.text = _host.name;
|
||||||
_hostLabel.textColor = [UIColor whiteColor];
|
_hostLabel.textColor = [UIColor whiteColor];
|
||||||
[_hostLabel sizeToFit];
|
[_hostLabel sizeToFit];
|
||||||
@@ -171,7 +171,7 @@ static const int LABEL_DY = 20;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void) hostClicked {
|
- (void) hostClicked {
|
||||||
[_callback hostClicked:_host];
|
[_callback hostClicked:_host view:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) addClicked {
|
- (void) addClicked {
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
// Copyright (c) 2014 Moonlight Stream. All rights reserved.
|
// Copyright (c) 2014 Moonlight Stream. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
@import ImageIO;
|
||||||
|
|
||||||
#import "MainFrameViewController.h"
|
#import "MainFrameViewController.h"
|
||||||
#import "CryptoManager.h"
|
#import "CryptoManager.h"
|
||||||
#import "HttpManager.h"
|
#import "HttpManager.h"
|
||||||
@@ -13,98 +15,220 @@
|
|||||||
#import "Utils.h"
|
#import "Utils.h"
|
||||||
#import "UIComputerView.h"
|
#import "UIComputerView.h"
|
||||||
#import "UIAppView.h"
|
#import "UIAppView.h"
|
||||||
#import "App.h"
|
|
||||||
#import "SettingsViewController.h"
|
#import "SettingsViewController.h"
|
||||||
#import "DataManager.h"
|
#import "DataManager.h"
|
||||||
#import "Settings.h"
|
#import "TemporarySettings.h"
|
||||||
#import "WakeOnLanManager.h"
|
#import "WakeOnLanManager.h"
|
||||||
#import "AppListResponse.h"
|
#import "AppListResponse.h"
|
||||||
#import "ServerInfoResponse.h"
|
#import "ServerInfoResponse.h"
|
||||||
#import "StreamFrameViewController.h"
|
#import "StreamFrameViewController.h"
|
||||||
#import "LoadingFrameViewController.h"
|
#import "LoadingFrameViewController.h"
|
||||||
|
#import "ComputerScrollView.h"
|
||||||
|
#import "TemporaryApp.h"
|
||||||
|
#import "IdManager.h"
|
||||||
|
|
||||||
@implementation MainFrameViewController {
|
@implementation MainFrameViewController {
|
||||||
NSOperationQueue* _opQueue;
|
NSOperationQueue* _opQueue;
|
||||||
Host* _selectedHost;
|
TemporaryHost* _selectedHost;
|
||||||
NSString* _uniqueId;
|
NSString* _uniqueId;
|
||||||
NSData* _cert;
|
NSData* _cert;
|
||||||
NSString* _currentGame;
|
|
||||||
DiscoveryManager* _discMan;
|
DiscoveryManager* _discMan;
|
||||||
AppAssetManager* _appManager;
|
AppAssetManager* _appManager;
|
||||||
StreamConfiguration* _streamConfig;
|
StreamConfiguration* _streamConfig;
|
||||||
UIAlertView* _pairAlert;
|
UIAlertController* _pairAlert;
|
||||||
UIScrollView* hostScrollView;
|
UIScrollView* hostScrollView;
|
||||||
int currentPosition;
|
int currentPosition;
|
||||||
|
NSArray* _sortedAppList;
|
||||||
|
NSCache* _boxArtCache;
|
||||||
}
|
}
|
||||||
static NSMutableSet* hostList;
|
static NSMutableSet* hostList;
|
||||||
static NSArray* appList;
|
|
||||||
|
|
||||||
- (void)showPIN:(NSString *)PIN {
|
- (void)showPIN:(NSString *)PIN {
|
||||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
_pairAlert = [[UIAlertView alloc] initWithTitle:@"Pairing" message:[NSString stringWithFormat:@"Enter the following PIN on the host machine: %@", PIN]delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
|
_pairAlert = [UIAlertController alertControllerWithTitle:@"Pairing"
|
||||||
[_pairAlert show];
|
message:[NSString stringWithFormat:@"Enter the following PIN on the host machine: %@", PIN]
|
||||||
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
[self presentViewController:_pairAlert animated:YES completion:nil];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)pairFailed:(NSString *)message {
|
- (void)pairFailed:(NSString *)message {
|
||||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[_pairAlert dismissWithClickedButtonIndex:0 animated:NO];
|
[_pairAlert dismissViewControllerAnimated:YES completion:nil];
|
||||||
_pairAlert = [[UIAlertView alloc] initWithTitle:@"Pairing Failed" message:message delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
|
_pairAlert = [UIAlertController alertControllerWithTitle:@"Pairing Failed"
|
||||||
[_pairAlert show];
|
message:message
|
||||||
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
[_pairAlert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:nil]];
|
||||||
|
[self presentViewController:_pairAlert animated:YES completion:nil];
|
||||||
|
|
||||||
[_discMan startDiscovery];
|
[_discMan startDiscovery];
|
||||||
[self hideLoadingFrame];
|
[self hideLoadingFrame];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)pairSuccessful {
|
- (void)pairSuccessful {
|
||||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[_pairAlert dismissWithClickedButtonIndex:0 animated:NO];
|
[_pairAlert dismissViewControllerAnimated:YES completion:nil];
|
||||||
_pairAlert = [[UIAlertView alloc] initWithTitle:@"Pairing Succesful" message:@"Successfully paired to host" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
|
|
||||||
[_pairAlert show];
|
|
||||||
[_discMan startDiscovery];
|
[_discMan startDiscovery];
|
||||||
[self hideLoadingFrame];
|
[self alreadyPaired];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)alreadyPaired {
|
- (void)alreadyPaired {
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
BOOL usingCachedAppList = false;
|
||||||
|
|
||||||
|
// Capture the host here because it can change once we
|
||||||
|
// leave the main thread
|
||||||
|
TemporaryHost* host = _selectedHost;
|
||||||
|
|
||||||
|
if ([host.appList count] > 0) {
|
||||||
|
usingCachedAppList = true;
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
_computerNameButton.title = _selectedHost.name;
|
if (host != _selectedHost) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_computerNameButton.title = host.name;
|
||||||
[self.navigationController.navigationBar setNeedsLayout];
|
[self.navigationController.navigationBar setNeedsLayout];
|
||||||
|
|
||||||
|
[self updateAppsForHost:host];
|
||||||
|
[self hideLoadingFrame];
|
||||||
});
|
});
|
||||||
HttpManager* hMan = [[HttpManager alloc] initWithHost:_selectedHost.address uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
}
|
||||||
|
Log(LOG_I, @"Using cached app list: %d", usingCachedAppList);
|
||||||
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
|
HttpManager* hMan = [[HttpManager alloc] initWithHost:host.activeAddress uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
||||||
|
|
||||||
AppListResponse* appListResp = [[AppListResponse alloc] init];
|
// Exempt this host from discovery while handling the applist query
|
||||||
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:appListResp withUrlRequest:[hMan newAppListRequest]]];
|
[_discMan removeHostFromDiscovery:host];
|
||||||
if (appListResp == nil || ![appListResp isStatusOk]) {
|
|
||||||
Log(LOG_W, @"Failed to get applist: %@", appListResp.statusMessage);
|
|
||||||
} else {
|
|
||||||
appList = [appListResp getAppList];
|
|
||||||
if (appList == nil) {
|
|
||||||
Log(LOG_W, @"Failed to parse applist");
|
|
||||||
} else {
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
[self updateApps];
|
|
||||||
});
|
|
||||||
|
|
||||||
[_appManager stopRetrieving];
|
// Try up to 5 times to get the app list
|
||||||
[_appManager retrieveAssets:appList fromHost:_selectedHost];
|
AppListResponse* appListResp;
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
appListResp = [[AppListResponse alloc] init];
|
||||||
|
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:appListResp withUrlRequest:[hMan newAppListRequest]]];
|
||||||
|
if (appListResp == nil || ![appListResp isStatusOk] || [appListResp getAppList] == nil) {
|
||||||
|
Log(LOG_W, @"Failed to get applist on try %d: %@", i, appListResp.statusMessage);
|
||||||
|
|
||||||
|
// Wait for one second then retry
|
||||||
|
[NSThread sleepForTimeInterval:1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log(LOG_I, @"App list successfully retreived - took %d tries", i);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[self hideLoadingFrame];
|
|
||||||
|
[_discMan addHostToDiscovery:host];
|
||||||
|
|
||||||
|
if (appListResp == nil || ![appListResp isStatusOk] || [appListResp getAppList] == nil) {
|
||||||
|
Log(LOG_W, @"Failed to get applist: %@", appListResp.statusMessage);
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[self hideLoadingFrame];
|
||||||
|
|
||||||
|
if (host != _selectedHost) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UIAlertController* applistAlert = [UIAlertController alertControllerWithTitle:@"Fetching App List Failed"
|
||||||
|
message:@"The connection to the PC was interrupted."
|
||||||
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
[applistAlert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:nil]];
|
||||||
|
[self presentViewController:applistAlert animated:YES completion:nil];
|
||||||
|
host.online = NO;
|
||||||
|
[self showHostSelectionView];
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[self updateApplist:[appListResp getAppList] forHost:host];
|
||||||
|
|
||||||
|
if (host != _selectedHost) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_computerNameButton.title = host.name;
|
||||||
|
[self.navigationController.navigationBar setNeedsLayout];
|
||||||
|
|
||||||
|
[self updateAppsForHost:host];
|
||||||
|
[_appManager stopRetrieving];
|
||||||
|
[_appManager retrieveAssetsFromHost:host];
|
||||||
|
[self hideLoadingFrame];
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) updateApplist:(NSSet*) newList forHost:(TemporaryHost*)host {
|
||||||
|
DataManager* database = [[DataManager alloc] init];
|
||||||
|
|
||||||
|
for (TemporaryApp* app in newList) {
|
||||||
|
BOOL appAlreadyInList = NO;
|
||||||
|
for (TemporaryApp* savedApp in host.appList) {
|
||||||
|
if ([app.id isEqualToString:savedApp.id]) {
|
||||||
|
savedApp.name = app.name;
|
||||||
|
savedApp.isRunning = app.isRunning;
|
||||||
|
appAlreadyInList = YES;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!appAlreadyInList) {
|
||||||
|
app.host = host;
|
||||||
|
[host.appList addObject:app];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL appWasRemoved;
|
||||||
|
do {
|
||||||
|
appWasRemoved = NO;
|
||||||
|
|
||||||
|
for (TemporaryApp* app in host.appList) {
|
||||||
|
appWasRemoved = YES;
|
||||||
|
for (TemporaryApp* mergedApp in newList) {
|
||||||
|
if ([mergedApp.id isEqualToString:app.id]) {
|
||||||
|
appWasRemoved = NO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (appWasRemoved) {
|
||||||
|
// Removing the app mutates the list we're iterating (which isn't legal).
|
||||||
|
// We need to jump out of this loop and restart enumeration.
|
||||||
|
|
||||||
|
[host.appList removeObject:app];
|
||||||
|
|
||||||
|
// It's important to remove the app record from the database
|
||||||
|
// since we'll have a constraint violation now that appList
|
||||||
|
// doesn't have this app in it.
|
||||||
|
[database removeApp:app];
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep looping until the list is no longer being mutated
|
||||||
|
} while (appWasRemoved);
|
||||||
|
|
||||||
|
[database updateAppsForExistingHost:host];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)showHostSelectionView {
|
- (void)showHostSelectionView {
|
||||||
appList = [[NSArray alloc] init];
|
|
||||||
[_appManager stopRetrieving];
|
[_appManager stopRetrieving];
|
||||||
|
_selectedHost = nil;
|
||||||
_computerNameButton.title = @"No Host Selected";
|
_computerNameButton.title = @"No Host Selected";
|
||||||
[self.collectionView reloadData];
|
[self.collectionView reloadData];
|
||||||
[self.view addSubview:hostScrollView];
|
[self.view addSubview:hostScrollView];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) receivedAssetForApp:(App*)app {
|
- (void) receivedAssetForApp:(TemporaryApp*)app {
|
||||||
[self.collectionView reloadData];
|
// Update the box art cache now so we don't have to do it
|
||||||
|
// on the main thread
|
||||||
|
[self updateBoxArtCacheForApp:app];
|
||||||
|
|
||||||
|
DataManager* dataManager = [[DataManager alloc] init];
|
||||||
|
[dataManager updateIconForExistingApp: app];
|
||||||
|
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[self.collectionView reloadData];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)displayDnsFailedDialog {
|
- (void)displayDnsFailedDialog {
|
||||||
@@ -115,17 +239,56 @@ static NSArray* appList;
|
|||||||
[self presentViewController:alert animated:YES completion:nil];
|
[self presentViewController:alert animated:YES completion:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) hostClicked:(Host *)host {
|
- (void) hostClicked:(TemporaryHost *)host view:(UIView *)view {
|
||||||
|
// Treat clicks on offline hosts to be long clicks
|
||||||
|
// This shows the context menu with wake, delete, etc. rather
|
||||||
|
// than just hanging for a while and failing as we would in this
|
||||||
|
// code path.
|
||||||
|
if (!host.online && view != nil) {
|
||||||
|
[self hostLongClicked:host view:view];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Log(LOG_D, @"Clicked host: %@", host.name);
|
Log(LOG_D, @"Clicked host: %@", host.name);
|
||||||
[self showLoadingFrame];
|
|
||||||
_selectedHost = host;
|
_selectedHost = host;
|
||||||
|
[self disableNavigation];
|
||||||
|
|
||||||
|
// If we are online, paired, and have a cached app list, skip straight
|
||||||
|
// to the app grid without a loading frame. This is the fast path that users
|
||||||
|
// should hit most.
|
||||||
|
if (host.online && host.pairState == PairStatePaired && host.appList.count > 0) {
|
||||||
|
[self alreadyPaired];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
[self showLoadingFrame];
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
HttpManager* hMan = [[HttpManager alloc] initWithHost:host.address uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
HttpManager* hMan = [[HttpManager alloc] initWithHost:host.activeAddress uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
||||||
ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init];
|
ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init];
|
||||||
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[hMan newServerInfoRequest]]];
|
|
||||||
|
// Exempt this host from discovery while handling the serverinfo request
|
||||||
|
[_discMan removeHostFromDiscovery:host];
|
||||||
|
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[hMan newServerInfoRequest]
|
||||||
|
fallbackError:401 fallbackRequest:[hMan newHttpServerInfoRequest]]];
|
||||||
|
[_discMan addHostToDiscovery:host];
|
||||||
|
|
||||||
if (serverInfoResp == nil || ![serverInfoResp isStatusOk]) {
|
if (serverInfoResp == nil || ![serverInfoResp isStatusOk]) {
|
||||||
Log(LOG_W, @"Failed to get server info: %@", serverInfoResp.statusMessage);
|
Log(LOG_W, @"Failed to get server info: %@", serverInfoResp.statusMessage);
|
||||||
[self hideLoadingFrame];
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[self hideLoadingFrame];
|
||||||
|
|
||||||
|
if (host != _selectedHost) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UIAlertController* applistAlert = [UIAlertController alertControllerWithTitle:@"Fetching Server Info Failed"
|
||||||
|
message:@"The connection to the PC was interrupted."
|
||||||
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
[applistAlert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:nil]];
|
||||||
|
[self presentViewController:applistAlert animated:YES completion:nil];
|
||||||
|
host.online = NO;
|
||||||
|
[self showHostSelectionView];
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
Log(LOG_D, @"server info pair status: %@", [serverInfoResp getStringTag:@"PairStatus"]);
|
Log(LOG_D, @"server info pair status: %@", [serverInfoResp getStringTag:@"PairStatus"]);
|
||||||
if ([[serverInfoResp getStringTag:@"PairStatus"] isEqualToString:@"1"]) {
|
if ([[serverInfoResp getStringTag:@"PairStatus"] isEqualToString:@"1"]) {
|
||||||
@@ -142,17 +305,10 @@ static NSArray* appList;
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)hostLongClicked:(Host *)host view:(UIView *)view {
|
- (void)hostLongClicked:(TemporaryHost *)host view:(UIView *)view {
|
||||||
Log(LOG_D, @"Long clicked host: %@", host.name);
|
Log(LOG_D, @"Long clicked host: %@", host.name);
|
||||||
UIAlertController* longClickAlert = [UIAlertController alertControllerWithTitle:host.name message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
|
UIAlertController* longClickAlert = [UIAlertController alertControllerWithTitle:host.name message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
|
||||||
if (host.online) {
|
if (!host.online) {
|
||||||
[longClickAlert addAction:[UIAlertAction actionWithTitle:@"Unpair" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
|
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
||||||
HttpManager* hMan = [[HttpManager alloc] initWithHost:host.address uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
|
||||||
[hMan executeRequest:[HttpRequest requestWithUrlRequest:[hMan newUnpairRequest]]];
|
|
||||||
});
|
|
||||||
}]];
|
|
||||||
} else {
|
|
||||||
[longClickAlert addAction:[UIAlertAction actionWithTitle:@"Wake" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
|
[longClickAlert addAction:[UIAlertAction actionWithTitle:@"Wake" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
|
||||||
UIAlertController* wolAlert = [UIAlertController alertControllerWithTitle:@"Wake On Lan" message:@"" preferredStyle:UIAlertControllerStyleAlert];
|
UIAlertController* wolAlert = [UIAlertController alertControllerWithTitle:@"Wake On Lan" message:@"" preferredStyle:UIAlertControllerStyleAlert];
|
||||||
[wolAlert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
|
[wolAlert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
|
||||||
@@ -175,8 +331,8 @@ static NSArray* appList;
|
|||||||
[dataMan removeHost:host];
|
[dataMan removeHost:host];
|
||||||
@synchronized(hostList) {
|
@synchronized(hostList) {
|
||||||
[hostList removeObject:host];
|
[hostList removeObject:host];
|
||||||
|
[self updateAllHosts:[hostList allObjects]];
|
||||||
}
|
}
|
||||||
[self updateAllHosts:[hostList allObjects]];
|
|
||||||
|
|
||||||
}]];
|
}]];
|
||||||
[longClickAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
|
[longClickAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
|
||||||
@@ -198,10 +354,8 @@ static NSArray* appList;
|
|||||||
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
|
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
|
||||||
NSString* hostAddress = ((UITextField*)[[alertController textFields] objectAtIndex:0]).text;
|
NSString* hostAddress = ((UITextField*)[[alertController textFields] objectAtIndex:0]).text;
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
|
||||||
[_discMan discoverHost:hostAddress withCallback:^(Host* host, NSString* error){
|
[_discMan discoverHost:hostAddress withCallback:^(TemporaryHost* host, NSString* error){
|
||||||
if (host != nil) {
|
if (host != nil) {
|
||||||
DataManager* dataMan = [[DataManager alloc] init];
|
|
||||||
[dataMan saveHosts];
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
@synchronized(hostList) {
|
@synchronized(hostList) {
|
||||||
[hostList addObject:host];
|
[hostList addObject:host];
|
||||||
@@ -222,19 +376,14 @@ static NSArray* appList;
|
|||||||
[self presentViewController:alertController animated:YES completion:nil];
|
[self presentViewController:alertController animated:YES completion:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) appClicked:(App *)app {
|
- (void) appClicked:(TemporaryApp *)app {
|
||||||
Log(LOG_D, @"Clicked app: %@", app.appName);
|
Log(LOG_D, @"Clicked app: %@", app.name);
|
||||||
_streamConfig = [[StreamConfiguration alloc] init];
|
_streamConfig = [[StreamConfiguration alloc] init];
|
||||||
_streamConfig.host = _selectedHost.address;
|
_streamConfig.host = app.host.activeAddress;
|
||||||
_streamConfig.hostAddr = [Utils resolveHost:_selectedHost.address];
|
_streamConfig.appID = app.id;
|
||||||
_streamConfig.appID = app.appId;
|
|
||||||
if (_streamConfig.hostAddr == 0) {
|
|
||||||
[self displayDnsFailedDialog];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataManager* dataMan = [[DataManager alloc] init];
|
DataManager* dataMan = [[DataManager alloc] init];
|
||||||
Settings* streamSettings = [dataMan retrieveSettings];
|
TemporarySettings* streamSettings = [dataMan getSettings];
|
||||||
|
|
||||||
_streamConfig.frameRate = [streamSettings.framerate intValue];
|
_streamConfig.frameRate = [streamSettings.framerate intValue];
|
||||||
_streamConfig.bitRate = [streamSettings.bitrate intValue];
|
_streamConfig.bitRate = [streamSettings.bitrate intValue];
|
||||||
@@ -247,30 +396,63 @@ static NSArray* appList;
|
|||||||
[[self revealViewController] revealToggle:self];
|
[[self revealViewController] revealToggle:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
App* currentApp = [self findRunningApp];
|
TemporaryApp* currentApp = [self findRunningApp:app.host];
|
||||||
if (currentApp != nil) {
|
if (currentApp != nil) {
|
||||||
UIAlertController* alertController = [UIAlertController
|
UIAlertController* alertController = [UIAlertController
|
||||||
alertControllerWithTitle: app.appName
|
alertControllerWithTitle: app.name
|
||||||
message: [app.appId isEqualToString:currentApp.appId] ? @"" : [NSString stringWithFormat:@"%@ is currently running", currentApp.appName]preferredStyle:UIAlertControllerStyleAlert];
|
message: [app.id isEqualToString:currentApp.id] ? @"" : [NSString stringWithFormat:@"%@ is currently running", currentApp.name]preferredStyle:UIAlertControllerStyleAlert];
|
||||||
[alertController addAction:[UIAlertAction
|
[alertController addAction:[UIAlertAction
|
||||||
actionWithTitle:[app.appId isEqualToString:currentApp.appId] ? @"Resume App" : @"Resume Running App" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
|
actionWithTitle:[app.id isEqualToString:currentApp.id] ? @"Resume App" : @"Resume Running App" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
|
||||||
Log(LOG_I, @"Resuming application: %@", currentApp.appName);
|
Log(LOG_I, @"Resuming application: %@", currentApp.name);
|
||||||
[self performSegueWithIdentifier:@"createStreamFrame" sender:nil];
|
[self performSegueWithIdentifier:@"createStreamFrame" sender:nil];
|
||||||
}]];
|
}]];
|
||||||
[alertController addAction:[UIAlertAction actionWithTitle:
|
[alertController addAction:[UIAlertAction actionWithTitle:
|
||||||
[app.appId isEqualToString:currentApp.appId] ? @"Quit App" : @"Quit Running App and Start" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action){
|
[app.id isEqualToString:currentApp.id] ? @"Quit App" : @"Quit Running App and Start" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action){
|
||||||
Log(LOG_I, @"Quitting application: %@", currentApp.appName);
|
Log(LOG_I, @"Quitting application: %@", currentApp.name);
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
HttpManager* hMan = [[HttpManager alloc] initWithHost:_selectedHost.address uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
HttpManager* hMan = [[HttpManager alloc] initWithHost:app.host.activeAddress uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
||||||
[hMan executeRequestSynchronously:[HttpRequest requestWithUrlRequest:[hMan newQuitAppRequest]]];
|
HttpResponse* quitResponse = [[HttpResponse alloc] init];
|
||||||
// TODO: handle failure to quit app
|
HttpRequest* quitRequest = [HttpRequest requestForResponse: quitResponse withUrlRequest:[hMan newQuitAppRequest]];
|
||||||
currentApp.isRunning = NO;
|
|
||||||
|
// Exempt this host from discovery while handling the quit operation
|
||||||
|
[_discMan removeHostFromDiscovery:app.host];
|
||||||
|
[hMan executeRequestSynchronously:quitRequest];
|
||||||
|
[_discMan addHostToDiscovery:app.host];
|
||||||
|
|
||||||
|
UIAlertController* alert;
|
||||||
|
|
||||||
|
// If it fails, display an error and stop the current operation
|
||||||
|
if (quitResponse.statusCode != 200) {
|
||||||
|
alert = [UIAlertController alertControllerWithTitle:@"Quitting App Failed"
|
||||||
|
message:@"Failed to quit app. If this app was started by "
|
||||||
|
"another device, you'll need to quit from that device."
|
||||||
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
}
|
||||||
|
// If it succeeds and we're to start streaming, segue to the stream and return
|
||||||
|
else if (![app.id isEqualToString:currentApp.id]) {
|
||||||
|
currentApp.isRunning = NO;
|
||||||
|
|
||||||
if (![app.appId isEqualToString:currentApp.appId]) {
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[self updateAppsForHost:app.host];
|
||||||
[self performSegueWithIdentifier:@"createStreamFrame" sender:nil];
|
[self performSegueWithIdentifier:@"createStreamFrame" sender:nil];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
// Otherwise, display a dialog to notify the user that the app was quit
|
||||||
|
else {
|
||||||
|
currentApp.isRunning = NO;
|
||||||
|
|
||||||
|
alert = [UIAlertController alertControllerWithTitle:@"Quitting App"
|
||||||
|
message:@"The app was quit successfully."
|
||||||
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
}
|
||||||
|
|
||||||
|
[alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:nil]];
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[self updateAppsForHost:app.host];
|
||||||
|
[self presentViewController:alert animated:YES completion:nil];
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}]];
|
}]];
|
||||||
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
|
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
|
||||||
@@ -280,8 +462,8 @@ static NSArray* appList;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (App*) findRunningApp {
|
- (TemporaryApp*) findRunningApp:(TemporaryHost*)host {
|
||||||
for (App* app in appList) {
|
for (TemporaryApp* app in host.appList) {
|
||||||
if (app.isRunning) {
|
if (app.isRunning) {
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
@@ -311,6 +493,7 @@ static NSArray* appList;
|
|||||||
|
|
||||||
- (void) hideLoadingFrame {
|
- (void) hideLoadingFrame {
|
||||||
[self dismissViewControllerAnimated:YES completion:nil];
|
[self dismissViewControllerAnimated:YES completion:nil];
|
||||||
|
[self enableNavigation];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidLoad
|
- (void)viewDidLoad
|
||||||
@@ -335,7 +518,7 @@ static NSArray* appList;
|
|||||||
|
|
||||||
// Set up crypto
|
// Set up crypto
|
||||||
[CryptoManager generateKeyPairUsingSSl];
|
[CryptoManager generateKeyPairUsingSSl];
|
||||||
_uniqueId = [CryptoManager getUniqueID];
|
_uniqueId = [IdManager getUniqueId];
|
||||||
_cert = [CryptoManager readCertFromFile];
|
_cert = [CryptoManager readCertFromFile];
|
||||||
|
|
||||||
_appManager = [[AppAssetManager alloc] initWithCallback:self];
|
_appManager = [[AppAssetManager alloc] initWithCallback:self];
|
||||||
@@ -346,19 +529,54 @@ static NSArray* appList;
|
|||||||
hostList = [[NSMutableSet alloc] init];
|
hostList = [[NSMutableSet alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_boxArtCache = [[NSCache alloc] init];
|
||||||
|
|
||||||
[self setAutomaticallyAdjustsScrollViewInsets:NO];
|
[self setAutomaticallyAdjustsScrollViewInsets:NO];
|
||||||
|
|
||||||
hostScrollView = [[UIScrollView alloc] init];
|
hostScrollView = [[ComputerScrollView alloc] init];
|
||||||
hostScrollView.frame = CGRectMake(0, self.navigationController.navigationBar.frame.origin.y + self.navigationController.navigationBar.frame.size.height, self.view.frame.size.width, self.view.frame.size.height / 2);
|
hostScrollView.frame = CGRectMake(0, self.navigationController.navigationBar.frame.origin.y + self.navigationController.navigationBar.frame.size.height, self.view.frame.size.width, self.view.frame.size.height / 2);
|
||||||
[hostScrollView setShowsHorizontalScrollIndicator:NO];
|
[hostScrollView setShowsHorizontalScrollIndicator:NO];
|
||||||
|
hostScrollView.delaysContentTouches = NO;
|
||||||
|
|
||||||
|
UIButton* pullArrow = [[UIButton alloc] init];
|
||||||
|
[pullArrow setImage:[UIImage imageNamed:@"PullArrow"] forState:UIControlStateNormal];
|
||||||
|
[pullArrow sizeToFit];
|
||||||
|
pullArrow.frame = CGRectMake(0,
|
||||||
|
self.collectionView.frame.size.height / 2 - pullArrow.frame.size.height / 2 - self.navigationController.navigationBar.frame.size.height,
|
||||||
|
pullArrow.frame.size.width,
|
||||||
|
pullArrow.frame.size.height);
|
||||||
|
[self.view addSubview:pullArrow];
|
||||||
|
|
||||||
|
|
||||||
|
self.collectionView.delaysContentTouches = NO;
|
||||||
|
self.collectionView.allowsMultipleSelection = NO;
|
||||||
|
self.collectionView.multipleTouchEnabled = NO;
|
||||||
|
|
||||||
[self retrieveSavedHosts];
|
[self retrieveSavedHosts];
|
||||||
_discMan = [[DiscoveryManager alloc] initWithHosts:[hostList allObjects] andCallback:self];
|
_discMan = [[DiscoveryManager alloc] initWithHosts:[hostList allObjects] andCallback:self];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||||
|
selector: @selector(handleReturnToForeground)
|
||||||
|
name: UIApplicationWillEnterForegroundNotification
|
||||||
|
object: nil];
|
||||||
|
|
||||||
[self updateHosts];
|
[self updateHosts];
|
||||||
[self.view addSubview:hostScrollView];
|
[self.view addSubview:hostScrollView];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void)dealloc
|
||||||
|
{
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void)handleReturnToForeground
|
||||||
|
{
|
||||||
|
// This will refresh the applist
|
||||||
|
if (_selectedHost != nil) {
|
||||||
|
[self hostClicked:_selectedHost view:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)viewDidAppear:(BOOL)animated
|
- (void)viewDidAppear:(BOOL)animated
|
||||||
{
|
{
|
||||||
[super viewDidAppear:animated];
|
[super viewDidAppear:animated];
|
||||||
@@ -371,10 +589,7 @@ static NSArray* appList;
|
|||||||
|
|
||||||
[_discMan startDiscovery];
|
[_discMan startDiscovery];
|
||||||
|
|
||||||
// This will refresh the applist
|
[self handleReturnToForeground];
|
||||||
if (_selectedHost != nil) {
|
|
||||||
[self hostClicked:_selectedHost];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidDisappear:(BOOL)animated
|
- (void)viewDidDisappear:(BOOL)animated
|
||||||
@@ -383,23 +598,36 @@ static NSArray* appList;
|
|||||||
// when discovery stops, we must create a new instance because you cannot restart an NSOperation when it is finished
|
// when discovery stops, we must create a new instance because you cannot restart an NSOperation when it is finished
|
||||||
[_discMan stopDiscovery];
|
[_discMan stopDiscovery];
|
||||||
|
|
||||||
// In case the host objects were updated in the background
|
// Purge the box art cache
|
||||||
[[[DataManager alloc] init] saveHosts];
|
[_boxArtCache removeAllObjects];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) retrieveSavedHosts {
|
- (void) retrieveSavedHosts {
|
||||||
DataManager* dataMan = [[DataManager alloc] init];
|
DataManager* dataMan = [[DataManager alloc] init];
|
||||||
NSArray* hosts = [dataMan retrieveHosts];
|
NSArray* hosts = [dataMan getHosts];
|
||||||
@synchronized(hostList) {
|
@synchronized(hostList) {
|
||||||
[hostList addObjectsFromArray:hosts];
|
[hostList addObjectsFromArray:hosts];
|
||||||
|
|
||||||
|
// Initialize the non-persistent host state
|
||||||
|
for (TemporaryHost* host in hostList) {
|
||||||
|
if (host.activeAddress == nil) {
|
||||||
|
host.activeAddress = host.localAddress;
|
||||||
|
}
|
||||||
|
if (host.activeAddress == nil) {
|
||||||
|
host.activeAddress = host.externalAddress;
|
||||||
|
}
|
||||||
|
if (host.activeAddress == nil) {
|
||||||
|
host.activeAddress = host.address;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) updateAllHosts:(NSArray *)hosts {
|
- (void) updateAllHosts:(NSArray *)hosts {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
Log(LOG_D, @"New host list:");
|
Log(LOG_D, @"New host list:");
|
||||||
for (Host* host in hosts) {
|
for (TemporaryHost* host in hosts) {
|
||||||
Log(LOG_D, @"Host: \n{\n\t name:%@ \n\t address:%@ \n\t localAddress:%@ \n\t externalAddress:%@ \n\t uuid:%@ \n\t mac:%@ \n\t pairState:%d \n\t online:%d \n}", host.name, host.address, host.localAddress, host.externalAddress, host.uuid, host.mac, host.pairState, host.online);
|
Log(LOG_D, @"Host: \n{\n\t name:%@ \n\t address:%@ \n\t localAddress:%@ \n\t externalAddress:%@ \n\t uuid:%@ \n\t mac:%@ \n\t pairState:%d \n\t online:%d \n\t activeAddress:%@ \n}", host.name, host.address, host.localAddress, host.externalAddress, host.uuid, host.mac, host.pairState, host.online, host.activeAddress);
|
||||||
}
|
}
|
||||||
@synchronized(hostList) {
|
@synchronized(hostList) {
|
||||||
[hostList removeAllObjects];
|
[hostList removeAllObjects];
|
||||||
@@ -416,13 +644,16 @@ static NSArray* appList;
|
|||||||
UIComputerView* compView;
|
UIComputerView* compView;
|
||||||
float prevEdge = -1;
|
float prevEdge = -1;
|
||||||
@synchronized (hostList) {
|
@synchronized (hostList) {
|
||||||
for (Host* comp in hostList) {
|
// Sort the host list in alphabetical order
|
||||||
|
NSArray* sortedHostList = [[hostList allObjects] sortedArrayUsingSelector:@selector(compareName:)];
|
||||||
|
for (TemporaryHost* comp in sortedHostList) {
|
||||||
compView = [[UIComputerView alloc] initWithComputer:comp andCallback:self];
|
compView = [[UIComputerView alloc] initWithComputer:comp andCallback:self];
|
||||||
compView.center = CGPointMake([self getCompViewX:compView addComp:addComp prevEdge:prevEdge], hostScrollView.frame.size.height / 2);
|
compView.center = CGPointMake([self getCompViewX:compView addComp:addComp prevEdge:prevEdge], hostScrollView.frame.size.height / 2);
|
||||||
prevEdge = compView.frame.origin.x + compView.frame.size.width;
|
prevEdge = compView.frame.origin.x + compView.frame.size.width;
|
||||||
[hostScrollView addSubview:compView];
|
[hostScrollView addSubview:compView];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prevEdge = [self getCompViewX:addComp addComp:addComp prevEdge:prevEdge];
|
prevEdge = [self getCompViewX:addComp addComp:addComp prevEdge:prevEdge];
|
||||||
addComp.center = CGPointMake(prevEdge, hostScrollView.frame.size.height / 2);
|
addComp.center = CGPointMake(prevEdge, hostScrollView.frame.size.height / 2);
|
||||||
|
|
||||||
@@ -438,7 +669,66 @@ static NSArray* appList;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) updateApps {
|
// This function forces immediate decoding of the UIImage, rather
|
||||||
|
// than the default lazy decoding that results in janky scrolling.
|
||||||
|
+ (UIImage*) loadBoxArtForCaching:(TemporaryApp*)app {
|
||||||
|
|
||||||
|
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)app.image, NULL);
|
||||||
|
CGImageRef cgImage = CGImageSourceCreateImageAtIndex(source, 0, (__bridge CFDictionaryRef)@{(id)kCGImageSourceShouldCacheImmediately: (id)kCFBooleanTrue});
|
||||||
|
|
||||||
|
UIImage *boxArt = [UIImage imageWithCGImage:cgImage];
|
||||||
|
|
||||||
|
CGImageRelease(cgImage);
|
||||||
|
CFRelease(source);
|
||||||
|
|
||||||
|
return boxArt;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) updateBoxArtCacheForApp:(TemporaryApp*)app {
|
||||||
|
if (app.image == nil) {
|
||||||
|
[_boxArtCache removeObjectForKey:app];
|
||||||
|
}
|
||||||
|
else if ([_boxArtCache objectForKey:app] == nil) {
|
||||||
|
[_boxArtCache setObject:[MainFrameViewController loadBoxArtForCaching:app] forKey:app];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) updateAppsForHost:(TemporaryHost*)host {
|
||||||
|
if (host != _selectedHost) {
|
||||||
|
Log(LOG_W, @"Mismatched host during app update");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_sortedAppList = [host.appList allObjects];
|
||||||
|
_sortedAppList = [_sortedAppList sortedArrayUsingSelector:@selector(compareName:)];
|
||||||
|
|
||||||
|
// Split the sorted array in half to allow 2 jobs to process app assets at once
|
||||||
|
NSArray *firstHalf;
|
||||||
|
NSArray *secondHalf;
|
||||||
|
NSRange range;
|
||||||
|
|
||||||
|
range.location = 0;
|
||||||
|
range.length = [_sortedAppList count] / 2;
|
||||||
|
|
||||||
|
firstHalf = [_sortedAppList subarrayWithRange:range];
|
||||||
|
|
||||||
|
range.location = range.length;
|
||||||
|
range.length = [_sortedAppList count] - range.length;
|
||||||
|
|
||||||
|
secondHalf = [_sortedAppList subarrayWithRange:range];
|
||||||
|
|
||||||
|
// Start 2 jobs
|
||||||
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
|
for (TemporaryApp* app in firstHalf) {
|
||||||
|
[self updateBoxArtCacheForApp:app];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
|
for (TemporaryApp* app in secondHalf) {
|
||||||
|
[self updateBoxArtCacheForApp:app];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
[hostScrollView removeFromSuperview];
|
[hostScrollView removeFromSuperview];
|
||||||
[self.collectionView reloadData];
|
[self.collectionView reloadData];
|
||||||
}
|
}
|
||||||
@@ -446,8 +736,8 @@ static NSArray* appList;
|
|||||||
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||||
UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"AppCell" forIndexPath:indexPath];
|
UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"AppCell" forIndexPath:indexPath];
|
||||||
|
|
||||||
App* app = appList[indexPath.row];
|
TemporaryApp* app = _sortedAppList[indexPath.row];
|
||||||
UIAppView* appView = [[UIAppView alloc] initWithApp:app andCallback:self];
|
UIAppView* appView = [[UIAppView alloc] initWithApp:app cache:_boxArtCache andCallback:self];
|
||||||
[appView updateAppImage];
|
[appView updateAppImage];
|
||||||
|
|
||||||
if (appView.bounds.size.width > 10.0) {
|
if (appView.bounds.size.width > 10.0) {
|
||||||
@@ -459,6 +749,18 @@ static NSArray* appList;
|
|||||||
[cell.subviews.firstObject removeFromSuperview]; // Remove a view that was previously added
|
[cell.subviews.firstObject removeFromSuperview]; // Remove a view that was previously added
|
||||||
[cell addSubview:appView];
|
[cell addSubview:appView];
|
||||||
|
|
||||||
|
|
||||||
|
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:cell.bounds];
|
||||||
|
cell.layer.masksToBounds = NO;
|
||||||
|
cell.layer.shadowColor = [UIColor blackColor].CGColor;
|
||||||
|
cell.layer.shadowOffset = CGSizeMake(1.0f, 5.0f);
|
||||||
|
cell.layer.shadowOpacity = 0.5f;
|
||||||
|
cell.layer.shadowPath = shadowPath.CGPath;
|
||||||
|
|
||||||
|
cell.layer.borderColor = [[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3f] CGColor];
|
||||||
|
cell.layer.borderWidth = 1;
|
||||||
|
cell.exclusiveTouch = YES;
|
||||||
|
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -467,7 +769,12 @@ static NSArray* appList;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
||||||
return appList.count;
|
if (_selectedHost != nil) {
|
||||||
|
return _selectedHost.appList.count;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didReceiveMemoryWarning
|
- (void)didReceiveMemoryWarning
|
||||||
@@ -489,4 +796,12 @@ static NSArray* appList;
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) disableNavigation {
|
||||||
|
self.navigationController.navigationBar.topItem.rightBarButtonItem.enabled = NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) enableNavigation {
|
||||||
|
self.navigationController.navigationBar.topItem.rightBarButtonItem.enabled = YES;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -554,8 +554,8 @@ static CGFloat scaledValue( CGFloat v1, CGFloat min2, CGFloat max2, CGFloat min1
|
|||||||
UITouch *touch = [touches anyObject];
|
UITouch *touch = [touches anyObject];
|
||||||
CGPoint nowPoint = [touch locationInView:self.view];
|
CGPoint nowPoint = [touch locationInView:self.view];
|
||||||
|
|
||||||
if (abs(nowPoint.x - _beginPoint.x) > kDirectionPanThreshold) _dragging = YES;
|
if (fabs(nowPoint.x - _beginPoint.x) > kDirectionPanThreshold) _dragging = YES;
|
||||||
else if (abs(nowPoint.y - _beginPoint.y) > kDirectionPanThreshold) self.state = UIGestureRecognizerStateFailed;
|
else if (fabs(nowPoint.y - _beginPoint.y) > kDirectionPanThreshold) self.state = UIGestureRecognizerStateFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -742,15 +742,6 @@ const int FrontViewPositionNone = 0xff;
|
|||||||
_userInteractionStore = _contentView.userInteractionEnabled;
|
_userInteractionStore = _contentView.userInteractionEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (NSUInteger)supportedInterfaceOrientations
|
|
||||||
{
|
|
||||||
// we could have simply not implemented this, but we choose to call super to make explicit that we
|
|
||||||
// want the default behavior.
|
|
||||||
return [super supportedInterfaceOrientations];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - Public methods and property accessors
|
#pragma mark - Public methods and property accessors
|
||||||
|
|
||||||
- (void)setFrontViewController:(UIViewController *)frontViewController
|
- (void)setFrontViewController:(UIViewController *)frontViewController
|
||||||
@@ -1274,7 +1265,7 @@ const int FrontViewPositionNone = 0xff;
|
|||||||
NSTimeInterval duration = _toggleAnimationDuration;
|
NSTimeInterval duration = _toggleAnimationDuration;
|
||||||
|
|
||||||
// Velocity driven change:
|
// Velocity driven change:
|
||||||
if (fabsf(velocity) > _quickFlickVelocity)
|
if (fabs(velocity) > _quickFlickVelocity)
|
||||||
{
|
{
|
||||||
// we may need to set the drag position and to adjust the animation duration
|
// we may need to set the drag position and to adjust the animation duration
|
||||||
CGFloat journey = xLocation;
|
CGFloat journey = xLocation;
|
||||||
@@ -1292,7 +1283,7 @@ const int FrontViewPositionNone = 0xff;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
duration = fabsf(journey/velocity);
|
duration = fabs(journey/velocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Position driven change:
|
// Position driven change:
|
||||||
@@ -1349,7 +1340,7 @@ const int FrontViewPositionNone = 0xff;
|
|||||||
|
|
||||||
NSTimeInterval duration = animated?_toggleAnimationDuration:0.0;
|
NSTimeInterval duration = animated?_toggleAnimationDuration:0.0;
|
||||||
NSTimeInterval firstDuration = duration;
|
NSTimeInterval firstDuration = duration;
|
||||||
int initialPosDif = abs( _frontViewPosition - preReplacementPosition );
|
int initialPosDif = (int) labs( _frontViewPosition - preReplacementPosition );
|
||||||
if ( initialPosDif == 1 ) firstDuration *= 0.8;
|
if ( initialPosDif == 1 ) firstDuration *= 0.8;
|
||||||
else if ( initialPosDif == 0 ) firstDuration = 0;
|
else if ( initialPosDif == 0 ) firstDuration = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "SettingsViewController.h"
|
#import "SettingsViewController.h"
|
||||||
#import "Settings.h"
|
#import "TemporarySettings.h"
|
||||||
#import "DataManager.h"
|
#import "DataManager.h"
|
||||||
|
|
||||||
#define BITRATE_INTERVAL 500 // in kbps
|
#define BITRATE_INTERVAL 500 // in kbps
|
||||||
@@ -22,7 +22,7 @@ static NSString* bitrateFormat = @"Bitrate: %.1f Mbps";
|
|||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
|
||||||
DataManager* dataMan = [[DataManager alloc] init];
|
DataManager* dataMan = [[DataManager alloc] init];
|
||||||
Settings* currentSettings = [dataMan retrieveSettings];
|
TemporarySettings* currentSettings = [dataMan getSettings];
|
||||||
|
|
||||||
// Bitrate is persisted in kbps
|
// Bitrate is persisted in kbps
|
||||||
_bitrate = [currentSettings.bitrate integerValue];
|
_bitrate = [currentSettings.bitrate integerValue];
|
||||||
@@ -33,18 +33,44 @@ static NSString* bitrateFormat = @"Bitrate: %.1f Mbps";
|
|||||||
} else if ([currentSettings.height integerValue] == 1080) {
|
} else if ([currentSettings.height integerValue] == 1080) {
|
||||||
resolution = 1;
|
resolution = 1;
|
||||||
} else {
|
} else {
|
||||||
resolution = 2;
|
resolution = 0;
|
||||||
}
|
}
|
||||||
NSInteger onscreenControls = [currentSettings.onscreenControls integerValue];
|
NSInteger onscreenControls = [currentSettings.onscreenControls integerValue];
|
||||||
|
|
||||||
[self.resolutionSelector setSelectedSegmentIndex:resolution];
|
[self.resolutionSelector setSelectedSegmentIndex:resolution];
|
||||||
|
[self.resolutionSelector addTarget:self action:@selector(newResolutionFpsChosen) forControlEvents:UIControlEventValueChanged];
|
||||||
[self.framerateSelector setSelectedSegmentIndex:framerate];
|
[self.framerateSelector setSelectedSegmentIndex:framerate];
|
||||||
|
[self.framerateSelector addTarget:self action:@selector(newResolutionFpsChosen) forControlEvents:UIControlEventValueChanged];
|
||||||
[self.onscreenControlSelector setSelectedSegmentIndex:onscreenControls];
|
[self.onscreenControlSelector setSelectedSegmentIndex:onscreenControls];
|
||||||
[self.bitrateSlider setValue:(_bitrate / BITRATE_INTERVAL) animated:YES];
|
[self.bitrateSlider setValue:(_bitrate / BITRATE_INTERVAL) animated:YES];
|
||||||
[self.bitrateSlider addTarget:self action:@selector(bitrateSliderMoved) forControlEvents:UIControlEventValueChanged];
|
[self.bitrateSlider addTarget:self action:@selector(bitrateSliderMoved) forControlEvents:UIControlEventValueChanged];
|
||||||
[self updateBitrateText];
|
[self updateBitrateText];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) newResolutionFpsChosen {
|
||||||
|
NSInteger frameRate = [self getChosenFrameRate];
|
||||||
|
NSInteger resHeight = [self getChosenStreamHeight];
|
||||||
|
NSInteger defaultBitrate;
|
||||||
|
|
||||||
|
// 1080p60 is 20 Mbps
|
||||||
|
if (frameRate == 60 && resHeight == 1080) {
|
||||||
|
defaultBitrate = 20000;
|
||||||
|
}
|
||||||
|
// 720p60 and 1080p30 are 10 Mbps
|
||||||
|
else if (frameRate == 60 || resHeight == 1080) {
|
||||||
|
defaultBitrate = 10000;
|
||||||
|
}
|
||||||
|
// 720p30 is 5 Mbps
|
||||||
|
else {
|
||||||
|
defaultBitrate = 5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
_bitrate = defaultBitrate;
|
||||||
|
[self.bitrateSlider setValue:defaultBitrate / BITRATE_INTERVAL animated:YES];
|
||||||
|
|
||||||
|
[self updateBitrateText];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) bitrateSliderMoved {
|
- (void) bitrateSliderMoved {
|
||||||
_bitrate = BITRATE_INTERVAL * (int)self.bitrateSlider.value;
|
_bitrate = BITRATE_INTERVAL * (int)self.bitrateSlider.value;
|
||||||
[self updateBitrateText];
|
[self updateBitrateText];
|
||||||
@@ -55,25 +81,23 @@ static NSString* bitrateFormat = @"Bitrate: %.1f Mbps";
|
|||||||
[self.bitrateLabel setText:[NSString stringWithFormat:bitrateFormat, _bitrate / 1000.]];
|
[self.bitrateLabel setText:[NSString stringWithFormat:bitrateFormat, _bitrate / 1000.]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSInteger) getChosenFrameRate {
|
||||||
|
return [self.framerateSelector selectedSegmentIndex] == 0 ? 30 : 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSInteger) getChosenStreamHeight {
|
||||||
|
return [self.resolutionSelector selectedSegmentIndex] == 0 ? 720 : 1080;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSInteger) getChosenStreamWidth {
|
||||||
|
return [self getChosenStreamHeight] == 720 ? 1280 : 1920;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) saveSettings {
|
- (void) saveSettings {
|
||||||
DataManager* dataMan = [[DataManager alloc] init];
|
DataManager* dataMan = [[DataManager alloc] init];
|
||||||
NSInteger framerate = [self.framerateSelector selectedSegmentIndex] == 0 ? 30 : 60;
|
NSInteger framerate = [self getChosenFrameRate];
|
||||||
NSInteger height;
|
NSInteger height = [self getChosenStreamHeight];
|
||||||
NSInteger width;
|
NSInteger width = [self getChosenStreamWidth];
|
||||||
if ([self.resolutionSelector selectedSegmentIndex] == 2) {
|
|
||||||
// Get screen native resolution
|
|
||||||
height = [UIScreen mainScreen].bounds.size.height * [UIScreen mainScreen].scale;
|
|
||||||
width = [UIScreen mainScreen].bounds.size.width * [UIScreen mainScreen].scale;
|
|
||||||
|
|
||||||
UIAlertController *alertResolution = [UIAlertController alertControllerWithTitle:@"Native resolution" message:[NSString stringWithFormat:@"You must select the following resolution in the game settings: %lix%li", (long)width, (long)height] preferredStyle:UIAlertControllerStyleAlert];
|
|
||||||
[alertResolution addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleCancel handler:nil]];
|
|
||||||
[self presentViewController:alertResolution animated:YES completion:nil];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
height = [self.resolutionSelector selectedSegmentIndex] == 0 ? 720 : 1080;
|
|
||||||
width = height == 720 ? 1280 : 1920;
|
|
||||||
}
|
|
||||||
NSInteger onscreenControls = [self.onscreenControlSelector selectedSegmentIndex];
|
NSInteger onscreenControls = [self.onscreenControlSelector selectedSegmentIndex];
|
||||||
[dataMan saveSettingsWithBitrate:_bitrate framerate:framerate height:height width:width onscreenControls:onscreenControls];
|
[dataMan saveSettingsWithBitrate:_bitrate framerate:framerate height:height width:width onscreenControls:onscreenControls];
|
||||||
}
|
}
|
||||||
|
|||||||