From c66c443bdfec40740a4ae743477992d30a1467f2 Mon Sep 17 00:00:00 2001 From: Cyrus Date: Mon, 12 Aug 2024 20:09:13 +0200 Subject: [PATCH] Logging & Cleanup --- config.py | 19 ++++++++++--------- main.py | 10 +++++----- menu.py | 39 ++++++++++++++++++++++++++++----------- microsip.py | 13 ++++++++----- osc.py | 0 params.py | 9 --------- vrphone.py | 9 ++++----- 7 files changed, 55 insertions(+), 44 deletions(-) delete mode 100644 osc.py diff --git a/config.py b/config.py index d0b925b..7322f31 100644 --- a/config.py +++ b/config.py @@ -12,14 +12,13 @@ def merge_dicts(dict1, dict2): dict1[k] = dict2[k] return dict1 - class Config: def __init__(self): appdata_path = os.environ.get('LOCALAPPDATA') - microsip_binary = os.path.join(appdata_path, "MicroSIP\microsip.exe") + microsip_binary = os.path.join(appdata_path, "MicroSIP\\microsip.exe") self.APP_NAME = 'VRChatVRPhone' self.default_config = { - "use_oscquery": True, + "use_oscquery": False, "server_port": 9001, "microsip_binary": microsip_binary, "call_autoanswer": False, @@ -27,6 +26,7 @@ def __init__(self): "interaction_timeout": 2, "max_call_time": 0, "max_ring_time": 10, + "log_verbose": False, "phonebook": [ ["Lobby", "5229"], ["Lobby2", "5230"], @@ -35,6 +35,7 @@ def __init__(self): ], "phonemenu": { "init_screen": "screensaver", + "transition_popup": 3, "dialogs": { "call_incoming":{ "dialog": 1, @@ -70,7 +71,7 @@ def __init__(self): "screens": { "screensaver": { "screenid": 0, - "loading_transition": True, + "transition": True, "selectors": { "selector1": False, "selector2": False, @@ -84,7 +85,7 @@ def __init__(self): }, "main": { "screenid": 1, - "loading_transition": True, + "transition": True, "selectors": { "selector1": True, "selector2": False, @@ -100,7 +101,7 @@ def __init__(self): }, "phonebook": { "screenid": 2, - "loading_transition": True, + "transition": True, "selectors": { "selector1": True, "selector2": True, @@ -116,7 +117,7 @@ def __init__(self): }, "conference": { "screenid": 3, - "loading_transition": True, + "transition": True, "selectors": { "selector1": False, "selector2": False, @@ -130,7 +131,7 @@ def __init__(self): }, "credits": { "screenid": 4, - "loading_transition": True, + "transition": True, "selectors": { "selector1": False, "selector2": False, @@ -143,7 +144,7 @@ def __init__(self): }, "secretmenu": { "screenid": 5, - "loading_transition": True, + "transition": True, "selectors": { "selector1": False, "selector2": False, diff --git a/main.py b/main.py index c30446f..2d67ba5 100644 --- a/main.py +++ b/main.py @@ -16,12 +16,12 @@ class ReceiveCallback(Resource): - def get(self, command, caller_id): - vrphone.microsip_callback(microsip_cmd=command, caller_id=caller_id) + def get(self, command, caller): + vrphone.microsip_callback(command=command, caller=caller) return - def put(self, command, caller_id): - vrphone.microsip_callback(microsip_cmd=command, caller_id=caller_id) + def put(self, command, caller): + vrphone.microsip_callback(command=command, caller=caller) return def start_oscquery(server_udp_port, server_tcp_port): @@ -51,7 +51,7 @@ def start_callbackapi(): app = Flask(__name__) app.logger.setLevel(logging.ERROR) api = Api(app=app) - api.add_resource(ReceiveCallback, '//') + api.add_resource(ReceiveCallback, '//') server_udp_port = cfg.get_by_key("server_port") diff --git a/menu.py b/menu.py index dc5edaa..f5e01ba 100644 --- a/menu.py +++ b/menu.py @@ -13,7 +13,7 @@ def __init__(self, config: Config, gui: Gui, osc_client, microsip: MicroSIP): self.active_screen: str = "" self.active_dialog: str = "" self.active_mode = 0 - self.verbose = True + self.call_start_time: float = float() self.osc_integer_parameters: dict[str, str] = { "screen": params.show_screen, "dialog": params.show_dialog, @@ -26,17 +26,17 @@ def __init__(self, config: Config, gui: Gui, osc_client, microsip: MicroSIP): "selector4": params.show_selection4 } self.microsip_dialog_mapping: dict[str, tuple] = { - "cmdCallEnd": ("call_ended", params.call_ended), - "cmdIncomingCall": ("call_incoming", params.call_incoming), - "cmdOutgoingCall": ("call_outgoing", params.call_outgoing), - "cmdCallStart": ("call_started", params.call_started), + "cmdCallEnd": "call_ended", + "cmdIncomingCall": "call_incoming", + "cmdOutgoingCall": "call_outgoing", + "cmdCallStart": "call_started", } def _initmenu(self): screen = self.config.get_by_key("phonemenu")["init_screen"] self._switch_screen(screen) self._reset_dialogs() - self.gui.print_terminal("Menu initialized, starting screen: {}".format(screen)) + self.gui.print_terminal("log_verbose: Ingame menu initialized") if self.config.get_by_key("log_verbose") else None def _reset_dialogs(self): self.active_mode = 0 @@ -49,6 +49,12 @@ def _reset_dialogs(self): ) def _switch_screen(self, screen): + self.gui.print_terminal("log_verbose: Switching screen to: {}".format(screen)) if self.config.get_by_key("log_verbose") else None + if self.config.get_by_key("phonemenu")["screens"][screen]["transition"]: + self.active_mode = 2 + self.osc_client.send_message(self.osc_integer_parameters.get("popup"), self.config.get_by_key("phonemenu")["transition_popup"]) + time.sleep(self.config.get_by_key("interaction_timeout")) + self.osc_client.send_message(self.osc_integer_parameters.get("popup"), 0) self.active_screen = screen self.active_mode = 0 self.osc_client.send_message(self.osc_integer_parameters.get("screen"), self.config.get_by_key("phonemenu")["screens"][screen]["screenid"]) @@ -59,6 +65,7 @@ def _switch_screen(self, screen): ) def _show_dialog(self, dialog): + self.gui.print_terminal("log_verbose: Showing dialog: {}".format(dialog)) if self.config.get_by_key("log_verbose") else None self.active_dialog = dialog self.active_mode = 1 self.osc_client.send_message(self.osc_integer_parameters.get("dialog"), self.config.get_by_key("phonemenu")["dialogs"][dialog]["dialog"]) @@ -70,6 +77,7 @@ def _show_dialog(self, dialog): ) def _redraw(self): + self.gui.print_terminal("log_verbose: Redrawing screen") if self.config.get_by_key("log_verbose") else None self.osc_client.send_message(self.osc_integer_parameters.get("screen"), self.config.get_by_key("phonemenu")["screens"][self.active_screen]["screenid"]) for selector in self.config.get_by_key("phonemenu")["screens"][self.active_screen]["selectors"]: self.osc_client.send_message( @@ -79,6 +87,9 @@ def _redraw(self): if self.active_mode == 1: self.osc_client.send_message(self.osc_integer_parameters.get("dialog"), self.config.get_by_key("phonemenu")["dialogs"][self.active_dialog]["dialog"]) self.osc_client.send_message(self.osc_integer_parameters.get("popup"), self.config.get_by_key("phonemenu")["dialogs"][self.active_dialog]["popup"]) + if self.active_mode == 2: + self.osc_client.send_message(self.osc_integer_parameters.get("dialog"), 0) + self.osc_client.send_message(self.osc_integer_parameters.get("popup"), self.config.get_by_key("phonemenu")["transition_popup"]) def _handle_choices(self, choice): match choice[0]: @@ -113,15 +124,21 @@ def handle_button_input(self, button): def handle_callback_input(self, command, caller): match command: case "cmdCallEnd" | "cmdCallBusy": - self._show_dialog(self.microsip_dialog_mapping.get("cmdCallEnd")[0]) - time.sleep(2) + self.gui.print_terminal("Call with #{} ended after {} seconds".format(caller,int(time.time() - self.call_start_time))) + self._show_dialog(self.microsip_dialog_mapping.get("cmdCallEnd")) + time.sleep(self.config.get_by_key("interaction_timeout")) self._reset_dialogs() case "cmdOutgoingCall": - self._show_dialog(self.microsip_dialog_mapping.get("cmdOutgoingCall")[0]) + self.call_start_time = time.time() + self.gui.print_terminal("Outgoing call to #{}".format(caller)) + self._show_dialog(self.microsip_dialog_mapping.get("cmdOutgoingCall")) case "cmdIncomingCall": - self._show_dialog(self.microsip_dialog_mapping.get("cmdIncomingCall")[0]) + self.call_start_time = time.time() + self.gui.print_terminal("Incoming call from #{}".format(caller)) + self._show_dialog(self.microsip_dialog_mapping.get("cmdIncomingCall")) case "cmdCallStart": - self._show_dialog(self.microsip_dialog_mapping.get("cmdCallStart")[0]) + self.gui.print_terminal("Call with #{} started".format(caller)) + self._show_dialog(self.microsip_dialog_mapping.get("cmdCallStart")) case _: return diff --git a/microsip.py b/microsip.py index 80e035c..82e8152 100644 --- a/microsip.py +++ b/microsip.py @@ -1,6 +1,5 @@ from config import Config from gui import Gui -import params import subprocess class MicroSIP: @@ -9,21 +8,28 @@ def __init__(self, config: Config, gui: Gui): self.gui = gui def run_phone_command(self, command, args = None): - self.gui.print_terminal("Microsip command: {} args: {}".format(command, args)) + self.gui.print_terminal("Microsip: Running command: {} args: {}".format(command, args)) if self.config.get_by_key("log_verbose") else None match command: case "answer": + self.gui.print_terminal("Microsip: Answering call") self.call_answer() case "hangup": + self.gui.print_terminal("Microsip: Hangup call") self.call_hangup() case "hangupcalling": + self.gui.print_terminal("Microsip: Hangup outgoing call") self.call_hangup(command) case "hangupincoming": + self.gui.print_terminal("Microsip: Hangup incoming call") self.call_hangup(command) case "phonebook": + self.gui.print_terminal("Microsip: Call phonebook entry #{}".format(args+1)) self.call_phonebook_entry(args) case "dtmf": + self.gui.print_terminal("Microsip: Send DTMF sequence: {}".format(args)) self.send_dtmf(args) case "transfer": + self.gui.print_terminal("Microsip: Transfer call to: {}".format(args)) self.call_transfer(args) def call_answer(self): @@ -45,9 +51,6 @@ def call_transfer(self, number): def call_phonebook_entry(self, entry): for p, (name, number) in enumerate(self.config.get_by_key("phonebook")): if p == entry: - self.gui.print_terminal( - "Call phone book entry #{} {} {}".format(p+1, name, number) - ) return self.execute_microsip_command(number) def execute_microsip_command(self, parameter: str): diff --git a/osc.py b/osc.py deleted file mode 100644 index e69de29..0000000 diff --git a/params.py b/params.py index 417a215..74536db 100644 --- a/params.py +++ b/params.py @@ -16,15 +16,6 @@ no_button = "/avatar/parameters/vrphone_no_button" center_button = "/avatar/parameters/vrphone_center_button" -#Outputs to use as indicators -call_started = "/avatar/parameters/vrphone_call_started" -call_ended = "/avatar/parameters/vrphone_call_ended" -call_incoming = "/avatar/parameters/vrphone_call_incoming" -call_outgoing = "/avatar/parameters/vrphone_call_outgoing" -call_answered = "/avatar/parameters/vrphone_call_answered" -call_ring = "/avatar/parameters/vrphone_call_ring" -call_busy = "/avatar/parameters/vrphone_call_busy" - #Shape Key Menu Control show_screen = "/avatar/parameters/ActiveScreen" show_dialog = "/avatar/parameters/ActiveDialog" diff --git a/vrphone.py b/vrphone.py index 9141788..496c2ce 100644 --- a/vrphone.py +++ b/vrphone.py @@ -18,7 +18,6 @@ def __init__(self, config: Config, gui: Gui, osc_client): self.input_queue: set = set() self.last_interactions: dict = dict() self.is_paused = False - self.verbose = False self.avatar_change_input = params.avatar_change self.osc_bool_inputs: dict[str, tuple] = { params.receiver_button: ("interaction", "answer", None), @@ -61,7 +60,7 @@ def _input_worker(self): self.input_queue.discard(address) except RuntimeError: pass - time.sleep(.05) + time.sleep(.025) def osc_collision(self, address: str, *args): if address == self.avatar_change_input: @@ -80,14 +79,14 @@ def osc_collision(self, address: str, *args): self.input_queue.add(address) self.last_interactions[address] = time.time() - def microsip_callback(self, microsip_cmd: str, caller_id: str): - self.menu.handle_callback_input(microsip_cmd, caller_id) + def microsip_callback(self, command: str, caller: str): + self.menu.handle_callback_input(command, caller) def map_parameters(self, dispatcher: dispatcher.Dispatcher): dispatcher.set_default_handler(self.osc_collision) def avatar_change(self): - self.gui.print_terminal("Avatar change, redrawing menu") + self.gui.print_terminal("Avatar change detected") self.menu._redraw() def run(self):