]> git.parisson.com Git - teleforma.git/commitdiff
add context_processors.hosts in order to parse media urls with HOST
authoryomguy <yomguy@parisson.com>
Wed, 5 Dec 2012 17:29:10 +0000 (18:29 +0100)
committeryomguy <yomguy@parisson.com>
Wed, 5 Dec 2012 17:29:10 +0000 (18:29 +0100)
teleforma/context_processors.py [new file with mode: 0644]
teleforma/templates/teleforma/course_conference.html
teleforma/templates/teleforma/course_conference_record.html
teleforma/templatetags/teleforma_tags.py
teleforma/views/core.py

diff --git a/teleforma/context_processors.py b/teleforma/context_processors.py
new file mode 100644 (file)
index 0000000..eb099a0
--- /dev/null
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+from django.conf import settings
+import socket
+
+interfaces = ['eth0', 'eth1', 'eth2', 'eth0-eth2', 'eth3', 'eth4',
+                  'wlan0', 'wlan1', 'wlan2', 'wlan3', 'wlan4']
+
+def get_ip_address(ifname):
+    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+    ip = socket.inet_ntoa(fcntl.ioctl(
+            s.fileno(),
+            0x8915,  # SIOCGIFADDR
+            struct.pack('256s', ifname[:15])
+            )[20:24])
+    return ip
+
+def get_local_host():
+    local_ip = ''
+    for interface in interfaces:
+        try:
+            ip = get_ip_address(interface)
+            if ip:
+                local_ip = ip
+                break
+        except:
+               pass
+
+    if not local_ip:
+        local_ip = '127.0.0.1'
+    return local_ip
+
+
+def get_http_host(request):
+    host = request.META['HTTP_HOST']
+    if ':' in host:
+        host = host.split(':')[0]
+    return host
+
+
+def host(request):
+    request_host = get_http_host(request)
+    local_host = get_local_host()
+
+    if request_host.split('.')[0] == local_host.split('.')[0] or \
+                                request_host == '127.0.0.1' or request_host == 'localhost':
+        # LAN access
+        ip = local_host
+    else:
+        ip = settings.ROUTER_IP
+
+    return {'HOST': ip }
+
index 395795be858338fc586f79a9643d3e856c0229ce..8bd754b2528ca1259426bc651552b81da5a4d8d6 100644 (file)
@@ -53,7 +53,7 @@
 <div class="video">
 <video width="640" height="360" controls autoplay preload="auto">
 <!-- Hello Chrome and Firefox (and Opera?) -->
-<source src="{{ livestream.url|get_host:host }}" type="video/webm" />
+<source src="{{ livestream.url|set_host:HOST }}" type="video/webm" />
 </video>
 </div>
 {% endif %}
index 25a7a4658412227b2606555746add403d93b0461..3416738cd792c51c0b7ec5b061d89442b0d69dfa 100644 (file)
@@ -26,7 +26,7 @@ jQuery(window).ready(function(){
 {% block video %}
 <div class="video">
 <video controls autoplay preload="auto" width="640" height="360">
-<source src="http://{{ host }}:8080/consume/safe" type="video/webm">
+<source src="http://{{ HOST }}:8080/consume/safe" type="video/webm">
 </video>
 </div>
 {% endblock video %}
index d88e9a187744d58e80a3ed30c2bbe6265c64e3cd..56c245726147ce6158f25b3615e1a3fdee1093fb 100644 (file)
@@ -193,10 +193,7 @@ def get_video_id(media):
     return
 
 @register.filter
-def get_host(url, host):
+def set_host(url, host):
     u = urlparse(url)
-    if host == '127.0.0.1' or host == 'localhost':
-        nu = u.scheme + '://' + host + ':' + str(u.port) + u.path
-        return nu
-    else:
-        return url
+    return u.scheme + '://' + host + ':' + str(u.port) + u.path
+    
\ No newline at end of file
index 70cc6c63fd6b88767ac24c2d7e89227abd697860..eb47e34c5536ddfba8b55cd05e06e6fad6ced8d6 100644 (file)
@@ -403,7 +403,7 @@ class ConferenceView(DetailView):
 
 
 class ConferenceRecordView(FormView):
-    "Conference record form : TeleCaster module required"
+    "Conference record form : telecaster module required"
 
     model = Conference
     form_class = ConferenceForm