a draft of player view, debug

This commit is contained in:
Blue 2018-10-29 00:32:44 +03:00 committed by Gitea
parent 46560924ce
commit c8b432fe57
13 changed files with 183 additions and 33 deletions

View file

@ -19,6 +19,7 @@
defineArray.push("lib/wController/pageStorage");
defineArray.push("lib/wController/page");
defineArray.push("lib/wController/localModel");
defineArray.push("lib/wController/player");
defineArray.push("views/view");
defineArray.push("views/layout");
@ -43,6 +44,7 @@
var PageStorage = require("lib/wController/pageStorage");
var PageController = require("lib/wController/page");
var LocalModel = require("lib/wController/localModel");
var PlayerModel = require("lib/wController/player");
var View = require("views/view");
var Layout = require("views/layout");
@ -204,9 +206,20 @@
var node = this._nodes[name];
node.connected = false;
switch (name) {
case "Corax":
if (this._playerCtl) {
this._mainLayout.removePlayer();
this._playerCtl._onSocketDisconnected();
this._playerCtl.uneregister();
this._playerCtl.destructor();
this._playerCtl = undefined;
}
}
for (var id in node.foreigns) {
if (node.foreigns[id].subscribed) {
node.foreigns[id].controller._onSocketDisconnected;
node.foreigns[id].controller._onSocketDisconnected();
}
}
node.state.setData(SocketState.straight.disconnected);
@ -242,14 +255,14 @@
this._nodes[name] = obj;
},
"registerForeignController": function(node, controller) {
var node = this._nodes[node];
"registerForeignController": function(nodeName, controller) {
var node = this._nodes[nodeName];
if (node === undefined) {
throw new Error("An attempt to register controller to an unknown node " + node);
throw new Error("An attempt to register controller to an unknown node " + nodeName);
}
if (node.foreigns[controller.id] !== undefined) {
throw new Error("An attempt to register a controller under node " + node + " for a second time");
throw new Error("An attempt to register a controller under node " + nodeName + " for a second time");
}
var obj = Object.create(null);
obj.controller = controller;
@ -271,43 +284,46 @@
"_responsePlayer": function(ev) {
var data = ev.getData();
console.log('Received player address: ' + data.at("address").toString());
this._playerCtl = new PlayerModel(data.at("address").clone());
this._playerCtl.register(this.dispatcher, this._nodes["Corax"].socket);
this._playerCtl.subscribe();
this._mainLayout.appendPlayer(this._playerCtl);
},
"setTheme": function(theme) {
View.setTheme(theme);
},
"subscribeForeignController": function(node, controller) {
var node = this._nodes[node];
"subscribeForeignController": function(nodeName, controller) {
var node = this._nodes[nodeName];
if (node === undefined) {
throw new Error("An attempt to subscribe a controller to an unknown node " + node);
throw new Error("An attempt to subscribe a controller to an unknown node " + nodeName);
}
if (node.foreigns[controller.id] === undefined) {
throw new Error("An attempt to subscribe not registered controller to node " + node);
throw new Error("An attempt to subscribe not registered controller to node " + nodeName);
}
node.foreigns[controller.id].subscribed = true;
controller.subscribe();
},
"unregisterForeignController": function(node, controller) {
var node = this._nodes[node];
"unregisterForeignController": function(nodeName, controller) {
var node = this._nodes[nodeName];
if (node === undefined) {
throw new Error("An attempt to unregister a controller from an unknown node " + node);
throw new Error("An attempt to unregister a controller from an unknown node " + nodeName);
}
if (node.foreigns[controller.id] === undefined) {
throw new Error("An attempt to unregister not registered controller from node " + node);
throw new Error("An attempt to unregister not registered controller from node " + nodeName);
}
delete node.foreigns[controller.id];
controller.unregister();
},
"unsubscribeForeignController": function(node, controller) {
var node = this._nodes[node];
"unsubscribeForeignController": function(nodeName, controller) {
var node = this._nodes[nodeName];
if (node === undefined) {
throw new Error("An attempt to unsubscribe a controller from an unknown node " + node);
throw new Error("An attempt to unsubscribe a controller from an unknown node " + nodeName);
}
if (node.foreigns[controller.id] === undefined) {
throw new Error("An attempt to unsubscribe not registered controller from node " + node);
throw new Error("An attempt to unsubscribe not registered controller from node " + nodeName);
}
node.foreigns[controller.id].subscribed = false;
controller.unsubscribe();

View file

@ -18,3 +18,4 @@ add_jslib(wController/imagePane.js lib/wController/imagePane ${LORGAR_DIR} brows
add_jslib(wController/file/file.js lib/wController/file/file ${LORGAR_DIR} browser)
add_jslib(wController/image.js lib/wController/image ${LORGAR_DIR} browser)
add_jslib(wController/button.js lib/wController/button ${LORGAR_DIR} browser)
add_jslib(wController/player.js lib/wController/player ${LORGAR_DIR} browser)

View file

@ -13,5 +13,6 @@ configure_file(pane.js pane.js)
configure_file(image.js image.js)
configure_file(button.js button.js)
configure_file(enumeration.js enumeration.js)
configure_file(player.js player.js)
add_subdirectory(helpers)

View file

@ -9,6 +9,7 @@
defineArray.push("views/navigationPanel");
defineArray.push("views/layout");
defineArray.push("views/enumeration");
defineArray.push("views/player");
defineArray.push("lib/wController/localModel");
define(moduleName, defineArray, function mainLayout_module() {
@ -18,6 +19,7 @@
var ViewNavigationPanel = require("views/navigationPanel");
var Layout = require("views/layout");
var Enumeration = require("views/enumeration");
var Player = require("views/player");
var LocalModel = require("lib/wController/localModel");
var MainLayout = GridLayout.inherit({
@ -26,6 +28,7 @@
GridLayout.fn.constructor.call(this, controller, options);
this._statusBarPosition = 2;
this._player = undefined;
this._mainColorHelper = new LocalModel({backgroundColor: "mainColor"});
this._statusBarModel = new LocalModel({backgroundColor: "secondaryColor"});
@ -72,6 +75,21 @@
this._statusBar.append(e, 0, this._statusBarPosition++, 1, 1, Layout.Aligment.LeftCenter);
this._uncyclic.push(lm.destructor.bind(lm));
},
appendPlayer: function(playerModel) {
if (this._player !== undefined) {
throw new Error("An attempt to add player to main layout for the second time");
}
this._player = new Player(playerModel);
this.append(this._player, 2, 0, 1, 3);
},
removePlayer: function() {
if (this._player === undefined) {
throw new Error("An attempt to remove non existing player from mainLayout");
}
this.removeChild(this._player);
this._player.destructor();
this._player = undefined;
}
});

99
lorgar/views/player.js Normal file
View file

@ -0,0 +1,99 @@
"use strict";
(function() {
var moduleName = "views/player"
var deps = [];
deps.push("views/gridLayout");
deps.push("views/button");
deps.push("views/label");
deps.push("lib/wController/localModel");
deps.push("lib/utils/enum");
define(moduleName, deps, function() {
var GridLayout = require("views/gridLayout");
var Button = require("views/button");
var Label = require("views/label");
var Model = require("lib/wController/localModel");
var Enum = require("lib/utils/enum");
var Player = GridLayout.inherit({
className: "Player",
constructor: function(ctrl, options) {
GridLayout.fn.constructor.call(this, ctrl, options);
this._playPause = null;
this._cpbCtrl = null;
this._infoModels = {
artist: new Model(null, "artist: unknown"),
album: new Model(null, "album: unknown"),
song: new Model(null, "song: unknown")
}
ctrl.on("newElement", this._onNewElement, this);
var artist = new Label(this._infoModels.artist);
var album = new Label(this._infoModels.album);
var song = new Label(this._infoModels.song);
this.append(artist, 0, 2, 1, 1)
this.append(song, 1, 2, 1, 1)
this.append(album, 2, 2, 1, 1)
this._uncyclic.push(this._infoModels.artist.destructor.bind(this._infoModels.artist));
this._uncyclic.push(this._infoModels.song.destructor.bind(this._infoModels.song));
this._uncyclic.push(this._infoModels.album.destructor.bind(this._infoModels.album));
},
destructor: function() {
this._f.off("newElement", this._onNewElement, this);
this._clearCpbCtrl();
GridLayout.fn.destructor.call(this);
},
_clearCpbCtrl: function() {
if (this._cpbCtrl !== null) {
this._cpbCtrl.off("newElement", this._onCpbNewElement, this);
this._cpbCtrl.off("removeElement", this._onCpbRemoveElement, this);
this._cpbCtrl = null;
}
},
_onNewElement: function(ctrl, type) {
var ItemType = Enum.storage["ItemType"];
switch (type) {
case ItemType.straight.playPause:
this._playPause = new Button(ctrl);
this.append(this._playPause, 0, 1, 3, 1);
break;
case ItemType.straight.queue:
break;
case ItemType.straight.currentPlayback:
this._clearCpbCtrl();
this._cpbCtrl = ctrl;
this._cpbCtrl.on("newElement", this._onCpbNewElement, this);
this._cpbCtrl.on("removeElement", this._onCpbRemoveElement, this);
break;
}
},
_onCpbNewElement: function(key, value) {
var model = this._infoModels[key];
if (model) {
model.setData(key + ": " + value.toString());
}
},
_onCpbRemoveElement: function(key) {
var model = this._infoModels[key];
if (model) {
model.setData(key + ": unknown");
}
}
});
return Player;
});
})()

View file

@ -54,7 +54,9 @@
for (var i = 0; i < this._f._controllers.length; ++i) {
this._onNewController(this._f._controllers[i]);
}
this._onData(this._f);
//if (this._f.initialized) {
this._onData(this._f);
//}
View.collection[this._id] = this;
this._applyProperties();