mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 06:39:16 +02:00
Basic working poc with favorites send over websocket
This commit is contained in:
parent
e490284511
commit
d509c090d3
7 changed files with 29 additions and 28 deletions
|
@ -3,3 +3,4 @@ from channels.layers import get_channel_layer
|
|||
|
||||
channel_layer = get_channel_layer()
|
||||
group_send = async_to_sync(channel_layer.group_send)
|
||||
group_add = async_to_sync(channel_layer.group_add)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from channels.generic.websocket import JsonWebsocketConsumer
|
||||
from funkwhale_api.common import channels
|
||||
|
||||
|
||||
class JsonAuthConsumer(JsonWebsocketConsumer):
|
||||
|
@ -9,3 +10,8 @@ class JsonAuthConsumer(JsonWebsocketConsumer):
|
|||
return self.close()
|
||||
|
||||
return self.accept()
|
||||
|
||||
def accept(self):
|
||||
super().accept()
|
||||
for group in self.groups:
|
||||
channels.group_add(group, self.channel_name)
|
||||
|
|
|
@ -8,10 +8,12 @@ record.registry.register_serializer(
|
|||
|
||||
|
||||
@record.registry.register_consumer('favorites.TrackFavorite')
|
||||
def broadcast_track_favorite_to_instance_timeline(data, obj):
|
||||
def broadcast_track_favorite_to_instance_activity(data, obj):
|
||||
if obj.user.privacy_level not in ['instance', 'everyone']:
|
||||
return
|
||||
channels.group_send('instance_timeline', {
|
||||
'type': 'event',
|
||||
|
||||
channels.group_send('instance_activity', {
|
||||
'type': 'event.send',
|
||||
'text': '',
|
||||
'data': data
|
||||
})
|
||||
|
|
8
api/funkwhale_api/instance/consumers.py
Normal file
8
api/funkwhale_api/instance/consumers.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from funkwhale_api.common.consumers import JsonAuthConsumer
|
||||
|
||||
|
||||
class InstanceActivityConsumer(JsonAuthConsumer):
|
||||
groups = ["instance_activity"]
|
||||
|
||||
def event_send(self, message):
|
||||
self.send_json(message['data'])
|
|
@ -1,17 +0,0 @@
|
|||
from funkwhale_api.common.consumers import JsonAuthConsumer
|
||||
|
||||
|
||||
class MyConsumer(JsonAuthConsumer):
|
||||
groups = ["broadcast"]
|
||||
|
||||
def receive_json(self, payload):
|
||||
print(payload, self.scope["user"])
|
||||
# Called with either text_data or bytes_data for each frame
|
||||
# You can call:
|
||||
self.send_json({'test': 'me'})
|
||||
# Or, to send a binary frame:
|
||||
# self.send(bytes_data="{Hello} world!")
|
||||
# Want to force-close the connection? Call:
|
||||
# self.close()
|
||||
# # Or add a custom WebSocket error code!
|
||||
# self.close(code=4123)
|
Loading…
Add table
Add a link
Reference in a new issue