This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
client.py
63 lines (45 loc) · 1.58 KB
/
client.py
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
import sys
import logging
import argparse
import asyncio
from xbox.webapi.authentication.manager import AuthenticationManager
from xbox.sg.console import Console
from xbox.sg.enum import ConnectionState
from xbox.nano.manager import NanoManager
from xbox.nano.render.client import SDLClient
def on_gamestream_error(error_msg) -> None:
print(f'!!! Gamestream error occured: {error_msg}')
sys.exit(1)
async def async_main():
parser = argparse.ArgumentParser(description="Basic smartglass NANO client")
parser.add_argument('--address', '-a',
help="IP address of console")
args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG)
discovered = await Console.discover(timeout=1, addr=args.address)
if len(discovered):
console = discovered[0]
console.add_manager(NanoManager)
console.nano.on_gamestream_error += on_gamestream_error
await console.connect("", "")
if console.connection_state != ConnectionState.Connected:
print("Connection failed")
sys.exit(1)
await console.wait(1)
await console.nano.start_stream()
await console.wait(2)
client = SDLClient(1280, 720)
await console.nano.start_gamestream(client)
try:
while True:
await console.wait(5.0)
except KeyboardInterrupt:
pass
else:
print("No consoles discovered")
sys.exit(1)
def main():
loop = asyncio.get_event_loop()
loop.run_until_complete(async_main())
if __name__ == "__main__":
main()