refactoring the pop.js code. embed-playerapi-rewrite
authorhamidouk
Tue, 24 Jan 2012 12:29:14 +0100
branchembed-playerapi-rewrite
changeset 699 0d6200d801ad
parent 698 329333e07267
child 700 c6933b86acba
refactoring the pop.js code.
src/js/pop.js
--- a/src/js/pop.js	Mon Jan 23 17:27:37 2012 +0100
+++ b/src/js/pop.js	Tue Jan 24 12:29:14 2012 +0100
@@ -2,30 +2,39 @@
    popcorn is a bit unstable at the time */
 
 IriSP.PopcornReplacement = {
-  msgPump : {} /* used by jquery to receive and send messages */,
-  __delay_seek_signal : false
-};
-
-IriSP.PopcornReplacement.media = { 
-  "paused": true,
-  "muted": false
 };
 
-IriSP.PopcornReplacement.listen = function(msg, callback) {
-//  IriSP.jQuery(IriSP.PopcornReplacement.msgPump).bind(msg, function(event, rest) { callback(rest); });
-  if (!IriSP.PopcornReplacement.msgPump.hasOwnProperty(msg))
-    IriSP.PopcornReplacement.msgPump[msg] = [];
 
-  IriSP.PopcornReplacement.msgPump[msg].push(callback);
+/** instantiate a new popcorn-compatible player
+    @param playerFns an object which contains a number of
+    methods: init, play, pause, getMute, setMute used by
+    our wrapper.
+ */
+IriSP.PopcornReplacement.player = function(playerFns) {
+  this.playerFns = playerFns;
+  this.media = { 
+    "paused": true,
+    "muted": false
+  };
+  
+  this.msgPump = {}; /* dictionnary used to receive and send messages */
 };
 
-IriSP.PopcornReplacement.trigger = function(msg, params) {
+IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) {
+//  IriSP.jQuery(IriSP.PopcornReplacement.msgPump).bind(msg, function(event, rest) { callback(rest); });
+  if (!this.msgPump.hasOwnProperty(msg))
+    this.msgPump[msg] = [];
+
+  this.msgPump[msg].push(callback);
+};
+
+IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) {
 //  IriSP.jQuery(IriSP.PopcornReplacement.msgPump).trigger(msg, params);
   
-  if (!IriSP.PopcornReplacement.msgPump.hasOwnProperty(msg))
+  if (!this.msgPump.hasOwnProperty(msg))
     return;
 
-  var d = IriSP.PopcornReplacement.msgPump[msg];
+  var d = this.msgPump[msg];
 
   for(var i = 0; i < d.length; i++) {
     d[i].call(window, params);
@@ -199,3 +208,4 @@
   var currentTime = IriSP.PopcornReplacement.currentTime();
   return Math.round(currentTime);
 };
+