# Copyright (c) 2022 <NAME>. All rights reserved.
""" Example of RemoteWeb """
import time
import webbrowser
from threading import Thread
from http.server import HTTPServer, SimpleHTTPRequestHandler

from remoteweb import RemoteWebServer, RemoteWebClient


def run_remoteweb_server() -> None:
    """Run RemoteWebServer Application"""
    server = RemoteWebServer()
    server.run()


def run_remoteweb_client() -> None:
    """Run RemoteWebClient Application"""
    client = RemoteWebClient("http://127.0.0.1:8000", "ws://127.0.0.1:6171/remoteweb/ws")
    client.run()


server_thread = Thread(target=run_remoteweb_server, daemon=True)
client_thread = Thread(target=run_remoteweb_client, daemon=True)

with HTTPServer(("127.0.0.1", 8000), SimpleHTTPRequestHandler) as server:
    server_thread.start()
    time.sleep(3)  # wait RemoteWebServer starts
    client_thread.start()
    webbrowser.open("http://localhost:8000")  # original http server
    webbrowser.open("http://localhost:6171")  # via RemoteWeb application
    server.serve_forever()

# Copyright (c) 2022 <NAME>. All rights reserved.
""" Example of RemoteWeb """
import time
import webbrowser
from threading import Thread
from http.server import HTTPServer, SimpleHTTPRequestHandler

from remoteweb import RemoteWebServer, RemoteWebClient


def run_remoteweb_server() -> None:
    """Run RemoteWebServer Application"""
    server = RemoteWebServer()
    server.run()


def run_remoteweb_client() -> None:
    """Run RemoteWebClient Application"""
    client = RemoteWebClient("http://127.0.0.1:8000", "ws://127.0.0.1:6171/remoteweb/ws")
    client.run()


server_thread = Thread(target=run_remoteweb_server, daemon=True)
client_thread = Thread(target=run_remoteweb_client, daemon=True)

with HTTPServer(("127.0.0.1", 8000), SimpleHTTPRequestHandler) as server:
    server_thread.start()
    time.sleep(3)  # wait RemoteWebServer starts
    client_thread.start()
    webbrowser.open("http://localhost:8000")  # original http server
    webbrowser.open("http://localhost:6171")  # via RemoteWeb application
    server.serve_forever()

# Copyright (c) 2022 <NAME>. All rights reserved. Example of RemoteWeb Run RemoteWebServer Application Run RemoteWebClient Application # wait RemoteWebServer starts # original http server # via RemoteWeb application