Skip to content

Commit

Permalink
Working version with Example showing just PeerPicker
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Owen committed Mar 10, 2012
1 parent 523df7b commit c415f2e
Show file tree
Hide file tree
Showing 19 changed files with 651 additions and 16,491 deletions.
2 changes: 1 addition & 1 deletion as/src/default/com/jamieowen/ane/ios/p2p/GKSendDataMode.as
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package com.jamieowen.ane.ios.p2p
*/
public class GKSendDataMode
{
public static const RELIABLE:uint = 0; // needs checking.
public static const RELIABLE:uint = 0;
public static const UNRELIABLE:uint = 1;

/**
Expand Down
23 changes: 21 additions & 2 deletions as/src/ios/com/jamieowen/ane/ios/p2p/GKPeerPickerController.as
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,37 @@ package com.jamieowen.ane.ios.p2p {
public class GKPeerPickerController extends EventDispatcher
{
private var _p2p:GKPeerToPeer;

private var _disposed:Boolean;
private var _shown:Boolean;
/**
* Class Constructor Description
*/
public function GKPeerPickerController($p2p:GKPeerToPeer)
{
if( !GKPeerToPeer.CREATE_GK_OBJECTS ) throw new Error("GKPeerPickerController objects must be instantiated via a GKPeerToPeer object");
if( !GKPeerToPeer.CREATE_GK_OBJECTS ) { throw new Error("GKPeerPickerController objects must be instantiated via a GKPeerToPeer object"); return; }

_disposed = false;
_shown = false;

_p2p = $p2p;
_p2p.context.addEventListener( StatusEvent.STATUS, onExtensionContextStatus );
}

public function show():void
{
if( _shown ) return;
if( _disposed ) { throw new Error("Picker has been disposed"); return; }

_shown = true;
_p2p.context.call( "gkPeerPickerController_show");
}

public function dismiss():void
{
if( !_shown ) return;
if( _disposed ) { throw new Error("Picker has been disposed"); return; }

_shown = false;
_p2p.context.call( "gkPeerPickerController_dismiss");
}

Expand All @@ -53,15 +65,20 @@ package com.jamieowen.ane.ios.p2p {
public function get visible():Boolean
{
if( _disposed ) { throw new Error("Picker has been disposed"); return false; }
return _p2p.context.call( "gkPeerPickerController_get_visible") as Boolean;
}
public function dispose():void
{
if( _disposed ) { throw new Error("Picker has been disposed"); return; }
_p2p.context.call( "gkPeerPickerController_dispose");
_p2p.context.removeEventListener( StatusEvent.STATUS, onExtensionContextStatus );
_p2p.setGKPeerPickerController(null);
_p2p = null;
_disposed = true;
}
protected function onExtensionContextStatus( $event:StatusEvent ):void
Expand All @@ -81,6 +98,8 @@ package com.jamieowen.ane.ios.p2p {
break;
case GKPeerPickerControllerEvent.CONTROLLER_DID_CANCEL :
// set shown to false - calling dismiss twice on the ExtensionContext crashes the app.
_shown = false;
dispatchEvent( new GKPeerPickerControllerEvent(GKPeerPickerControllerEvent.CONTROLLER_DID_CANCEL));
break;
}
Expand Down
55 changes: 50 additions & 5 deletions as/src/ios/com/jamieowen/ane/ios/p2p/GKSession.as
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.jamieowen.ane.ios.p2p {
public class GKSession extends EventDispatcher
{
private var _p2p:GKPeerToPeer;
private var _disposed:Boolean;

//--//////////////////////////////////////////////////
//--//// GETTERS/SETTERS
Expand All @@ -27,11 +28,15 @@ package com.jamieowen.ane.ios.p2p {

public function get available():Boolean
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return false; }

return _p2p.context.call( "gkSession_get_available") as Boolean;
}

public function set available($available:Boolean):void
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return; }

_p2p.context.call( "gkSession_set_available", $available );
}

Expand All @@ -40,21 +45,29 @@ package com.jamieowen.ane.ios.p2p {

public function get displayName():String
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return ""; }

return _p2p.context.call( "gkSession_get_displayName") as String;
}

public function get peerID():String
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return ""; }

return _p2p.context.call( "gkSession_get_peerID") as String;
}

