Skip to content

Commit

Permalink
Merge pull request #367 from EsupPortail/dev
Browse files Browse the repository at this point in the history
Dev #2.7.1
  • Loading branch information
ptitloup authored Oct 28, 2020
2 parents 8c5d37d + 1ae92bd commit 68dd325
Show file tree
Hide file tree
Showing 11 changed files with 522 additions and 494 deletions.
9 changes: 9 additions & 0 deletions pod/live/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class Broadcaster(models.Model):
'Height of the embedded site (in pixels)'))
status = models.BooleanField(default=0, help_text=_(
'Check if the broadcaster is currently sending stream.'))
enable_viewer_count = models.BooleanField(
default=1,
verbose_name=_(u'Enable viewers count'),
help_text=_('Enable viewers count on live.'))
is_restricted = models.BooleanField(
verbose_name=_(u'Restricted access'),
help_text=_(
Expand Down Expand Up @@ -149,3 +153,8 @@ class HeartBeat(models.Model):
verbose_name=_('Broadcaster'))
last_heartbeat = models.DateTimeField(
_('Last heartbeat'), default=timezone.now)

class Meta:
verbose_name = _("Heartbeat")
verbose_name_plural = _("Heartbeats")
ordering = ['broadcaster']
5 changes: 4 additions & 1 deletion pod/live/templates/live/live.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
<script src="{% static 'video-js-6.8.0/video.min.js' %}"></script>
<script src="{% static 'js/videojs-http-streaming.min.js' %}"></script>
<script src="{% static 'js/videojs-logo-controlbar.js' %}"></script>
{% if broadcaster.enable_viewer_count%}
<script>let heartbeat_delay = {{heartbeat_delay}}</script>
<script src="{% static 'js/viewcounter.js' %}"></script>
{%endif%}
{% endblock %}


Expand Down Expand Up @@ -191,8 +193,9 @@ <h5 class="card-title pl-2">
// Management of the streaming live
var player = videojs('podvideoplayer', options, function(){});


{% if broadcaster.enable_viewer_count%}
player.videoJsViewerCount();
{% endif %}
player.videoJsLogo({imgsrc: '{% static LOGO_PLAYER %}', linktitle:'{{TITLE_ETB}} - {{TITLE_SITE}}', link:'{{LINK_PLAYER}}'});
player.on('error', function() {
// Handle successives errors to avoid multiple reload
Expand Down
51 changes: 22 additions & 29 deletions pod/live/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,25 @@ def change_status(request, slug):


def heartbeat(request):
if request.is_ajax():
try:
key = request.GET.get('key', '')
broadcaster_id = int(request.GET.get('liveid', 0))
heartbeat = HeartBeat.objects.filter(viewkey=key)
if heartbeat.count() == 0:
if request.user.is_anonymous:
HeartBeat.objects.create(
viewkey=key, broadcaster_id=broadcaster_id)
else:
HeartBeat.objects.create(
viewkey=key, broadcaster_id=1, user=request.user)
else:
heartbeat = heartbeat.first()
heartbeat.last_heartbeat = timezone.now()
heartbeat.save()
except ObjectDoesNotExist:
return HttpResponseBadRequest()
else:
return HttpResponseBadRequest()
mimetype = 'application/json'
broadcast = Broadcaster.objects.get(id=broadcaster_id)
viewers = broadcast.viewers.values(
'first_name', 'last_name', 'is_superuser')
can_see = (VIEWERS_ONLY_FOR_STAFF and
request.user.is_staff) or not VIEWERS_ONLY_FOR_STAFF
return HttpResponse(json.dumps(
{"viewers": broadcast.viewcount, "viewers_list": list(
viewers) if can_see else []}), mimetype)
if request.is_ajax() and request.method == "GET":
broadcaster_id = int(request.GET.get('liveid', 0))
broadcast = get_object_or_404(
Broadcaster, id=broadcaster_id)
key = request.GET.get('key', '')
heartbeat, created = HeartBeat.objects.get_or_create(
viewkey=key, broadcaster_id=broadcaster_id)
if created:
if not request.user.is_anonymous:
heartbeat.user = request.user
heartbeat.last_heartbeat = timezone.now()
heartbeat.save()

mimetype = 'application/json'
viewers = broadcast.viewers.values(
'first_name', 'last_name', 'is_superuser')
can_see = (VIEWERS_ONLY_FOR_STAFF and
request.user.is_staff) or not VIEWERS_ONLY_FOR_STAFF
return HttpResponse(json.dumps(
{"viewers": broadcast.viewcount, "viewers_list": list(
viewers) if can_see else []}), mimetype)
return HttpResponseBadRequest()
Binary file modified pod/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 68dd325

Please sign in to comment.