Skip to content

Commit

Permalink
Logging & Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lcb01a committed Aug 12, 2024
1 parent c73522b commit c66c443
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 44 deletions.
19 changes: 10 additions & 9 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ 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,
"callback_port": 19001,
"interaction_timeout": 2,
"max_call_time": 0,
"max_ring_time": 10,
"log_verbose": False,
"phonebook": [
["Lobby", "5229"],
["Lobby2", "5230"],
Expand All @@ -35,6 +35,7 @@ def __init__(self):
],
"phonemenu": {
"init_screen": "screensaver",
"transition_popup": 3,
"dialogs": {
"call_incoming":{
"dialog": 1,
Expand Down Expand Up @@ -70,7 +71,7 @@ def __init__(self):
"screens": {
"screensaver": {
"screenid": 0,
"loading_transition": True,
"transition": True,
"selectors": {
"selector1": False,
"selector2": False,
Expand All @@ -84,7 +85,7 @@ def __init__(self):
},
"main": {
"screenid": 1,
"loading_transition": True,
"transition": True,
"selectors": {
"selector1": True,
"selector2": False,
Expand All @@ -100,7 +101,7 @@ def __init__(self):
},
"phonebook": {
"screenid": 2,
"loading_transition": True,
"transition": True,
"selectors": {
"selector1": True,
"selector2": True,
Expand All @@ -116,7 +117,7 @@ def __init__(self):
},
"conference": {
"screenid": 3,
"loading_transition": True,
"transition": True,
"selectors": {
"selector1": False,
"selector2": False,
Expand All @@ -130,7 +131,7 @@ def __init__(self):
},
"credits": {
"screenid": 4,
"loading_transition": True,
"transition": True,
"selectors": {
"selector1": False,
"selector2": False,
Expand All @@ -143,7 +144,7 @@ def __init__(self):
},
"secretmenu": {
"screenid": 5,
"loading_transition": True,
"transition": True,
"selectors": {
"selector1": False,
"selector2": False,
Expand Down
10 changes: 5 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -51,7 +51,7 @@ def start_callbackapi():
app = Flask(__name__)
app.logger.setLevel(logging.ERROR)
api = Api(app=app)
api.add_resource(ReceiveCallback, '/<string:command>/<string:caller_id>')
api.add_resource(ReceiveCallback, '/<string:command>/<string:caller>')

server_udp_port = cfg.get_by_key("server_port")

Expand Down
39 changes: 28 additions & 11 deletions menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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"])
Expand All @@ -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"])
Expand All @@ -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(
Expand All @@ -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]:
Expand Down Expand Up @@ -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

Expand Down
13 changes: 8 additions & 5 deletions microsip.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from config import Config
from gui import Gui
import params
import subprocess

class MicroSIP:
Expand All @@ -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):
Expand All @@ -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):
Expand Down
Empty file removed osc.py
Empty file.
9 changes: 0 additions & 9 deletions params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 4 additions & 5 deletions vrphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit c66c443

Please sign in to comment.