Session 318
These are confidential sessionsplease refrain from streaming, blogging, or taking pictures.
Joe Abuan
Interactive Media Group, Software Engineering
Agenda
Overview of capabilities The APIs
GKSession GKPeerPickerController GKVoiceChatService
GKPeerPickerController GKSession
Handles Networking
UI for Connecting
Duarte
Voice Chat
GKVoiceChatService
Overview
Application
Overview
Application
10
Overview
Application
Bonjour
Sockets
11
Overview
Application
Bonjour
Sockets
Russian Hill Wednesday 10:30AM
12
Overview
Application
Bonjour
Sockets
13
GKSession Class
Terminology
Peer
Peer
Peer
Peer
Peer
14
GKSession Class
Terminology
Peer Peer ID
Peer
Peer
peerID-1 Peer
peerID-2 Peer
peerID-3
peerID-4
15
GKSession Class
Terminology
Peer Peer ID displayNameForPeerID
Peer
peerID-2 Peer
peerID-3
peerID-4
16
Duarte Some nice graphic here with three parts that combine to make one big piece
17
Duarte Some nice graphic here with three parts that combine to make one big piece
18
19
Session ID
Uniquely identifies your application Recommended to be a registered Bonjour service type
20
Display name
21
Duarte
22
Set as available
session.available = YES;
23
24
Available state
if (GKPeerStateAvailable == state) { // Found a peer that can accept connection requests
Connected state
if (GKPeerStateConnected == state) { // Now connected to another peer
25
26
27
28
29
Receive data
- (void) receiveData: fromPeer: inSession: context: (NSData *) data (NSString *) peerID (GKSession *) session (void *) context { }
30
GKSession Review
Creates the peer-to-peer network and delivers your data
Works over Bluetooth Peers and peer IDs
Three stages
Initialize Connect Deliver data
31
Jonathan Bennett
Game Kit Engineer
32
Standard UI
Application
Bonjour
Sockets
34
Application
Bonjour
Sockets
35
Need real art - some real or faked app in background instead of the colored boxes - iPhone surrounding screenshot - Note there are multiple images in this smart build
List nearby discovered iPhones Invite another iPhone to connect Accept invitations Connect to another peer Turn on Bluetooth if needed
36
Duarte-
Johns iPhone
Need a phone with a main menu of an app (same theme as the other mock-ups as the other slides). Also, any cleanup you see t of this series of builds over the next few slides would be great.
37
Duarte-
Johns iPhone
Similar to before, need this screenshot wrapped around an iPhone, with a fake game oneto-one multiplayer type game behind it.
Session?
38
Duarte-
Johns iPhone
Similar to before, need this screenshot wrapped around an iPhone, with a fake game oneto-one multiplayer type game behind it.
Session
39
Duarte-
Johns iPhone
Similar to before, need this screenshot wrapped around an iPhone, with a fake game oneto-one multiplayer type game behind it.
Session
40
Duarte-
Johns iPhone
Janes iPhone
Need a good Wireless fan instead of these handdrawn ones. Similar to before, need this screenshot wrapped around an iPhone, with a fake game oneto-one multiplayer type game behind it.
Application
Found Peer
Found Peer
41
Duarte-
Johns iPhone
Janes iPhone
Need better button press animation (although this one kind of works) Need a list of peers that has each other. On Johns iPhone should show one item Janes iPhone in the list, on Janes iPhone should show Johns iPhone in the list. Same as ebfore, these screenshots should be wrapped in iphones and a fake game UI behind the picker.
42
Duarte-
Johns iPhone
Janes iPhone
Similar to before, need this screenshot wrapped around an iPhone, with a fake game oneto-one multiplayer type game behind it.
43
Duarte-
Johns iPhone
Janes iPhone
Need better button press animation (although this one works okay). Similar to before, need this screenshot wrapped around an iPhone, with a fake game oneto-one multiplayer type game behind it.
44
Duarte-
Johns iPhone
Janes iPhone
Similar to before, need this screenshot wrapped around an iPhone, with a fake game oneto-one multiplayer type game behind it.
Connected
Connected
45
Duarte-
Johns iPhone
Janes iPhone
Similar to before, need this screenshot wrapped around an iPhone, with a fake game oneto-one multiplayer type game behind it.
Dismiss
Dismiss
46
Duarte -
Johns iPhone
Janes iPhone
Application
Application
Session
Connected
Session
47
Johns iPhone
Janes iPhone
Application Session
Connected
Application Session
48
49
50
51
Important: In iPhone OS 3.0, the Peer Picker only configures nearby connections over Bluetooth. Your application will have to configure other connection types.
52
Responsibilities
Respond to user actions Tell Peer Picker who to look for Respond when peers connected
53
54
55
57
lots of orange, maybe too much to highlight important parts. consider some type of build to change focus.
Implement -peerPickerController:didSelectConnectionType: Optional: Only needed when supporting multiple connection types Dismiss Peer Picker if Online selected
- (void) peerPickerController: (GKPeerPickerController *) picker didSelectConnectionType: (GKPeerPickerConnectionType) type { if( type == GKPeerPickerConnectionTypeOnline ) { [picker dismiss]; picker.delegate = nil; [picker autorelease]; // Display your own user interface for configuring Internet connections. } }
58
DuarteSimilar to before, need this screenshot wrapped around an iPhone, with a fake game one-to-one multiplayer type game behind it.
Session?
59
Duarte-
Similar to before, need this screenshot wrapped around an iPhone, with a fake game one-to-one multiplayer type game behind it.
Session
60
DuarteSimilar to before, need this screenshot wrapped around an iPhone, with a fake game one-to-one multiplayer type game behind it.
Session
Implement -peerPickerController:sessionForConnectionType: If not implemented, Peer Picker creates default GKSession object Provided GKSession must be configured to GKSessionModePeer
- (GKSession *)peerPickerController: (GKPeerPickerController *) picker sessionForConnectionType: (GKPeerPickerConnectionType) type { GKSession *session = [[GKSession alloc] initWithSessionID: myExampleSessionID displayName: playerName sessionMode: GKSessionModePeer]; return [session autorelease]; }
There are a few different ways the developer may want to provide and create a GKSession for the picker. Do we need to create other slides to go over some of the different options? Is this the best correct example? Do we need/want to set the session/delegate here? Need to highlight important parts of the code. Look at presenter notes.
62
Connected
Connected
64
65
66
For Duarte -
67
GKVoiceChatService
Adding voice chat to your application
Roberto Garcia
Game Kit Engineer
68
Overview
Understanding the API Implementation using Bonjour sample code
69
Duarte
Architecture
Application implements
Application GKVoiceChatClient GKVoiceChatService
Make sure this color scheme matches previous block color schemes
GKVoiceChatClient Protocol Calls GKVoiceChatService methods GKVoiceChatService uses GKVoiceChatClient protocol to pass setup information
Apartment B Apartment B
70
71
Application
GKVoiceChatClient GKVoiceChatService Invite
Duarte Literally a cloud representing arbitrary connection infrastructure bet ween the devices. Use connection gure consistent with previous slides
Application
GKVoiceChatClient GKVoiceChatService
72
Application
GKVoiceChatClient GKVoiceChatService Reply
Application
GKVoiceChatClient GKVoiceChatService
73
Application
GKVoiceChatClient Audio GKVoiceChatService
Application
GKVoiceChatClient GKVoiceChatService
74
75
GKVoiceChatClient Protocol
Delegate that provides a channel abstraction Only required methods are
-(NSString *) participantID -(void) voiceChatService:sendData:toParticipantID
-(void) receivedData:fromParticipantID
76
-(NSString*)participantID
An address semantically meaningful only to the client
An AIM account name, a fully qualified Jabber ID, Bonjour Service Instance Name
77
-(void) VoiceChatService:sendData:toParticipantID:
Called by GKVoiceChatService to send control packets!
[voiceChatClient voiceChatService: self sendData: inviteOrReplyData toParticipantID: @alice@fooim.org];
78
-(void) VoiceChatService:sendData:toParticipantID:
Remote instance calls GKVoiceChatService
receivedData:fromParticipantID
[voiceChatService receivedData: inviteOrReplyData fromParticipantID: @bob@fooim.org];
79
startVoiceChat
Application
I use the dissolve effect bet ween slides to animate the disappearance of objects on this slide and the appearance of objects on the next slide.
Application
Invite Invite GKVoiceChatClient
This slide and the following slides need to be made consistent with the previous similar slides.
GKVoiceChatClient GKVoiceChatService
GKVoiceChatService
The line strokes on the second invite shape are intentional to indicate wrapping of the invite packet by the VoiceChatClient/Application
80
Application
GKVoiceChatClient GKVoiceChatService Invite
Application
GKVoiceChatClient GKVoiceChatService receivedInvitation
81
acceptCall
Application
GKVoiceChatClient GKVoiceChatService Reply
Application
GKVoiceChatClient GKVoiceChatService
82
Application
GKVoiceChatClient GKVoiceChatService Reply Reply
Application
GKVoiceChatClient GKVoiceChatService
83
Application
GKVoiceChatClient Audio GKVoiceChatService didStartVoiceChat
Application
GKVoiceChatClient GKVoiceChatService didStartVoiceChat
84
WiTap
Bonjour sample code used to establish
tcp connections over a subnet Add voice chat
85
WiTap
86
Duarte
WiTap
87
Initialization
- (void) setupVoiceChat { [self setupAudioSession]; } voiceChatService = [GKVoiceChatService defaultVoiceChatService]; voiceChatService.client = self;
88
Initialization
- (void) setupVoiceChat { [self setupAudioSession]; } voiceChatService = [GKVoiceChatService defaultVoiceChatService]; voiceChatService.client = self;
89
Initialization
- (void) setupVoiceChat { [self setupAudioSession]; } voiceChatService = [GKVoiceChatService defaultVoiceChatService]; voiceChatService.client = self;
90
Required GKVoiceChatClientMethods
Implement required methods
- (NSString *) participantID { return serviceName; } - (void)voiceChatService:(GKVoiceChatService *)voiceChatService sendData:(NSData *)data toParticipantID:(NSString *)participantID { [self performSelectorOnMainThread:@selector(voiceChatSend:) withObject:data waitUntilDone:NO]; } //service name, service type, domain
91
92
93
94
95
96
97
98
99
100
101
102
Recap
GKVoiceChatClient exchanges Invite/Reply messages
for the GKVoiceChatService layer Voice chat is fun, go for it!
103
More Information
Allan Schaffer
Graphics Technology Evangelist aschaffer@apple.com
104
Related Sessions
Zero Configuration Networking Using Bonjour
Russian Hill Wednesday 10:30AM
105
Labs
Game Kit Game Development for iPhone
iPhone Lab D Thursday 9:00AM iPhone Lab C Thursday 9:00AM
106
Q&A
WWDC Session Survey
You can rate your sessions on the WWDC Attendee Site. Survey forms are located on each session description page at: developer.apple.com/wwdc/attendee
107
108
109