1# Copyright 2017 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import logging 6 7DEFAULT_TIMEOUT = 30 8TELEMETRY_API = 'hrTelemetryApi' 9 10 11class CfmMeetingsAPI(object): 12 """Utility class for interacting with CfMs.""" 13 14 def __init__(self, webview_context): 15 self._webview_context = webview_context 16 17 def _execute_telemetry_command(self, command): 18 self._webview_context.ExecuteJavaScript( 19 'window.%s.%s' % (TELEMETRY_API, command)) 20 21 def _evaluate_telemetry_command(self, command): 22 return self._webview_context.EvaluateJavaScript( 23 'window.%s.%s' % (TELEMETRY_API, command)) 24 25 # UI commands/functions 26 def wait_for_meetings_landing_page(self): 27 """Waits for the landing page screen.""" 28 self._webview_context.WaitForJavaScriptCondition( 29 'window.hasOwnProperty("%s") ' 30 '&& !window.%s.isInMeeting()' % (TELEMETRY_API, TELEMETRY_API), 31 timeout=DEFAULT_TIMEOUT) 32 logging.info('Reached meetings landing page.') 33 34 def wait_for_meetings_in_call_page(self): 35 """Waits for the in-call page to launch.""" 36 self._webview_context.WaitForJavaScriptCondition( 37 'window.hasOwnProperty("%s") ' 38 '&& window.%s.isInMeeting()' % (TELEMETRY_API, TELEMETRY_API), 39 timeout=DEFAULT_TIMEOUT) 40 logging.info('Reached meetings in-call page.') 41 42 def wait_for_telemetry_commands(self): 43 """Wait for hotrod app to load and telemetry commands to be available. 44 """ 45 raise NotImplementedError 46 47 def wait_for_oobe_start_page(self): 48 """Wait for oobe start screen to launch.""" 49 raise NotImplementedError 50 51 def skip_oobe_screen(self): 52 """Skip Chromebox for Meetings oobe screen.""" 53 raise NotImplementedError 54 55 def is_oobe_start_page(self): 56 """Check if device is on CFM oobe start screen.""" 57 raise NotImplementedError 58 59 # Hangouts commands/functions 60 def start_meeting_session(self): 61 """Start a meeting.""" 62 if self.is_in_meeting_session(): 63 self.end_meeting_session() 64 65 self._execute_telemetry_command('startMeeting()') 66 self.wait_for_meetings_in_call_page() 67 logging.info('Started meeting session.') 68 69 def join_meeting_session(self, meeting_name): 70 """Joins a meeting. 71 72 @param meeting_name: Name of the meeting session. 73 """ 74 if self.is_in_meeting_session(): 75 self.end_meeting_session() 76 77 self._execute_telemetry_command('joinMeeting("%s")' % meeting_name) 78 self.wait_for_meetings_in_call_page() 79 logging.info('Started meeting session: %s', meeting_name) 80 81 def end_meeting_session(self): 82 """End current meeting session.""" 83 self._execute_telemetry_command('endCall()') 84 self.wait_for_meetings_landing_page() 85 logging.info('Ended meeting session.') 86 87 def is_in_meeting_session(self): 88 """Check if device is in meeting session.""" 89 if self._evaluate_telemetry_command('isInMeeting()'): 90 logging.info('Is in meeting session.') 91 return True 92 logging.info('Is not in meeting session.') 93 return False 94 95 def start_new_hangout_session(self, hangout_name): 96 """Start a new hangout session. 97 98 @param hangout_name: Name of the hangout session. 99 """ 100 raise NotImplementedError 101 102 def end_hangout_session(self): 103 """End current hangout session.""" 104 raise NotImplementedError 105 106 def is_in_hangout_session(self): 107 """Check if device is in hangout session.""" 108 raise NotImplementedError 109 110 def is_ready_to_start_hangout_session(self): 111 """Check if device is ready to start a new hangout session.""" 112 raise NotImplementedError 113 114 # Diagnostics commands/functions 115 def is_diagnostic_run_in_progress(self): 116 """Check if hotrod diagnostics is running.""" 117 raise NotImplementedError 118 119 def wait_for_diagnostic_run_to_complete(self): 120 """Wait for hotrod diagnostics to complete.""" 121 raise NotImplementedError 122 123 def run_diagnostics(self): 124 """Run hotrod diagnostics.""" 125 raise NotImplementedError 126 127 def get_last_diagnostics_results(self): 128 """Get latest hotrod diagnostics results.""" 129 raise NotImplementedError 130 131 # Mic audio commands/functions 132 def is_mic_muted(self): 133 """Check if mic is muted.""" 134 if self._evaluate_telemetry_command('isMicMuted()'): 135 logging.info('Mic is muted.') 136 return True 137 logging.info('Mic is not muted.') 138 return False 139 140 def mute_mic(self): 141 """Local mic mute from toolbar.""" 142 self._execute_telemetry_command('setMicMuted(true)') 143 logging.info('Locally muted mic.') 144 145 def unmute_mic(self): 146 """Local mic unmute from toolbar.""" 147 self._execute_telemetry_command('setMicMuted(false)') 148 logging.info('Locally unmuted mic.') 149 150 def get_mic_devices(self): 151 """Get all mic devices detected by hotrod.""" 152 return self._evaluate_telemetry_command('getAudioInDevices()') 153 154 def get_preferred_mic(self): 155 """Get preferred microphone for hotrod.""" 156 return self._evaluate_telemetry_command('getPreferredAudioInDevice()') 157 158 def set_preferred_mic(self, mic_name): 159 """Set preferred mic for hotrod. 160 161 @param mic_name: String with mic name. 162 """ 163 self._execute_telemetry_command('setPreferredAudioInDevice(%s)' 164 % mic_name) 165 logging.info('Setting preferred mic to %s.', mic_name) 166 167 def remote_mute_mic(self): 168 """Remote mic mute request from cPanel.""" 169 raise NotImplementedError 170 171 def remote_unmute_mic(self): 172 """Remote mic unmute request from cPanel.""" 173 raise NotImplementedError 174 175 # Speaker commands/functions 176 def get_speaker_devices(self): 177 """Get all speaker devices detected by hotrod.""" 178 return self._evaluate_telemetry_command('getAudioOutDevices()') 179 180 def get_preferred_speaker(self): 181 """Get speaker preferred for hotrod.""" 182 return self._evaluate_telemetry_command('getPreferredAudioOutDevice()') 183 184 def set_preferred_speaker(self, speaker_name): 185 """Set preferred speaker for hotrod. 186 187 @param speaker_name: String with speaker name. 188 """ 189 self._execute_telemetry_command('setPreferredAudioOutDevice(%s)' 190 % speaker_name) 191 logging.info('Set preferred speaker to %s.', speaker_name) 192 193 def set_speaker_volume(self, volume_level): 194 """Set speaker volume. 195 196 @param volume_level: Number value ranging from 0-100 to set volume to. 197 """ 198 self._execute_telemetry_command('setAudioOutVolume(%d)' % volume_level) 199 logging.info('Set speaker volume to %d', volume_level) 200 201 def get_speaker_volume(self): 202 """Get current speaker volume.""" 203 return self._evaluate_telemetry_command('getAudioOutVolume()') 204 205 def play_test_sound(self): 206 """Play test sound.""" 207 raise NotImplementedError 208 209 # Camera commands/functions 210 def get_camera_devices(self): 211 """Get all camera devices detected by hotrod. 212 213 @return List of camera devices. 214 """ 215 return self._evaluate_telemetry_command('getVideoInDevices()') 216 217 def get_preferred_camera(self): 218 """Get camera preferred for hotrod.""" 219 return self._evaluate_telemetry_command('getPreferredVideoInDevice()') 220 221 def set_preferred_camera(self, camera_name): 222 """Set preferred camera for hotrod. 223 224 @param camera_name: String with camera name. 225 """ 226 self._execute_telemetry_command('setPreferredVideoInDevice(%s)' 227 % camera_name) 228 logging.info('Set preferred camera to %s.', camera_name) 229 230 def is_camera_muted(self): 231 """Check if camera is muted (turned off).""" 232 if self._evaluate_telemetry_command('isCameraMuted()'): 233 logging.info('Camera is muted.') 234 return True 235 logging.info('Camera is not muted.') 236 return False 237 238 def mute_camera(self): 239 """Mute (turn off) camera.""" 240 self._execute_telemetry_command('setCameraMuted(true)') 241 logging.info('Camera muted.') 242 243 def unmute_camera(self): 244 """Unmute (turn on) camera.""" 245 self._execute_telemetry_command('setCameraMuted(false)') 246 logging.info('Camera unmuted.') 247