Exemple #1
0
    def post(request, *args, **kwargs):
        event = request.META.get("HTTP_X_STAGYBEE_EXTRACTOR_EVENT")
        channel_layer = get_channel_layer()
        congregation_group_name = generate_channel_group_name(
            "stage", kwargs.get("pk"))
        if event == "listeners":
            async_to_sync(channel_layer.group_send)(
                congregation_group_name,
                {
                    "type": "extractor.listeners",
                    "listeners": request.body
                },
            )
            return HttpResponse(content="success", status=202)
        elif event == "status":
            async_to_sync(channel_layer.group_send)(
                congregation_group_name,
                {
                    "type": "extractor.status",
                    "status": request.body
                },
            )
            return HttpResponse(content="success", status=202)
        elif event == "meta":
            return HttpResponse(content="success", status=200)

        return HttpResponse(status=204)
Exemple #2
0
 def post(request, *args, **kwargs):
     channel_layer = get_channel_layer()
     congregation_group_name = generate_channel_group_name(
         "console", kwargs.get("pk"))
     stage_group_name = generate_channel_group_name("message",
                                                    kwargs.get("pk"))
     if request.POST.get("action") == "message-send":
         async_to_sync(channel_layer.group_send)(stage_group_name, {
             "type": "message.alert",
             "alert": {
                 "value": request.POST.get("message")
             }
         })
         async_to_sync(channel_layer.group_send)(
             congregation_group_name, {
                 "type": "console.wait_for_ack"
             })
         congregation = Credential.objects.get(
             congregation=kwargs.get("pk"))
         if congregation is not None:
             Audit.objects.create_audit(congregation=congregation,
                                        message=request.POST.get("message"),
                                        user=request.user)
     elif request.POST.get("action") == "message-ack":
         async_to_sync(channel_layer.group_send)(congregation_group_name, {
             "type": "console.message",
             "message": {
                 "message": "ACK"
             }
         })
     elif request.POST.get("action") == "scrim-toggle":
         async_to_sync(channel_layer.group_send)(congregation_group_name, {
             "type": "console.scrim"
         })
     elif request.POST.get("action") == "scrim-refresh":
         async_to_sync(channel_layer.group_send)(
             congregation_group_name, {
                 "type": "console.scrim_refresh"
             })
     else:
         return HttpResponse("", status=404)
     return HttpResponse("", status=202)
Exemple #3
0
 async def timer_callback(self, timer, running):
     congregation = self.scope["url_route"]["kwargs"]["congregation"]
     group_name = generate_channel_group_name("console", congregation)
     if running:
         await self.channel_layer.group_send(group_name, {"type": "timer.tick"})
     else:
         remaining_time = timer.get_formatted_remaining_time()
         elapsed_time = timer.get_formatted_elapsed_time()
         percentage = timer.get_elapsed_percentage()
         await self.channel_layer.group_send(group_name, {"type": "timer.stop", "data": {"remaining": remaining_time,
                                                                                         "elapsed": elapsed_time,
                                                                                         "percentage": percentage}})
Exemple #4
0
 def post(self, request, *args, **kwargs):
     congregation = kwargs.get("pk")
     channel_layer = get_channel_layer()
     stage_congregation_group_name = generate_channel_group_name(
         "stage", congregation)
     if request.POST.get("action") == "connect":
         async_to_sync(channel_layer.group_send)(
             stage_congregation_group_name, {
                 "type": "extractor.connect"
             })
     else:
         return HttpResponse(status=404)
     return HttpResponse(status=202)
Exemple #5
0
 async def connect(self):
     user = self.scope["user"]
     if user.is_anonymous or not user.is_authenticated:
         await self.close()
         return
     congregation = self.scope["url_route"]["kwargs"]["congregation"]
     language = self.scope["url_route"]["kwargs"]["language"]
     translation.activate(language)
     await self.channel_layer.group_add(generate_channel_group_name("timer", congregation), self.channel_name)
     timer = GLOBAL_TIMERS.get(congregation)
     if timer is not None:
         timer.set_callback(self.timer_callback)
     await self.accept()
Exemple #6
0
 async def post(request, *args, **kwargs):
     congregation = kwargs.get("pk")
     channel_layer = get_channel_layer()
     congregation_group_name = generate_channel_group_name(
         "timer", congregation)
     if request.POST.get("action") == "timer-start":
         if congregation in GLOBAL_TIMERS:
             actual_timer = GLOBAL_TIMERS.get(congregation)
             if actual_timer is not None:
                 await actual_timer.cancel()
                 GLOBAL_TIMERS.pop(congregation)
         context = {
             "duration":
             timedelta(hours=float(request.POST.get("h")),
                       minutes=float(request.POST.get("m")),
                       seconds=float(request.POST.get("s"))),
             "start":
             timezone.now(),
             "index":
             request.POST.get("talk_index"),
             "congregation":
             congregation,
             "running":
             True
         }
         timer = Timer(1,
                       None,
                       context=context,
                       timer_name=request.POST.get("talk_name"))
         GLOBAL_TIMERS[congregation] = timer
         await channel_layer.group_send(congregation_group_name,
                                        {"type": "timer.action"})
     elif request.POST.get("action") == "timer-stop":
         if congregation in GLOBAL_TIMERS and GLOBAL_TIMERS[
                 congregation] is not None:
             await GLOBAL_TIMERS[congregation].cancel()
             GLOBAL_TIMERS.pop(congregation)
     else:
         return HttpResponse(status=404)
     return HttpResponse(status=202)
Exemple #7
0
 async def connect(self):
     # user = self.scope["user"]
     # if user.is_anonymous or not user.is_authenticated:
     #     await self.close()
     #     return
     congregation = self.scope["url_route"]["kwargs"]["congregation"]
     language = self.scope["url_route"]["kwargs"]["language"]
     translation.activate(language)
     if "scrim" not in self.scope["session"] or self.scope["session"]["scrim"] is None:
         self.scope["session"]["scrim"] = False
     await self.channel_layer.group_add(generate_channel_group_name("console", congregation), self.channel_name)
     if self.scope["session"]["scrim"]:
         message_alert = render_to_string(template_name="stage/events/scrim.html")
     else:
         message_alert = ""
     await self.accept()
     await self.send(text_data=message_alert)
     timer = GLOBAL_TIMERS.get(congregation)
     if timer is not None:
         context = {"index": timer.get_context()["index"]}
         event = render_to_string(template_name="stopwatch/fragments/talk_index.html", context=context)
         await self.send(text_data=event)
     await self.console_scrim_refresh({})
Exemple #8
0
 def test_generate_channel_group_name(self):
     self.assertEqual("congregation.console.testAZaz", generate_channel_group_name("console", "testAZaz"))
     self.assertEqual("congregation.console.T.e_s-t", generate_channel_group_name("console", "T.e_s-t"))
     self.assertEqual("congregation.console.t_est_", generate_channel_group_name("console", "t%est%"))
Exemple #9
0
 async def disconnect(self, close_code):
     await self.channel_layer.group_discard(
         generate_channel_group_name("console", self.scope["url_route"]["kwargs"]["congregation"]),
         self.channel_name
     )
     raise StopConsumer()