feat: show host serving address

This commit is contained in:
Swann
2020-06-17 22:11:20 +02:00
parent 2bdbfb082b
commit 5199a810cd
4 changed files with 38 additions and 3 deletions

View File

@ -22,16 +22,18 @@ import os
import subprocess
import sys
from pathlib import Path
import socket
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
SUBPROCESS_DIR = None
rtypes = []
def module_can_be_imported(name):
try:
__import__(name)
@ -50,10 +52,23 @@ def install_package(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):
if not os.path.exists(dir):
os.makedirs(dir)
def setup(dependencies, python_path):
global PYTHON_PATH, SUBPROCESS_DIR

View File

@ -117,6 +117,9 @@ class SessionStartOperator(bpy.types.Operator):
# Host a session
if self.host:
runtime_settings.is_host = True
runtime_settings.internet_ip = environment.get_ip()
for scene in bpy.data.scenes:
client.add(scene)

View File

@ -386,12 +386,20 @@ class SessionProps(bpy.types.PropertyGroup):
description='Session password',
subtype='PASSWORD'
)
internet_ip: bpy.props.StringProperty(
name="internet ip",
default="no found",
description='Internet interface ip',
)
user_snap_running: bpy.props.BoolProperty(
default=False
)
time_snap_running: bpy.props.BoolProperty(
default=False
)
is_host: bpy.props.BoolProperty(
default=False
)
classes = (

View File

@ -109,6 +109,8 @@ class SESSION_PT_settings(bpy.types.Panel):
layout = self.layout
layout.use_property_split = True
row = layout.row()
runtime_settings = context.window_manager.session
settings = utils.get_preferences()
if hasattr(context.window_manager, 'session'):
# STATE INITIAL
@ -127,6 +129,10 @@ class SESSION_PT_settings(bpy.types.Panel):
if current_state in [STATE_ACTIVE, STATE_LOBBY]:
row.operator("session.stop", icon='QUIT', text="Exit")
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
elif current_state in [STATE_SRV_SYNC,
@ -377,7 +383,7 @@ class SESSION_UL_users(bpy.types.UIList):
ping = '-'
frame_current = '-'
scene_current = '-'
status_icon = 'DOT'
status_icon = 'BLANK1'
if session:
user = session.online_users.get(item.username)
if user:
@ -438,6 +444,9 @@ class SESSION_PT_services(bpy.types.Panel):
def poll(cls, context):
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):
layout = self.layout
online_users = context.window_manager.online_users