public function get sessionID():String
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return ""; }

return _p2p.context.call( "gkSession_get_sessionID") as String;
}

public function get sessionMode():String
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return ""; }

return _p2p.context.call( "gkSession_get_sessionMode") as String;
}

Expand All @@ -63,12 +76,16 @@ package com.jamieowen.ane.ios.p2p {

public function get disconnectTimeout():Number
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return 0; }

return _p2p.context.call( "gkSession_get_disconnectTimeout") as Number;
}


public function set disconnectTimeout( $timeout:Number ):void
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return; }

_p2p.context.call( "gkSession_set_disconnectTimeout", $timeout );
}

Expand All @@ -79,10 +96,10 @@ package com.jamieowen.ane.ios.p2p {
*/
public function GKSession( $p2p:GKPeerToPeer )
{
if( !GKPeerToPeer.CREATE_GK_OBJECTS ) throw new Error("GKSession objects must be instantiated via a GKPeerToPeer object");
if( !GKPeerToPeer.CREATE_GK_OBJECTS ) { throw new Error("GKSession objects must be instantiated via a GKPeerToPeer object"); return; }

_disposed = false;
_p2p = $p2p;

_p2p.context.addEventListener( StatusEvent.STATUS, onExtensionContextStatus );
}

Expand All @@ -95,6 +112,8 @@ package com.jamieowen.ane.ios.p2p {

public function initWithSessionID( $id:String, $displayName:String, $sessionMode:uint = GKSessionMode.PEER ):void
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return; }

if( $sessionMode != GKSessionMode.CLIENT || $sessionMode != GKSessionMode.PEER || $sessionMode != GKSessionMode.SERVER )
throw new Error( "Invalid sessionMode type");

Expand All @@ -106,12 +125,16 @@ package com.jamieowen.ane.ios.p2p {

public function peersWithConnectionState( $state:uint = GKPeerConnectionState.AVAILABLE ):Vector.<String>
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return null; }

return _p2p.context.call( "gkSession_peersWithConnectionState", $state ) as Vector.<String>;
}


public function displayNameForPeer($peerID:String):String
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return ""; }

return _p2p.context.call( "gkSession_displayNameForPeer", $peerID ) as String;
}

Expand All @@ -120,11 +143,15 @@ package com.jamieowen.ane.ios.p2p {

public function connectToPeer($peerID:String, $timeout:Number):void
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return; }

_p2p.context.call( "gkSession_connectToPeer", $peerID, $timeout );
}

public function cancelConnectToPeer($peerID:String):void
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return; }

_p2p.context.call( "gkSession_cancelConnectToPeer", $peerID );
}

Expand All @@ -133,6 +160,8 @@ package com.jamieowen.ane.ios.p2p {

public function acceptConnectionFromPeer( $peerID:String ):Boolean
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return false; }

// if the result is false - an error should be thrown - this is not supported yet.
var result:Boolean = _p2p.context.call( "gkSession_acceptConnectionFromPeer", $peerID ) as Boolean;
if( !result )
Expand All @@ -148,6 +177,8 @@ package com.jamieowen.ane.ios.p2p {

public function denyConnectionFromPeer( $peerID:String ):void
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return; }

_p2p.context.call( "gkSession_denyConnectionFromPeer", $peerID );
}

Expand All @@ -156,6 +187,8 @@ package com.jamieowen.ane.ios.p2p {

public function sendData( $data:String, $peers:Vector.<String>, $dataMode:uint = GKSendDataMode.RELIABLE ):Boolean
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return false; }

if( $peers == null ) throw new Error( "Peers cannot be null");
else if( $dataMode != GKSendDataMode.RELIABLE || $dataMode != GKSendDataMode.UNRELIABLE ) throw new Error( "Invalid dataMode");

