@octalmage/node-appletv
Version:
A Node.js library for communicating with an Apple TV
56 lines (55 loc) • 2.17 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class NowPlayingInfo {
constructor(message) {
this.message = message;
let nowPlayingInfo = message.nowPlayingInfo;
if (nowPlayingInfo) {
this.duration = nowPlayingInfo.duration;
this.elapsedTime = nowPlayingInfo.elapsedTime;
this.title = nowPlayingInfo.title;
this.artist = nowPlayingInfo.artist;
this.album = nowPlayingInfo.album;
this.timestamp = nowPlayingInfo.timestamp;
}
this.appDisplayName = message.displayName;
this.appBundleIdentifier = message.displayID;
if (message.playbackState == 2) {
this.playbackState = NowPlayingInfo.State.Paused;
}
else if (message.playbackState == 1) {
this.playbackState = NowPlayingInfo.State.Playing;
}
}
percentCompleted() {
if (!this.elapsedTime || !this.duration) {
return "0.00";
}
return ((this.elapsedTime / this.duration) * 100).toPrecision(3);
}
toString() {
if (this.artist) {
let album = this.album == null ? '' : " -- " + this.album + " ";
return this.title + " by " + this.artist + album + " (" + this.percentCompleted() + "%) | "
+ this.appDisplayName + " (" + this.appBundleIdentifier + ") | "
+ this.playbackState;
}
else if (this.title) {
return this.title + " (" + this.percentCompleted() + "%) | "
+ this.appDisplayName + " (" + this.appBundleIdentifier + ") | "
+ this.playbackState;
}
else {
return this.appDisplayName + " (" + this.appBundleIdentifier + ") | "
+ this.playbackState;
}
}
}
exports.NowPlayingInfo = NowPlayingInfo;
(function (NowPlayingInfo) {
let State;
(function (State) {
State["Playing"] = "playing";
State["Paused"] = "paused";
})(State = NowPlayingInfo.State || (NowPlayingInfo.State = {}));
})(NowPlayingInfo = exports.NowPlayingInfo || (exports.NowPlayingInfo = {}));