2015: live: Misc cleanup.
authorDavid Thompson <dthompson2@worcester.edu>
Sat, 21 Mar 2015 01:23:11 +0000 (21:23 -0400)
committerDavid Thompson <dthompson2@worcester.edu>
Sat, 21 Mar 2015 01:23:11 +0000 (21:23 -0400)
2015/assets/js/stream.js

index ce1dbd22344e21454d85fa79a0feaed935d2790a..e94160662319c74d015f0cecd1baa90e7dc6e26c 100644 (file)
@@ -81,7 +81,9 @@ app.mountToStreamUrl = function(mount) {
 };
 
 app.changeVideoMount = function(video, mount) {
-  console.log(mount);
+  // This is quite hacky and doesn't feel like the Mithril way to do
+  // things, but we need to explicitly reload the video when the
+  // source URL changes.
   video.src = app.mountToStreamUrl(mount);
   video.load();
   video.play();
@@ -107,26 +109,40 @@ app.streams = [
 ];
 
 app.controller = function() {
-  var self = this;
-
   this.stream = m.prop(app.streams[0]);
   this.stats = m.prop(app.nullStats);
-
   this.showDesktop = m.prop(false);
 
-  this.updateStats = function() {
-    self.stats = app.streamStats(self.stream().speakerMount);
-  };
+  // Check stats every 10 seconds.
+  app.scheduleEvery(10000, this.updateStats.bind(this));
+};
 
-  app.scheduleEvery(10000, function() {
-    self.updateStats();
-  });
+app.controller.prototype.updateStats = function() {
+  this.stats = app.streamStats(this.stream().speakerMount);
 };
 
 app.view = function(ctrl) {
   var stream = ctrl.stream();
-  var showDesktop = ctrl.showDesktop();
   var stats = ctrl.stats();
+  var showDesktop = ctrl.showDesktop();
+
+  function renderSpeakerStream() {
+    return m("video.lp-video", {
+      id: "speaker-video",
+      controls: true,
+      autoplay: true
+    }, [
+      m("source", {
+        src: app.mountToStreamUrl(stream.speakerMount)
+      }),
+      m("p",
+        m("em", [
+          "Your browser does not support the HTML5 video tag, ",
+          m("a", { href: "TODO" }, "[ please download ]"),
+          "the video instead"
+        ]))
+    ]);
+  }
 
   function renderDesktopStream() {
     return m("video.lp-video", {
@@ -203,21 +219,7 @@ app.view = function(ctrl) {
     renderRoomSelector(),
     m("h2", stream.name),
     renderStats(),
-    m("video.lp-video", {
-      id: "speaker-video",
-      controls: true,
-      autoplay: true
-    }, [
-      m("source", {
-        src: app.mountToStreamUrl(stream.speakerMount)
-      }),
-      m("p",
-        m("em", [
-          "Your browser does not support the HTML5 video tag, ",
-          m("a", { href: "TODO" }, "[ please download ]"),
-          "the video instead"
-        ]))
-    ]),
+    renderSpeakerStream(),
     showDesktop ? renderDesktopStream() : null,
     renderToggleDesktopStream(),
     m("h2", "IRC"),