Expand All @@ -173,9 +206,12 @@ package com.jamieowen.ane.ios.p2p {

public function sendDataToAllPeers( $data:String, $dataMode:uint = GKSendDataMode.RELIABLE ):Boolean
{
if( $dataMode != GKSendDataMode.RELIABLE || $dataMode != GKSendDataMode.UNRELIABLE ) throw new Error( "Invalid dataMode");
if( _disposed ) { throw new Error("GKSession has been disposed"); return false; }

if( $dataMode != GKSendDataMode.RELIABLE && $dataMode != GKSendDataMode.UNRELIABLE ) throw new Error( "Invalid dataMode");

var result:Boolean = _p2p.context.call( "gkSession_sendDataToAllPeers", $data, $dataMode ) as Boolean;

if( !result )
{
// TODO : HANDLE ERROR CORRECTLY.
Expand All @@ -189,11 +225,15 @@ package com.jamieowen.ane.ios.p2p {

public function disconnectFromAllPeers():void
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return; }

_p2p.context.call( "gkSession_disconnectFromAllPeers");
}

public function disconnectPeerFromAllPeers( $peerID:String ):void
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return; }

_p2p.context.call( "gkSession_disconnectPeerFromAllPeers", $peerID );
}

Expand All @@ -202,6 +242,8 @@ package com.jamieowen.ane.ios.p2p {

public function dispose():void
{
if( _disposed ) { throw new Error("GKSession has been disposed"); return; }

_p2p.context.call( "gkSession_dispose");
_p2p.context.removeEventListener( StatusEvent.STATUS, onExtensionContextStatus );
_p2p.setGKSession(null);
Expand All @@ -213,6 +255,9 @@ package com.jamieowen.ane.ios.p2p {

protected function onExtensionContextStatus( $event:StatusEvent ):void
{
// for debugging
dispatchEvent( $event );

var peerID:String;
var error:Object;
var args:Array;
Expand Down Expand Up @@ -256,8 +301,8 @@ package com.jamieowen.ane.ios.p2p {

case GKSessionEvent.DATA_RECEIVED :
args = $event.level.split("{&}");
peerID = args[0];
var data:String = args[1];
peerID = args[1];
var data:String = args[0];
dispatchEvent( new GKSessionEvent(GKSessionEvent.DATA_RECEIVED, peerID, 0, data ));

break;
Expand Down
2 changes: 1 addition & 1 deletion build/build.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project.name = AirNativeiOS-GameKitP2P
sdk.air = /Users/jamieowen/Workbench/libraries/sdks/air3_2_022712_flex_sdk_4.6.0.23201

# The location of the iOS SDK
sdk.ios = /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk
sdk.ios = /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk

# Ant build config containing provisioning information.
provisioning.config = /Users/jamieowen/Workbench/provisioning/ios/provisioning.config
4 changes: 3 additions & 1 deletion build/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
</exec>!-->

<!-- don't build with xcode just yet - just copy from release folder !-->
<copy file="../obj-c/AirNativeiOS-GameKitP2P/build/Release-iphoneos/lib${project.name}.a" todir="../temp/ios" overwrite="true"/>
<copy file="../obj-c/AirNativeiOS-GameKitP2P/build/Debug-iphoneos/lib${project.name}.a" todir="../temp/ios" overwrite="true"/>

<!--<copy file="../obj-c/AirNativeiOS-GameKitP2P/build/Release-iphoneos/lib${project.name}.a" todir="../temp/ios" overwrite="true"/>!-->

<!--<delete dir="../temp/ios/build/"/>!-->
</target>
Expand Down
5 changes: 3 additions & 2 deletions examples/GameKitP2PExample/build/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
<arg value="-package"/>

<arg value="-target"/>
<arg value="ipa-test"/>
<arg value="ipa-debug-interpreter"/>
<!--<arg value="ipa-test"/>!-->

<arg value="-provisioning-profile"/>
<arg value="${provisioning.wildcard}"/>
Expand All @@ -47,7 +48,7 @@

<!-- output ipa and source app descriptor !-->
<arg value="ios/${project.name}Example.ipa"/>
<arg value="../bin/GameKitP2PExample-app.xml"/>
<arg value="../bin/../bin/${project.name}Example-app.xml"/>

<!-- ANE !-->
<arg value="-extdir"/>
Expand Down
Binary file modified examples/GameKitP2PExample/lib/AirNativeiOS-GameKitP2P.ane
Binary file not shown.
Binary file modified examples/GameKitP2PExample/lib/AirNativeiOS-GameKitP2P.swc
Binary file not shown.
Binary file added examples/GameKitP2PExample/lib/tweener.swc
Binary file not shown.
Loading

0 comments on commit c415f2e

Please sign in to comment.