feat(ui refresh): Added an optionnal callback recv message function
docs(imgs): Added 2 video capture for perenity
This commit is contained in:
parent
930983b06d
commit
414cf1fc73
BIN
img/2users.mp4
Normal file
BIN
img/2users.mp4
Normal file
Binary file not shown.
BIN
img/4users.gif
Normal file
BIN
img/4users.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 MiB |
@ -91,9 +91,8 @@ class Session():
|
|||||||
self.is_running = False
|
self.is_running = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Client():
|
class Client():
|
||||||
def __init__(self, context=zmq.Context(), id="default"):
|
def __init__(self, context=zmq.Context(), id="default", recv_callback=None):
|
||||||
|
|
||||||
self.context = context
|
self.context = context
|
||||||
self.pull_sock = None
|
self.pull_sock = None
|
||||||
@ -101,6 +100,7 @@ class Client():
|
|||||||
self.poller = None
|
self.poller = None
|
||||||
|
|
||||||
self.id = id
|
self.id = id
|
||||||
|
self.recv_callback = recv_callback
|
||||||
self.bind_ports()
|
self.bind_ports()
|
||||||
# Main client loop registration
|
# Main client loop registration
|
||||||
self.task = asyncio.ensure_future(self.main())
|
self.task = asyncio.ensure_future(self.main())
|
||||||
@ -139,9 +139,14 @@ class Client():
|
|||||||
|
|
||||||
if self.pull_sock in socks:
|
if self.pull_sock in socks:
|
||||||
message = self.pull_sock.recv_multipart(zmq.NOBLOCK)
|
message = self.pull_sock.recv_multipart(zmq.NOBLOCK)
|
||||||
logger.info("{}:{}".format(message[0].decode('ascii'), umsgpack.unpackb(message[1])))
|
logger.info("{}:{}".format(message[0].decode(
|
||||||
|
'ascii'), umsgpack.unpackb(message[1])))
|
||||||
# Store message
|
# Store message
|
||||||
self.store.append([message[0].decode('ascii'), umsgpack.unpackb(message[1])])
|
self.store.append(
|
||||||
|
[message[0].decode('ascii'), umsgpack.unpackb(message[1])])
|
||||||
|
|
||||||
|
if self.recv_callback:
|
||||||
|
self.recv_callback()
|
||||||
|
|
||||||
def send_msg(self, msg):
|
def send_msg(self, msg):
|
||||||
self.push_sock.send(umsgpack.packb(msg))
|
self.push_sock.send(umsgpack.packb(msg))
|
||||||
|
@ -91,7 +91,10 @@ class close(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
# CLIENT-SERVER
|
# CLIENT-SERVER
|
||||||
|
def refresh_window():
|
||||||
|
import bpy
|
||||||
|
|
||||||
|
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
||||||
|
|
||||||
class session_join(bpy.types.Operator):
|
class session_join(bpy.types.Operator):
|
||||||
bl_idname = "session.join"
|
bl_idname = "session.join"
|
||||||
@ -106,7 +109,8 @@ class session_join(bpy.types.Operator):
|
|||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
global client
|
global client
|
||||||
|
|
||||||
client = net_components.Client()
|
username = str(context.scene.session_settings.username)
|
||||||
|
client = net_components.Client(id=username ,recv_callback=refresh_window)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
bpy.ops.asyncio.loop()
|
bpy.ops.asyncio.loop()
|
||||||
@ -150,7 +154,7 @@ class session_create(bpy.types.Operator):
|
|||||||
username = str(context.scene.session_settings.username)
|
username = str(context.scene.session_settings.username)
|
||||||
|
|
||||||
server = net_components.Server()
|
server = net_components.Server()
|
||||||
client = net_components.Client(id=username)
|
client = net_components.Client(id=username,recv_callback=refresh_window)
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ class SessionPanel(bpy.types.Panel):
|
|||||||
area_msg.label(text="{}:{}".format(id,msg))
|
area_msg.label(text="{}:{}".format(id,msg))
|
||||||
else:
|
else:
|
||||||
area_msg.label(text="Empty")
|
area_msg.label(text="Empty")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(scene.session_settings,"username",text="")
|
row.prop(scene.session_settings,"username",text="")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user