Example #1
0
def dispatch_video(video, to_admin=False):
    """Send the video to users connected to the video consumer."""
    room_name = VIDEO_ADMIN_ROOM_NAME if to_admin else VIDEO_ROOM_NAME
    channel_layer = get_channel_layer()
    serialized_video = VideoSerializer(video, context={"is_admin": to_admin})
    async_to_sync(channel_layer.group_send)(
        room_name.format(video_id=str(video.id)),
        {"type": "video_updated", "video": serialized_video.data},
    )
Example #2
0
    def test_send_video_to_simple_user(self):
        """A message containing serialized video is dispatched to the regular group."""
        video = VideoFactory()

        channel_layer = get_channel_layer()
        async_to_sync(channel_layer.group_add)(
            VIDEO_ROOM_NAME.format(video_id=str(video.id)), "test_channel")

        channel_layers_utils.dispatch_video(video, to_admin=False)

        message = async_to_sync(channel_layer.receive)("test_channel")
        self.assertEqual(message["type"], "video_updated")
        self.assertEqual(
            message["video"],
            VideoSerializer(video, context={
                "is_admin": False
            }).data)
Example #3
0
 def _get_serializer_data(self, video, context):
     serializer = VideoSerializer(video, context=context)
     return serializer.data