glowers-radio/lib/RadioPreview.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

"use-strict";
const { objSerialize, notNullElse } = require("./util.js")
/**
* @public
* @readonly
* @enum {number}
*/
const EDisplayType = {
"NATIVE": -1,
"LANDSCAPE": 0,
"SQUARE": 1,
"STRETCH": 2
}
/**
* @public
* @constructor
* @params {string} uri
* @params {string} type
* @params {string[]} codecs
* @params {String} size
* @params {EDisplayType} [displayType=null] size
* @returns {RadioPreview}
*/
const RadioPreview = function (uri, type, codecs, size, displayType=null) {
this.uri = uri
this.type = type
this.codecs = codecs?.length ? codecs : undefined
this.size = size.replace(/x/g, "×")
this.display_type = displayType
return this
}
/**
* @public
* @params {string} uri
* @params {string} type
* @params {string[]} codecs
* @params {String} size
* @params {EDisplayType} [displayType=null] size
* @returns {RadioPreview}
*/
RadioPreview.new = (uri, type, codecs, size, displayType) => new RadioPreview(uri, type, codecs, size, displayType)
/**
* @deprecated
* @params {RadioSource} radioSource
* @returns {Object}
*/
RadioPreview.prototype.serialize = function (radioSource) {
this.display_type = notNullElse(this.display_type, radioSource.type.startsWith("video/") ? EDisplayType.NATIVE : EDisplayType.SQUARE)
return objSerialize(this, [
"display_type",
"type",
"codecs",
"size",
"uri"
])
}
module.exports = { RadioPreview, EDisplayType }