From 99ce09bb2fd1fbd264df385cd0375ac7f20f05c5 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Thu, 26 Dec 2024 13:47:50 +0100 Subject: [PATCH] wip: make PeerMessage work --- umap/consumers.py | 21 +++++++++++++++------ umap/static/umap/js/modules/sync/engine.js | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/umap/consumers.py b/umap/consumers.py index abcdbd0a..a762d02f 100644 --- a/umap/consumers.py +++ b/umap/consumers.py @@ -7,6 +7,7 @@ from .websocket_server import ( OperationMessage, Request, ValidationError, + PeerMessage, ) @@ -40,7 +41,11 @@ class SyncConsumer(AsyncWebsocketConsumer): await self.channel_layer.group_discard(self.map_id, self.channel_name) async def broadcast(self, event): - print(event) + print("broadcast", event) + await self.send(event["message"]) + + async def pair_to_pair(self, event): + print("pair_to_pair", event) await self.send(event["message"]) async def receive(self, text_data): @@ -81,11 +86,15 @@ class SyncConsumer(AsyncWebsocketConsumer): ) # Send peer messages to the proper peer - # case PeerMessage(recipient=_id): - # peer = connections.get(_id) - # if peer: - # await peer.send(raw_message) - # websockets.broadcast(other_peers, text_data) + case PeerMessage(): + print("Received peermessage", incoming.root) + await self.channel_layer.send( + incoming.root.recipient, + { + "message": text_data, + "type": "pair_to_pair", + }, + ) # Send peer messages to the proper peer # case PeerMessage(recipient=_id): diff --git a/umap/static/umap/js/modules/sync/engine.js b/umap/static/umap/js/modules/sync/engine.js index 9df767af..3a465ce6 100644 --- a/umap/static/umap/js/modules/sync/engine.js +++ b/umap/static/umap/js/modules/sync/engine.js @@ -285,6 +285,7 @@ export class SyncEngine { */ sendToPeer(recipient, verb, payload) { payload.verb = verb + console.log('Sending peermessage to', recipient) this.transport.send('PeerMessage', { sender: this.uuid, recipient: recipient,