timvideos / streaming-system

Tim Video's - Live Streaming for user groups and other events.
https://code.timvideos.us/
Apache License 2.0
131 stars 52 forks source link

Refactor the Javascript to use classes #31

Open mithro opened 11 years ago

mithro commented 11 years ago
/**
-*- coding: utf-8 -*-
 * vim: set ts=2 sw=2 et sts=2 ai:
 */

function JWPlayer(group, mode, quality) {
  this.group = group;

  this.jwsettings = {
      autostart: true,
      mute: true,
      //skin: '/static/third_party/jwplayer/skin/glow.zip',
      modes: streamer_{{group|safe_js}}.modes(mode, quality),
      width: '250',
      height: '200'
  };

  player_jwobject = jwplayer(group).setup(jwsettings);

  player_jwobject.onReady(this.updateSize);

  this.lastState = null;
  this.lastStateChange = 0;
}

function updateSize() {
  var player_sizer = $("#"+this.group);
  this.jwobject.resize(player_sizer.width(), player_sizer.height());
}

function checkState() {
  var state = this.jwobject.getState();

  var now = new Date().getTime();
  switch(state) {
  case this.jwobject.BUFFERING:
    if (state - now > 30) {
      this.reset();
    }
    break;
  }

  if (this.lastState != state) {
    this.lastStateChange = now;
    this.lastState = state;
  }
}
rihenperry commented 10 years ago

https://github.com/timvideos/streaming-system/issues/60 since streaming-system project is switching to html5 video support JWPlayer should be deprecated and this issue should be closed

mithro commented 10 years ago

Refactoring the code to use javascript classes is independent of which video player the project ends up using. Using javascript classes is generally good style.

rihenperry commented 10 years ago

@mithro, yeah that is correct.Also trying to minimize global variables creation and avoiding namespace confliction self-executing anonymous functions can also be used in modules.This is one of the best practices recommended by Douglas Crockford in his "Javascript:The Good Parts" book.

On Mon, Mar 17, 2014 at 6:42 AM, Tim Ansell notifications@github.comwrote:

Refactoring the code to use javascript classes is independent of which video player the project ends up using. Using javascript classes is generally good style.

— Reply to this email directly or view it on GitHubhttps://github.com/timvideos/streaming-system/issues/31#issuecomment-37778103 .