]> git.parisson.com Git - mezzo.git/commitdiff
[Vertigo M&C] : streaming event queue
authorEmilie <zawadzki@ircam.fr>
Wed, 15 Mar 2017 13:33:23 +0000 (14:33 +0100)
committerEmilie <zawadzki@ircam.fr>
Wed, 15 Mar 2017 13:33:23 +0000 (14:33 +0100)
app/organization/core/templatetags/organization_tags.py
app/organization/media/views.py
app/themes/base/static/src/js/modules/live-streaming-counter.js
app/themes/base/templates/media/live_streaming/live_streaming_detail.html

index 7b66bf79b0f14dfa9f9c0a163dd0f5272a39547a..a3db871a6f121ac4c5108fb8fb18fdf679f87757 100644 (file)
@@ -238,7 +238,3 @@ def filter_content(dynamic_contents):
         else :
             dict["other"].append(dc)
     return dict
-
-@register.filter
-def format_iso(date):
-    return date.isoformat()
index 8b834d3b248c2eefa65c621429bac9581e824f3d..2e893306e5f3a48855a8bdc84701e8e9ad2ec81f 100644 (file)
@@ -18,7 +18,7 @@
 
 # You should have received a copy of the GNU Affero General Public License
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
-
+import json
 from django.shortcuts import render
 from collections import defaultdict
 from organization.media.models import *
@@ -26,6 +26,7 @@ from organization.core.views import *
 from dal import autocomplete
 from django.core.exceptions import FieldDoesNotExist
 from datetime import datetime
+from django.db.models import Q
 
 # temporarily excluse not ready models
 EXCLUDED_MODELS = ("organizationplaylist", "personplaylist")
@@ -137,7 +138,8 @@ class LiveStreamingDetailView(SlugMixin, DetailView):
 
     def get_context_data(self, **kwargs):
         context = super(LiveStreamingDetailView, self).get_context_data(**kwargs)
-        print("LIVE_STREAMING_TYPE_CHOICES", LIVE_STREAMING_TYPE_CHOICES)
+
+        # check type choices
         type_choices = []
         for st in LIVE_STREAMING_TYPE_CHOICES:
             type_choices.append(st[0])
@@ -146,6 +148,25 @@ class LiveStreamingDetailView(SlugMixin, DetailView):
         else :
             context['type'] = self.kwargs['type']
 
-        context['slug'] = self.object.slug        
-        context['next_event'] = Event.objects.filter(location=self.object.event_location).filter(start__gt=datetime.now()).first()
+        # slug
+        context['slug'] = self.object.slug
+
+        # event data
+        all_events = Event.objects.filter(location=self.object.event_location)
+        curr_event = Event.objects.filter(location=self.object.event_location).filter(end__gte=datetime.now()).order_by('start').first()
+
+        events_data = {}
+        counter = 0
+        curr_event_index = len(all_events)
+        for event in all_events:
+            events_data[counter] = {}
+            events_data[counter]['title'] = event.title
+            events_data[counter]['begin'] = event.start.isoformat()
+            events_data[counter]['end'] = event.end.isoformat()
+            if curr_event:
+                if curr_event.id == event.id :
+                    curr_event_index = counter
+            counter += 1
+        context['curr_event_index'] = curr_event_index
+        context['json_event'] = json.dumps(events_data)
         return context
index 1dd05a3f83ea9526702203c6667f3581c33838ca..576897bb98fd942bc0d3eeaff9b8e094e06562bd 100644 (file)
@@ -32,10 +32,17 @@ function cleanCounter() {
     $('#countdown').html('<br />');
 }
 
-function CountDownTimer(dt_begin, dt_end, id, video_id/*, video_url*/)
+function CountDownTimer(json_event, curr_event_index, id, video_id/*, video_url*/)
     {
-        var begin = new Date(dt_begin);
-        var end = new Date(dt_end);
+        //console.log("json_event.length", Object.keys(json_event).length);
+        //console.log("curr_event_index", curr_event_index);
+        if (Object.keys(json_event).length <= curr_event_index) {
+            return ;
+        }
+
+        var curr_event = json_event[curr_event_index];
+        var begin = new Date(curr_event.begin);
+        var end = new Date(curr_event.end);
 
         var _second = 1000;
         var _minute = _second * 60;
@@ -43,12 +50,12 @@ function CountDownTimer(dt_begin, dt_end, id, video_id/*, video_url*/)
         var _day = _hour * 24;
         var timer;
         var distance_out = 1;
-        var distance_in = 0;
+        var distance_in = 1;
 
         function showRemaining() {
             var now = new Date();
             var distance_out = begin - now;
-            // console.log("distance_out", distance_out)
+            //console.log("distance_out", distance_out)
 
             if (distance_out < 0) {
                 //clearInterval(timer);
@@ -58,11 +65,11 @@ function CountDownTimer(dt_begin, dt_end, id, video_id/*, video_url*/)
                 //switchVideo(video_id, video_url);
                 $('.countdown-overlay').hide()
                 distance_in = 1;
-                nextEvent()
-                return;
+                hideRemaining()
+                //return;
             }
 
-            $('#countdown-title').html('Retransmission dans :');
+            $('#countdown-title').html('Prochain évènement :<br><br/><strong>'+ curr_event.title +'</strong><br/><br/> Retransmission dans :');
 
             var days = Math.floor(distance_out / _day);
             var hours = Math.floor((distance_out % _day) / _hour);
@@ -76,17 +83,37 @@ function CountDownTimer(dt_begin, dt_end, id, video_id/*, video_url*/)
 
         }
 
-        function nextEvent() {
+        function hideRemaining() {
             var now = new Date();
             var distance_in = end - now;
             //console.log("distance_in", distance_in)
 
             if (distance_in < 0) {
+                nextEvent()
+                distance_in = end - now;
                 $('.countdown-overlay').show()
+            }
+        }
+
+        function nextEvent() {
+            curr_event_index++;
+            if (shouldStreamingStop()) {
+                curr_event = json_event[curr_event_index]
+                begin = new Date(curr_event.begin);
+                end = new Date(curr_event.end);
+            }
+        }
 
+        function shouldStreamingStop() {
+            var bool = true;
+            if (json_event.length - 1 < curr_event_index) {
+                clearInterval(timer);
+                bool = false;
             }
+            return bool;
         }
 
+
         // calculer le diff avec le prochain évènement
         // réactiver le countdown
 
@@ -96,7 +123,7 @@ function CountDownTimer(dt_begin, dt_end, id, video_id/*, video_url*/)
 
         //console.log("distance_in", distance_in)
         if (distance_in > 0) {
-            timer = setInterval(nextEvent, 1000);
+            timer = setInterval(hideRemaining, 1000);
         }
     }
 
index 486e9f6667486dfeb7aacdd0b70e9914577e801e..9a1a67e7443757820455b9418e51223aaeee23f4 100644 (file)
@@ -52,8 +52,7 @@
     <script src="{% static "src/js/modules/live-streaming-counter.js" %}"></script>
 
     <script type="text/javascript">
-        var d_begin = '{{ next_event.start|format_iso }}';
-        var d_end = '{{ next_event.end|format_iso }}';
-        CountDownTimer(d_begin, d_end, 'countdown', 'live-streaming');
+        var json_event = {{ json_event|safe }}
+        CountDownTimer(json_event, {{ curr_event_index }}, 'countdown', 'live-streaming');
     </script>
 {% endblock %}