from teleforma.models.core import Conference, StreamingServer, LiveStream
-def render(request, template, data = None, mimetype = None):
- return render_to_response(template, data, context_instance=RequestContext(request),
- mimetype=mimetype)
+def render(request, template, data=None, mimetype=None):
+ return render_to_response(
+ template, data, context_instance=RequestContext(request), mimetype=mimetype
+ )
+
def get_host(request):
- host = request.META['HTTP_HOST']
- if ':' in host:
- host = host.split(':')[0]
+ host = request.META["HTTP_HOST"]
+ if ":" in host:
+ host = host.split(":")[0]
return host
+
status = Status()
class StatusView(object):
-
- @jsonrpc_method('telecaster.get_server_status')
+ @jsonrpc_method("telecaster.get_server_status")
def get_server_status(request):
status.update()
return status.to_dict()
- @jsonrpc_method('telecaster.get_station_status')
+ @jsonrpc_method("telecaster.get_station_status")
def get_station_status(request):
stations = Station.objects.filter(started=True)
if stations:
station = {}
return station
- @jsonrpc_method('telecaster.start')
+ @jsonrpc_method("telecaster.start")
def start(request, station_dict):
pass
- @jsonrpc_method('telecaster.stop')
+ @jsonrpc_method("telecaster.stop")
def stop(request):
pass
-class ConferenceRecordView(FormView):
- "Conference record form : telecaster module required"
-
- model = Conference
- form_class = ConferenceForm
- template_name='teleforma/course_conference_record.html'
- hidden_fields = ['started', 'date_begin', 'date_end', 'public_id', 'readers']
-
- def get_context_data(self, **kwargs):
- context = super(ConferenceRecordView, self).get_context_data(**kwargs)
- context['mime_type'] = 'video/webm'
- status = Status()
- status.update()
- context['hidden_fields'] = self.hidden_fields
- context['room'] = get_room(name='monitor')
- return context
-
- def get_success_url(self):
- return reverse('teleforma-conference-detail', kwargs={'period_id': self.conference.period.id,
- 'pk':self.conference.id})
-
- def form_valid(self, form):
- form.save()
- uuid = get_random_hash()
- conference = form.instance
- conference.date_begin = datetime.datetime.now()
- conference.public_id = uuid
- conference.save()
- self.conference = conference
- status = Status()
- status.get_hosts()
-
- if conference.streaming:
- stations = settings.TELECASTER_CONF
- else:
- stations = settings.TELECASTER_CONF_NO_STREAMING
-
- for station in stations:
- type = station['type']
- conf = station['conf']
- port = station['port']
- server_type = station['server_type']
- server, c = StreamingServer.objects.get_or_create(host=status.ip, port=port, type=server_type)
- station = Station(conference=conference, public_id=uuid)
- station.setup(conf)
- try:
- station.start()
- except:
- continue
- station.save()
- stream = LiveStream(conference=conference, server=server,
- stream_type=type, streaming=True)
- stream.save()
- if server_type == 'stream-m':
- try:
- self.snapshot('http://localhost:8080/snapshot/monitor', station.output_dir)
- except:
- pass
- if conference.streaming:
- try:
- live_message(self.conference)
- except:
- pass
-
- try:
- self.push()
- except:
- pass
-
- return super(ConferenceRecordView, self).form_valid(form)
-
- def snapshot(self, url, dir):
- width = 160
- height = 90
- img = urllib.urlopen(url)
- path = dir + os.sep + 'preview.webp'
- f = open(path, 'w')
- f.write(img.read())
- f.close()
- command = 'dwebp "' + path + '" -o "' + dir + os.sep + 'preview.png" &'
- os.system(command)
-
- @method_decorator(login_required)
- def dispatch(self, *args, **kwargs):
- return super(ConferenceRecordView, self).dispatch(*args, **kwargs)
-
- @jsonrpc_method('teleforma.create_conference')
- def create(request, conf_dict):
- if isinstance(conf_dict, dict):
- conferences = Conference.objects.filter(public_id=conf_dict['id'])
- if not conferences:
- conference = Conference()
- conference.from_json_dict(conf_dict)
- conference.save()
-
- for stream in conf_dict['streams']:
- host = stream['host']
- port = stream['port']
- server_type = stream['server_type']
- stream_type = stream['stream_type']
- site = Site.objects.all()[0]
- server, c = StreamingServer.objects.get_or_create(host=site,
- port=port,
- type=server_type)
- stream = LiveStream(conference=conference, server=server,
- stream_type=stream_type, streaming=True)
- stream.save()
- try:
- live_message(conference)
- except:
- pass
- else:
- raise 'Error : input must be a conference dictionnary'
-
- def push(self):
- url = 'https://' + self.conference.department.domain + '/json/'
- s = ServiceProxy(url)
- s.teleforma.create_conference(self.conference.to_json_dict())