OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if !defined(__has_feature) || !__has_feature(objc_arc) | 5 #if !defined(__has_feature) || !__has_feature(objc_arc) |
6 #error "This file requires ARC support." | 6 #error "This file requires ARC support." |
7 #endif | 7 #endif |
8 | 8 |
9 #import "remoting/client/ios/session/remoting_client.h" | 9 #import "remoting/client/ios/session/remoting_client.h" |
10 | 10 |
11 #import "base/mac/bind_objc_block.h" | 11 #import "base/mac/bind_objc_block.h" |
| 12 #import "ios/third_party/material_components_ios/src/components/Dialogs/src/Mate
rialDialogs.h" |
| 13 #import "remoting/client/ios/display/gl_display_handler.h" |
| 14 #import "remoting/client/ios/domain/client_session_details.h" |
| 15 #import "remoting/client/ios/domain/host_info.h" |
12 | 16 |
| 17 #include "base/strings/sys_string_conversions.h" |
13 #include "remoting/client/chromoting_client_runtime.h" | 18 #include "remoting/client/chromoting_client_runtime.h" |
14 #include "remoting/client/chromoting_session.h" | 19 #include "remoting/client/chromoting_session.h" |
15 #include "remoting/client/connect_to_host_info.h" | 20 #include "remoting/client/connect_to_host_info.h" |
16 #include "remoting/client/ios/session/remoting_client_session_delegate.h" | 21 #include "remoting/client/ios/session/remoting_client_session_delegate.h" |
| 22 #include "remoting/protocol/session.h" |
17 #include "remoting/protocol/video_renderer.h" | 23 #include "remoting/protocol/video_renderer.h" |
18 | 24 |
| 25 NSString* const kHostSessionStatusChanged = @"kHostSessionStatusChanged"; |
| 26 NSString* const kHostSessionPinProvided = @"kHostSessionPinProvided"; |
| 27 |
| 28 NSString* const kSessionDetails = @"kSessionDetails"; |
| 29 NSString* const kSessonStateErrorCode = @"kSessonStateErrorCode"; |
| 30 NSString* const kHostSessionPin = @"kHostSessionPin"; |
| 31 |
19 @interface RemotingClient () { | 32 @interface RemotingClient () { |
20 remoting::ChromotingClientRuntime* _runtime; | 33 remoting::ChromotingClientRuntime* _runtime; |
21 std::unique_ptr<remoting::ChromotingSession> _session; | 34 std::unique_ptr<remoting::ChromotingSession> _session; |
22 remoting::RemotingClientSessonDelegate* _sessonDelegate; | 35 remoting::RemotingClientSessonDelegate* _sessonDelegate; |
| 36 ClientSessionDetails* _sessionDetails; |
| 37 // Call _secretFetchedCallback on the network thread. |
| 38 remoting::protocol::SecretFetchedCallback _secretFetchedCallback; |
23 } | 39 } |
24 @end | 40 @end |
25 | 41 |
26 @implementation RemotingClient | 42 @implementation RemotingClient |
27 | 43 |
28 @synthesize displayHandler = _displayHandler; | 44 @synthesize displayHandler = _displayHandler; |
29 | 45 |
30 - (instancetype)init { | 46 - (instancetype)init { |
31 self = [super init]; | 47 self = [super init]; |
32 if (self) { | 48 if (self) { |
33 _runtime = remoting::ChromotingClientRuntime::GetInstance(); | 49 _runtime = remoting::ChromotingClientRuntime::GetInstance(); |
34 _sessonDelegate = new remoting::RemotingClientSessonDelegate(self); | 50 _sessonDelegate = new remoting::RemotingClientSessonDelegate(self); |
| 51 _sessionDetails = [[ClientSessionDetails alloc] init]; |
| 52 |
| 53 [[NSNotificationCenter defaultCenter] |
| 54 addObserver:self |
| 55 selector:@selector(hostSessionPinProvided:) |
| 56 name:kHostSessionPinProvided |
| 57 object:nil]; |
35 } | 58 } |
36 return self; | 59 return self; |
37 } | 60 } |
38 | 61 |
39 - (void)connectToHost:(const remoting::ConnectToHostInfo&)info { | 62 - (void)connectToHost:(HostInfo*)hostInfo |
40 remoting::ConnectToHostInfo hostInfo(info); | 63 username:(NSString*)username |
| 64 accessToken:(NSString*)accessToken { |
| 65 DCHECK(hostInfo); |
| 66 DCHECK(hostInfo.jabberId); |
| 67 DCHECK(hostInfo.hostId); |
| 68 DCHECK(hostInfo.publicKey); |
| 69 |
| 70 _sessionDetails.hostInfo = hostInfo; |
| 71 |
| 72 remoting::ConnectToHostInfo info; |
| 73 info.username = base::SysNSStringToUTF8(username); |
| 74 info.auth_token = base::SysNSStringToUTF8(accessToken); |
| 75 info.host_jid = base::SysNSStringToUTF8(hostInfo.jabberId); |
| 76 info.host_id = base::SysNSStringToUTF8(hostInfo.hostId); |
| 77 info.host_pubkey = base::SysNSStringToUTF8(hostInfo.publicKey); |
| 78 // TODO(nicholss): If iOS supports pairing, pull the stored data and |
| 79 // insert it here. |
| 80 info.pairing_id = ""; |
| 81 info.pairing_secret = ""; |
| 82 |
| 83 // TODO(nicholss): I am not sure about the following fields yet. |
| 84 // info.capabilities = |
| 85 // info.flags = |
| 86 // info.host_version = |
| 87 // info.host_os = |
| 88 // info.host_os_version = |
41 | 89 |
42 remoting::protocol::ClientAuthenticationConfig client_auth_config; | 90 remoting::protocol::ClientAuthenticationConfig client_auth_config; |
43 client_auth_config.host_id = info.host_id; | 91 client_auth_config.host_id = info.host_id; |
44 client_auth_config.pairing_client_id = info.pairing_id; | 92 client_auth_config.pairing_client_id = info.pairing_id; |
45 client_auth_config.pairing_secret = info.pairing_secret; | 93 client_auth_config.pairing_secret = info.pairing_secret; |
46 client_auth_config.fetch_secret_callback = base::BindBlockArc( | 94 client_auth_config.fetch_secret_callback = base::BindBlockArc( |
47 ^(bool pairing_supported, const remoting::protocol::SecretFetchedCallback& | 95 ^(bool pairing_supported, const remoting::protocol::SecretFetchedCallback& |
48 secret_fetched_callback) { | 96 secret_fetched_callback) { |
49 NSLog(@"TODO(nicholss): Implement the FetchSecretCallback."); | 97 _secretFetchedCallback = secret_fetched_callback; |
50 // TODO(nicholss): For now we pass back a junk number. | 98 _sessionDetails.state = SessionPinPrompt; |
51 secret_fetched_callback.Run("000000"); | 99 [[NSNotificationCenter defaultCenter] |
| 100 postNotificationName:kHostSessionStatusChanged |
| 101 object:self |
| 102 userInfo:[NSDictionary |
| 103 dictionaryWithObject:_sessionDetails |
| 104 forKey:kSessionDetails]]; |
52 }); | 105 }); |
53 | 106 |
54 // TODO(nicholss): Add audio support to iOS. | 107 // TODO(nicholss): Add audio support to iOS. |
55 base::WeakPtr<remoting::protocol::AudioStub> audioPlayer = nullptr; | 108 base::WeakPtr<remoting::protocol::AudioStub> audioPlayer = nullptr; |
56 | 109 |
57 _displayHandler = [[GlDisplayHandler alloc] init]; | 110 _displayHandler = [[GlDisplayHandler alloc] init]; |
58 | 111 |
59 _runtime->ui_task_runner()->PostTask( | 112 _runtime->ui_task_runner()->PostTask( |
60 FROM_HERE, base::BindBlockArc(^{ | 113 FROM_HERE, base::BindBlockArc(^{ |
61 _session.reset(new remoting::ChromotingSession( | 114 _session.reset(new remoting::ChromotingSession( |
62 _sessonDelegate->GetWeakPtr(), | 115 _sessonDelegate->GetWeakPtr(), |
63 [_displayHandler CreateCursorShapeStub], | 116 [_displayHandler CreateCursorShapeStub], |
64 [_displayHandler CreateVideoRenderer], audioPlayer, hostInfo, | 117 [_displayHandler CreateVideoRenderer], audioPlayer, info, |
65 client_auth_config)); | 118 client_auth_config)); |
66 _session->Connect(); | 119 _session->Connect(); |
67 })); | 120 })); |
68 } | 121 } |
69 | 122 |
| 123 #pragma mark - Eventing |
| 124 |
| 125 - (void)hostSessionPinProvided:(NSNotification*)notification { |
| 126 NSString* pin = [[notification userInfo] objectForKey:kHostSessionPin]; |
| 127 if (_secretFetchedCallback) { |
| 128 _runtime->network_task_runner()->PostTask( |
| 129 FROM_HERE, base::BindBlockArc(^{ |
| 130 _secretFetchedCallback.Run(base::SysNSStringToUTF8(pin)); |
| 131 })); |
| 132 } |
| 133 } |
| 134 |
| 135 #pragma mark - Properties |
| 136 |
| 137 - (HostInfo*)hostInfo { |
| 138 return _sessionDetails.hostInfo; |
| 139 } |
| 140 |
70 #pragma mark - ChromotingSession::Delegate | 141 #pragma mark - ChromotingSession::Delegate |
71 | 142 |
72 - (void)onConnectionState:(remoting::protocol::ConnectionToHost::State)state | 143 - (void)onConnectionState:(remoting::protocol::ConnectionToHost::State)state |
73 error:(remoting::protocol::ErrorCode)error { | 144 error:(remoting::protocol::ErrorCode)error { |
74 NSLog(@"TODO(nicholss): implement this, onConnectionState: %d %d.", state, | 145 switch (state) { |
75 error); | 146 case remoting::protocol::ConnectionToHost::INITIALIZING: |
| 147 NSLog(@"State --> INITIALIZING"); |
| 148 _sessionDetails.state = SessionInitializing; |
| 149 break; |
| 150 case remoting::protocol::ConnectionToHost::CONNECTING: |
| 151 NSLog(@"State --> CONNECTING"); |
| 152 _sessionDetails.state = SessionConnecting; |
| 153 break; |
| 154 case remoting::protocol::ConnectionToHost::AUTHENTICATED: |
| 155 NSLog(@"State --> AUTHENTICATED"); |
| 156 _sessionDetails.state = SessionAuthenticated; |
| 157 break; |
| 158 case remoting::protocol::ConnectionToHost::CONNECTED: |
| 159 NSLog(@"State --> CONNECTED"); |
| 160 _sessionDetails.state = SessionConnected; |
| 161 break; |
| 162 case remoting::protocol::ConnectionToHost::FAILED: |
| 163 NSLog(@"State --> FAILED"); |
| 164 _sessionDetails.state = SessionFailed; |
| 165 break; |
| 166 case remoting::protocol::ConnectionToHost::CLOSED: |
| 167 NSLog(@"State --> CLOSED"); |
| 168 _sessionDetails.state = SessionClosed; |
| 169 break; |
| 170 default: |
| 171 LOG(ERROR) << "onConnectionState, unknown state: " << state; |
| 172 } |
| 173 |
| 174 // TODO(nicholss): Send along the error code when we know what to do about it. |
| 175 [[NSNotificationCenter defaultCenter] |
| 176 postNotificationName:kHostSessionStatusChanged |
| 177 object:self |
| 178 userInfo:[NSDictionary dictionaryWithObject:_sessionDetails |
| 179 forKey:kSessionDetails]]; |
76 } | 180 } |
77 | 181 |
78 - (void)commitPairingCredentialsForHost:(NSString*)host | 182 - (void)commitPairingCredentialsForHost:(NSString*)host |
79 id:(NSString*)id | 183 id:(NSString*)id |
80 secret:(NSString*)secret { | 184 secret:(NSString*)secret { |
81 NSLog(@"TODO(nicholss): implement this, commitPairingCredentialsForHost."); | 185 NSLog(@"TODO(nicholss): implement this, commitPairingCredentialsForHost."); |
82 } | 186 } |
83 | 187 |
84 - (void)fetchThirdPartyTokenForUrl:(NSString*)tokenUrl | 188 - (void)fetchThirdPartyTokenForUrl:(NSString*)tokenUrl |
85 clientId:(NSString*)clientId | 189 clientId:(NSString*)clientId |
86 scope:(NSString*)scope { | 190 scope:(NSString*)scope { |
87 NSLog(@"TODO(nicholss): implement this, fetchThirdPartyTokenForUrl."); | 191 NSLog(@"TODO(nicholss): implement this, fetchThirdPartyTokenForUrl."); |
88 } | 192 } |
89 | 193 |
90 - (void)setCapabilities:(NSString*)capabilities { | 194 - (void)setCapabilities:(NSString*)capabilities { |
91 NSLog(@"TODO(nicholss): implement this, setCapabilities."); | 195 NSLog(@"TODO(nicholss): implement this, setCapabilities."); |
92 } | 196 } |
93 | 197 |
94 - (void)handleExtensionMessageOfType:(NSString*)type | 198 - (void)handleExtensionMessageOfType:(NSString*)type |
95 message:(NSString*)message { | 199 message:(NSString*)message { |
96 NSLog(@"TODO(nicholss): implement this, handleExtensionMessageOfType %@:%@.", | 200 NSLog(@"TODO(nicholss): implement this, handleExtensionMessageOfType %@:%@.", |
97 type, message); | 201 type, message); |
98 } | 202 } |
99 | 203 |
100 @end | 204 @end |
OLD | NEW |