feat(ui refresh): Added an optionnal callback recv message function

docs(imgs): Added 2 video capture for perenity
This commit is contained in:
Swann 2019-02-12 10:18:39 +01:00
parent 930983b06d
commit 414cf1fc73
No known key found for this signature in database
GPG Key ID: B02D0B41F8B6D2EE
5 changed files with 18 additions and 8 deletions

BIN
img/2users.mp4 Normal file

Binary file not shown.

BIN
img/4users.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

View File

@ -91,9 +91,8 @@ class Session():
self.is_running = False
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.pull_sock = None
@ -101,6 +100,7 @@ class Client():
self.poller = None
self.id = id
self.recv_callback = recv_callback
self.bind_ports()
# Main client loop registration
self.task = asyncio.ensure_future(self.main())
@ -139,9 +139,14 @@ class Client():
if self.pull_sock in socks:
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
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):
self.push_sock.send(umsgpack.packb(msg))

View File

@ -91,7 +91,10 @@ class close(bpy.types.Operator):
return {"FINISHED"}
# CLIENT-SERVER
def refresh_window():
import bpy
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
class session_join(bpy.types.Operator):
bl_idname = "session.join"
@ -106,7 +109,8 @@ class session_join(bpy.types.Operator):
def execute(self, context):
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)
bpy.ops.asyncio.loop()
@ -150,7 +154,7 @@ class session_create(bpy.types.Operator):
username = str(context.scene.session_settings.username)
server = net_components.Server()
client = net_components.Client(id=username)
client = net_components.Client(id=username,recv_callback=refresh_window)
time.sleep(1)

View File

@ -37,6 +37,7 @@ class SessionPanel(bpy.types.Panel):
area_msg.label(text="{}:{}".format(id,msg))
else:
area_msg.label(text="Empty")
else:
row = layout.row()
row.prop(scene.session_settings,"username",text="")