Repository navigation
Expand file tree
/
Copy pathxapi_selfview.py
More file actions
167 lines (138 loc) · 6.11 KB
/
Copy pathxapi_selfview.py
File metadata and controls
167 lines (138 loc) · 6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env python3
# Copyright (C) 2026 Frederick W. Nielsen
#
# This file is part of xAPI tools.
#
# xAPI tools is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# xAPI tools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with xAPI tools. If not, see <https://www.gnu.org/licenses/>.
"""
xapi_selfview.py
Control the camera self-view on a Cisco RoomOS codec.
Actions:
on-fullscreen - show self-view in full-screen mode
on-thumbnail - show self-view as a PiP thumbnail
off - hide self-view
xCommand reference:
xCommand Video Selfview Set Mode: On FullscreenMode: On
xCommand Video Selfview Set Mode: On FullscreenMode: Off
xCommand Video Selfview Set Mode: Off
Modes:
local - SSH into device and run xCommand
cloud - Webex Cloud xAPI REST
Deps:
pip install paramiko requests pyyaml
"""
from __future__ import annotations
import argparse
import getpass
import json
import sys
from typing import Any, Dict
from xapi_common import resolve_device_id, resolve_token, ssh_run_xcommand, xapi_command
# ------------------------------------------------------------------
# xCommand builders (local SSH)
# ------------------------------------------------------------------
def build_selfview_xcommand(action: str) -> str:
if action == "on-fullscreen":
return "xCommand Video Selfview Set Mode: On FullscreenMode: On"
elif action == "on-thumbnail":
return "xCommand Video Selfview Set Mode: On FullscreenMode: Off"
else: # off
return "xCommand Video Selfview Set Mode: Off"
# ------------------------------------------------------------------
# Cloud mode: Webex xAPI REST
# ------------------------------------------------------------------
def cloud_selfview(device_id: str, token: str, action: str,
base_url: str, timeout: int) -> Dict[str, Any]:
if action == "on-fullscreen":
arguments = {"Mode": "On", "FullscreenMode": "On"}
elif action == "on-thumbnail":
arguments = {"Mode": "On", "FullscreenMode": "Off"}
else: # off
arguments = {"Mode": "Off"}
return xapi_command("Video.Selfview.Set", device_id, token, arguments, base_url, timeout)
# ------------------------------------------------------------------
# CLI
# ------------------------------------------------------------------
def main() -> int:
"""control camera self-view on a RoomOS codec (local SSH or cloud xAPI)"""
ap = argparse.ArgumentParser(
description="Control camera self-view on a RoomOS codec "
"via local SSH or Webex Cloud xAPI.",
)
sub = ap.add_subparsers(dest="mode", required=True)
# ---- local subparser ----
ap_local = sub.add_parser("local", help="Control self-view via local SSH xAPI")
ap_local.add_argument("--host", required=True, help="Codec IP/hostname")
ap_local.add_argument("-P", "--port", type=int, default=22, help="SSH port (default: 22)")
ap_local.add_argument("-u", "--username", required=True, help="SSH username")
ap_local.add_argument("-p", "--password", help="SSH password (omit to prompt)")
ap_local.add_argument("-k", "--key", dest="key_path", help="SSH private key path (optional)")
ap_local.add_argument("--timeout", type=int, default=10, help="SSH timeout seconds (default: 10)")
# ---- cloud subparser ----
ap_cloud = sub.add_parser("cloud", help="Control self-view via Webex Cloud xAPI REST")
ap_cloud.add_argument("--device-id", help="Webex deviceId of the codec (or set XAPI_DEVICE_ID)")
ap_cloud.add_argument("--token", help="Webex access token (omit to prompt)")
ap_cloud.add_argument("--base-url", default="https://webexapis.com", help="Webex API base URL")
ap_cloud.add_argument("--timeout", type=int, default=15, help="HTTP timeout seconds (default: 15)")
ap_cloud.add_argument("--json", action="store_true", help="Print the raw JSON response instead of a summary")
# ---- shared action argument ----
for p in (ap_local, ap_cloud):
p.add_argument("action", choices=["on-fullscreen", "on-thumbnail", "off"],
help="Self-view action: on-fullscreen, on-thumbnail, or off")
args = ap.parse_args()
try:
# ---- Local mode ----
if args.mode == "local":
if not args.password and not args.key_path:
args.password = getpass.getpass("SSH Password: ")
cmd = build_selfview_xcommand(args.action)
out = ssh_run_xcommand(
host=args.host,
port=args.port,
username=args.username,
password=args.password,
key_path=args.key_path,
xcommand=cmd,
timeout=args.timeout,
)
if out:
print(out)
return 0
# ---- Cloud mode ----
if args.mode == "cloud":
token = resolve_token(args.token)
device_id = resolve_device_id(args.device_id)
if not device_id:
print("ERROR: device id required: pass --device-id or set XAPI_DEVICE_ID",
file=sys.stderr)
return 2
result = cloud_selfview(
device_id=device_id, token=token,
action=args.action,
base_url=args.base_url, timeout=args.timeout,
)
if args.json:
print(json.dumps(result, indent=2))
else:
print(f"Self-view set to {args.action}.")
return 0
return 2
except KeyboardInterrupt:
print("\nCancelled.", file=sys.stderr)
return 130
except Exception as e:
print(f"ERROR: {e}", file=sys.stderr)
return 1
if __name__ == "__main__":
raise SystemExit(main())