Starts a WebSocket server on the specified port. This method sets up the environment, locates paths, and starts the WebSocket server process. :param port: The port number on which to start the WebSocket server.
(cls, port: int)
| 109 | |
| 110 | @classmethod |
| 111 | def start_websocket_server(cls, port: int) -> None: |
| 112 | """ |
| 113 | Starts a WebSocket server on the specified port. |
| 114 | |
| 115 | This method sets up the environment, locates paths, and starts |
| 116 | the WebSocket server process. |
| 117 | |
| 118 | :param port: The port number on which to start the WebSocket server. |
| 119 | """ |
| 120 | |
| 121 | global ws_process |
| 122 | |
| 123 | webui_path = tool.Blender.get_data_dir_path("webui") |
| 124 | ws_path = (webui_path / "sioserver.py").__str__() |
| 125 | |
| 126 | py_version = sys.version_info |
| 127 | |
| 128 | bonsai_lib_path = ( |
| 129 | Path(bpy.utils.user_resource("EXTENSIONS")) |
| 130 | / ".local" |
| 131 | / "lib" |
| 132 | / f"python{py_version.major}.{py_version.minor}" |
| 133 | / "site-packages" |
| 134 | ) |
| 135 | |
| 136 | env = os.environ.copy() |
| 137 | env["BONSAI_LIB_PATH"] = str(bonsai_lib_path) |
| 138 | env["BONSAI_VERSION"] = tool.Blender.get_bonsai_version() |
| 139 | |
| 140 | ws_process = subprocess.Popen( |
| 141 | [sys.executable, ws_path, "--p", str(port), "--host", "127.0.0.1"], |
| 142 | cwd=webui_path.__str__(), |
| 143 | env=env, |
| 144 | ) |
| 145 | |
| 146 | cls.set_is_running(True) |
| 147 | |
| 148 | @classmethod |
| 149 | def connect_websocket_server(cls, port: int) -> None: |
no test coverage detected