wip: make PeerMessage work

This commit is contained in:
Yohan Boniface 2024-12-26 13:47:50 +01:00
parent 481963e3f3
commit 99ce09bb2f
2 changed files with 16 additions and 6 deletions

View file

@ -7,6 +7,7 @@ from .websocket_server import (
OperationMessage, OperationMessage,
Request, Request,
ValidationError, ValidationError,
PeerMessage,
) )
@ -40,7 +41,11 @@ class SyncConsumer(AsyncWebsocketConsumer):
await self.channel_layer.group_discard(self.map_id, self.channel_name) await self.channel_layer.group_discard(self.map_id, self.channel_name)
async def broadcast(self, event): 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"]) await self.send(event["message"])
async def receive(self, text_data): async def receive(self, text_data):
@ -81,11 +86,15 @@ class SyncConsumer(AsyncWebsocketConsumer):
) )
# Send peer messages to the proper peer # Send peer messages to the proper peer
# case PeerMessage(recipient=_id): case PeerMessage():
# peer = connections.get(_id) print("Received peermessage", incoming.root)
# if peer: await self.channel_layer.send(
# await peer.send(raw_message) incoming.root.recipient,
# websockets.broadcast(other_peers, text_data) {
"message": text_data,
"type": "pair_to_pair",
},
)
# Send peer messages to the proper peer # Send peer messages to the proper peer
# case PeerMessage(recipient=_id): # case PeerMessage(recipient=_id):

View file

@ -285,6 +285,7 @@ export class SyncEngine {
*/ */
sendToPeer(recipient, verb, payload) { sendToPeer(recipient, verb, payload) {
payload.verb = verb payload.verb = verb
console.log('Sending peermessage to', recipient)
this.transport.send('PeerMessage', { this.transport.send('PeerMessage', {
sender: this.uuid, sender: this.uuid,
recipient: recipient, recipient: recipient,