an image to player, first ideas to make a playback

This commit is contained in:
Blue 2018-12-02 18:07:43 +03:00
parent 43d0a1dfe9
commit 98a443e298
10 changed files with 192 additions and 10 deletions

View file

@ -18,3 +18,4 @@ configure_file(catalogue.js catalogue.js)
configure_file(imagePane.js imagePane.js)
configure_file(file/file.js file/file.js)
configure_file(player.js player.js)
configure_file(imageById.js imageById.js)

View file

@ -0,0 +1,46 @@
"use strict";
var LocalModel = require("./localModel");
var File = require("./file/file");
var Address = require("../wType/address");
var ImageById = LocalModel.inherit({
className: "ImageById",
constructor: function(properties, id) {
LocalModel.fn.constructor.call(this, properties);
this._imageId = id;
this._fileCtrl = new File(new Address(["images", this._imageId.toString()]));
this._need = 0;
this._fileCtrl.on("data", this._onControllerData, this);
this.addForeignController("Corax", this._fileCtrl);
},
dontNeedData: function() {
--this._need;
if (this._need === 0) {
this._fileCtrl.dontNeedData();
}
},
getMimeType: function () {
return this._fileCtrl.getMimeType();
},
hasData: function() {
return this._fileCtrl.hasData();
},
needData: function() {
if (this._need === 0) {
this._fileCtrl.needData();
}
++this._need;
},
_onControllerData: function() {
this.data = this._fileCtrl.data;
this.trigger("data");
}
});
module.exports = ImageById;

View file

@ -1,6 +1,7 @@
"use strict";
var counter = 0;
var Subscribable = require("../utils/subscribable");
var Controller = require("./controller");
var LocalModel = Subscribable.inherit({
"className": "LocalModel",
@ -9,6 +10,7 @@ var LocalModel = Subscribable.inherit({
this.properties = [];
this._controllers = [];
this._foreignControllers = [];
if (properties) {
for (var key in properties) {
@ -25,6 +27,14 @@ var LocalModel = Subscribable.inherit({
}
},
"destructor": function() {
for (i = 0; i < this._foreignControllers.length; ++i) {
var pair = this._foreignControllers[i];
global.unsubscribeForeignController(pair.n, pair.c);
global.registerForeignController(pair.n, pair.c);
pair.c.destructor();
}
for (var i = 0; i < this._controllers.length; ++i) {
this._controllers[i].destructor();
}
@ -34,6 +44,40 @@ var LocalModel = Subscribable.inherit({
"addController": function(ctrl) {
this._controllers.push(ctrl);
},
"addForeignController": function(nodeName, ctrl) {
if (!(ctrl instanceof Controller)) {
throw new Error("An attempt to add not a controller into " + this.className);
}
this._foreignControllers.push({n: nodeName, c: ctrl});
ctrl.on("serviceMessage", this._onControllerServiceMessage, this);
global.registerForeignController(nodeName, ctrl);
global.subscribeForeignController(nodeName, ctrl);
},
"_onControllerServiceMessage": Controller.fn._onControllerServiceMessage,
"removeForeignController": function(ctrl) {
if (!(ctrl instanceof Controller)) {
throw new Error("An attempt to remove not a controller from " + this.className);
}
for (var i = 0; i < this._foreignControllers.length; ++i) {
if (this._foreignControllers[i].c === ctrl) {
break;
}
}
if (i === this._foreignControllers.length) {
throw new Error("An attempt to remove not not existing controller from " + this.className);
} else {
var pair = this._foreignControllers[i];
global.unsubscribeForeignController(pair.n, pair.c);
global.registerForeignController(pair.n, pair.c);
pair.c.off("serviceMessage", this._onControllerServiceMessage, this);
this._foreignControllers.splice(i, 1);
}
},
"setData": function(data) {
this.data = data;
this.initialized = true;

View file

@ -1,7 +1,11 @@
"use strict";
var Uint64 = require("../wType/uint64");
var Address = require("../wType/address");
var Controller = require("./controller");
var Button = require("./button");
var ImageById = require("./imageById");
var Vocabulary = require("./vocabulary");
var Enum = require("../utils/enum");
@ -12,6 +16,7 @@ var Player = Controller.inherit({
this.controls = Object.create(null);
this.views = Object.create(null);
this.mode = PlayerMode.straight.playback;
this.addHandler("get");
this.addHandler("viewsChange");
@ -41,6 +46,8 @@ var Player = Controller.inherit({
},
_addView: function(type, address) {
var t = type.valueOf();
var ctrl;
var supported = false;
if (this.views[t] !== undefined) {
throw new Error("An attempt to add multiple instances of " + ItemType.reversed[t] + " into Player");
@ -52,11 +59,18 @@ var Player = Controller.inherit({
this.trigger("serviceMessage", "Queue is not supported yet in Player");
break;
case ItemType.straight.currentPlayback:
var cpb = new Vocabulary(address.clone());
cpb.ItemType = t;
this.views[t] = cpb;
this.addController(cpb);
this.trigger("newElement", cpb, t);
ctrl = new Vocabulary(address.clone());
ctrl.on("newElement", this._onNewPlayBackElement, this);
ctrl.on("removeElement", this._onNewRemoveBackElement, this);
supported = true;
break;
case ItemType.straight.picture:
ctrl = new ImageById(null, address.back());
ctrl.ItemType = t;
this.views[t] = ctrl;
this.trigger("newElement", ctrl, t);
supported = false; //just to avoid adding with addController, since ImageById is not a controller
break;
default:
this.trigger("serviceMessage", "An attempt to add ItemType " + ItemType.reversed[t] + " to views of the Player, but it's not qualified to be a view");
@ -64,12 +78,21 @@ var Player = Controller.inherit({
} else {
this.trigger("serviceMessage", "An unrecgnized item ItemType in Player: " + t);
}
if (supported) {
ctrl.ItemType = t;
this.views[t] = ctrl;
this.addController(ctrl);
this.trigger("newElement", ctrl, t);
}
},
_h_get: function(ev) {
var data = ev.getData();
var controls = data.at("controls");
var views = data.at("views");
var mode = data.at("mode").valueOf();
var size, i, vc;
size = controls.length();
@ -84,6 +107,13 @@ var Player = Controller.inherit({
this._addView(vc.at("type"), vc.at("address"));
}
if (this.mode !== mode) {
if (PlayerMode.reversed[mode] === undefined) {
throw new Error("Unsupported mode of player: " + mode);
}
this.mode = mode;
}
this.initialized = true;
this.trigger("data");
},
@ -105,19 +135,38 @@ var Player = Controller.inherit({
this._addView(vc.at("type"), vc.at("address"));
}
},
_onNewPlayBackElement: function(key, element) {
switch (key) {
case "image":
var address = new Address(["images", element.toString()]);
this._addView(new Uint64(ItemType.straight.picture), address);
address.destructor();
break;
}
},
_onNewRemoveBackElement: function(key) {
switch (key) {
case "image":
this._removeView(new Uint64(ItemType.straight.picture));
break;
}
},
_removeControl: function(type) {
//TODO
},
_removeView: function(type) {
//TODO
}
});
var ItemType = new Enum("ItemType");
ItemType.add("playPause");
ItemType.add("currentPlayback");
ItemType.add("queue");
ItemType.add("picture");
var PlayerMode = new Enum("PlayerMode");
PlayerMode.add("playback");
Player.ItemType = ItemType;