feat: show host serving address
This commit is contained in:
@ -22,16 +22,18 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import socket
|
||||||
|
|
||||||
THIRD_PARTY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs")
|
THIRD_PARTY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libs")
|
||||||
DEFAULT_CACHE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "cache")
|
DEFAULT_CACHE_DIR = os.path.join(
|
||||||
|
os.path.dirname(os.path.abspath(__file__)), "cache")
|
||||||
PYTHON_PATH = None
|
PYTHON_PATH = None
|
||||||
SUBPROCESS_DIR = None
|
SUBPROCESS_DIR = None
|
||||||
|
|
||||||
|
|
||||||
rtypes = []
|
rtypes = []
|
||||||
|
|
||||||
|
|
||||||
def module_can_be_imported(name):
|
def module_can_be_imported(name):
|
||||||
try:
|
try:
|
||||||
__import__(name)
|
__import__(name)
|
||||||
@ -50,10 +52,23 @@ def install_package(name):
|
|||||||
subprocess.run([str(PYTHON_PATH), "-m", "pip", "install", name])
|
subprocess.run([str(PYTHON_PATH), "-m", "pip", "install", name])
|
||||||
|
|
||||||
|
|
||||||
|
def get_ip():
|
||||||
|
"""
|
||||||
|
Retrieve the main network interface IP.
|
||||||
|
|
||||||
|
"""
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
s.connect(("8.8.8.8", 80))
|
||||||
|
ip = s.getsockname()[0]
|
||||||
|
s.close()
|
||||||
|
return ip
|
||||||
|
|
||||||
|
|
||||||
def check_dir(dir):
|
def check_dir(dir):
|
||||||
if not os.path.exists(dir):
|
if not os.path.exists(dir):
|
||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
|
|
||||||
|
|
||||||
def setup(dependencies, python_path):
|
def setup(dependencies, python_path):
|
||||||
global PYTHON_PATH, SUBPROCESS_DIR
|
global PYTHON_PATH, SUBPROCESS_DIR
|
||||||
|
|
||||||
|
@ -117,6 +117,9 @@ class SessionStartOperator(bpy.types.Operator):
|
|||||||
|
|
||||||
# Host a session
|
# Host a session
|
||||||
if self.host:
|
if self.host:
|
||||||
|
runtime_settings.is_host = True
|
||||||
|
runtime_settings.internet_ip = environment.get_ip()
|
||||||
|
|
||||||
for scene in bpy.data.scenes:
|
for scene in bpy.data.scenes:
|
||||||
client.add(scene)
|
client.add(scene)
|
||||||
|
|
||||||
|
@ -386,12 +386,20 @@ class SessionProps(bpy.types.PropertyGroup):
|
|||||||
description='Session password',
|
description='Session password',
|
||||||
subtype='PASSWORD'
|
subtype='PASSWORD'
|
||||||
)
|
)
|
||||||
|
internet_ip: bpy.props.StringProperty(
|
||||||
|
name="internet ip",
|
||||||
|
default="no found",
|
||||||
|
description='Internet interface ip',
|
||||||
|
)
|
||||||
user_snap_running: bpy.props.BoolProperty(
|
user_snap_running: bpy.props.BoolProperty(
|
||||||
default=False
|
default=False
|
||||||
)
|
)
|
||||||
time_snap_running: bpy.props.BoolProperty(
|
time_snap_running: bpy.props.BoolProperty(
|
||||||
default=False
|
default=False
|
||||||
)
|
)
|
||||||
|
is_host: bpy.props.BoolProperty(
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
|
@ -109,6 +109,8 @@ class SESSION_PT_settings(bpy.types.Panel):
|
|||||||
layout = self.layout
|
layout = self.layout
|
||||||
layout.use_property_split = True
|
layout.use_property_split = True
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
|
runtime_settings = context.window_manager.session
|
||||||
|
settings = utils.get_preferences()
|
||||||
|
|
||||||
if hasattr(context.window_manager, 'session'):
|
if hasattr(context.window_manager, 'session'):
|
||||||
# STATE INITIAL
|
# STATE INITIAL
|
||||||
@ -127,6 +129,10 @@ class SESSION_PT_settings(bpy.types.Panel):
|
|||||||
if current_state in [STATE_ACTIVE, STATE_LOBBY]:
|
if current_state in [STATE_ACTIVE, STATE_LOBBY]:
|
||||||
row.operator("session.stop", icon='QUIT', text="Exit")
|
row.operator("session.stop", icon='QUIT', text="Exit")
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
|
if runtime_settings.is_host:
|
||||||
|
row = row.box()
|
||||||
|
row.label(text=f"{runtime_settings.internet_ip}:{settings.port}", icon='INFO')
|
||||||
|
row = layout.row()
|
||||||
|
|
||||||
# CONNECTION STATE
|
# CONNECTION STATE
|
||||||
elif current_state in [STATE_SRV_SYNC,
|
elif current_state in [STATE_SRV_SYNC,
|
||||||
@ -377,7 +383,7 @@ class SESSION_UL_users(bpy.types.UIList):
|
|||||||
ping = '-'
|
ping = '-'
|
||||||
frame_current = '-'
|
frame_current = '-'
|
||||||
scene_current = '-'
|
scene_current = '-'
|
||||||
status_icon = 'DOT'
|
status_icon = 'BLANK1'
|
||||||
if session:
|
if session:
|
||||||
user = session.online_users.get(item.username)
|
user = session.online_users.get(item.username)
|
||||||
if user:
|
if user:
|
||||||
@ -438,6 +444,9 @@ class SESSION_PT_services(bpy.types.Panel):
|
|||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
return operators.client and operators.client.state['STATE'] == 2
|
return operators.client and operators.client.state['STATE'] == 2
|
||||||
|
|
||||||
|
def draw_header(self, context):
|
||||||
|
self.layout.label(text="", icon='FILE_CACHE')
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
online_users = context.window_manager.online_users
|
online_users = context.window_manager.online_users
|
||||||
|
Reference in New Issue
Block a user