@swrve/smarttv-sdk
Version:
Swrve marketing engagement platform SDK for SmartTV OTT devices
211 lines (210 loc) • 7.7 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const base_1 = __importDefault(require("./base"));
const IPlatform_1 = require("./IPlatform");
const SwrveLogger_1 = __importDefault(require("../SwrveLogger"));
/**
* Samsung platform
*/
class SamsungPlatform extends base_1.default {
constructor(config) {
super();
this.tizenKeyMapping = {
38: "Up",
40: "Down",
37: "Left",
39: "Right",
13: "Enter",
403: "ColorF0Red",
404: "B",
405: "C",
406: "D",
10009: "Back",
415: "Play",
417: "FastForward",
412: "Rewind",
413: "Stop",
10252: "PlayPause",
19: "Pause",
65376: "Done",
65385: "Cancel",
};
// this platform does not need a proxy.
this.needsProxy = false;
if (config) {
this.config = config;
if (config.customKeyMappingTizen) {
this.tizenKeyMapping = config.customKeyMappingTizen;
}
}
}
name() {
var _a, _b;
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.customDeviceName) {
return (_b = this.config) === null || _b === void 0 ? void 0 : _b.customDeviceName;
}
else {
return {
name: "Samsung",
variation: "Tizen",
};
}
}
exit(toMenu = false) {
if (toMenu) {
tizen.application.getCurrentApplication().hide();
}
else {
tizen.application.getCurrentApplication().exit();
}
}
init(deviceProperties = []) {
super.init(deviceProperties);
tizen.tvinputdevice.registerKey("0");
tizen.tvinputdevice.registerKey("1");
tizen.tvinputdevice.registerKey("2");
tizen.tvinputdevice.registerKey("3");
tizen.tvinputdevice.registerKey("4");
tizen.tvinputdevice.registerKey("5");
tizen.tvinputdevice.registerKey("6");
tizen.tvinputdevice.registerKey("7");
tizen.tvinputdevice.registerKey("8");
tizen.tvinputdevice.registerKey("9");
tizen.tvinputdevice.registerKey("MediaPlay");
tizen.tvinputdevice.registerKey("MediaPause");
tizen.tvinputdevice.registerKey("MediaFastForward");
tizen.tvinputdevice.registerKey("MediaRewind");
tizen.tvinputdevice.registerKey("MediaStop");
tizen.tvinputdevice.registerKey("ColorF0Red");
return deviceProperties.reduce((promise, property) => promise.then(() => this.getDeviceProperty(property)), Promise.resolve());
}
disableScreenSaver() {
if (typeof webapis !== "undefined") {
webapis.appcommon.setScreenSaver(webapis.appcommon.AppCommonScreenSaverState.SCREEN_SAVER_OFF);
}
else {
SwrveLogger_1.default.error("Tizen TV webapis are not loaded can not disable screensaver");
}
}
get firmware() {
if (this._firmware === undefined) {
this._firmware = webapis.productinfo.getFirmware();
}
return this._firmware || "";
}
get model() {
if (this._model === undefined) {
this._model = webapis.productinfo.getRealModel();
}
return this._model || "";
}
get os() {
var _a, _b;
return (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.customOS) !== null && _b !== void 0 ? _b : "tizen";
}
get osVersion() {
var _a, _b;
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.customOSVersion) {
return (_b = this.config) === null || _b === void 0 ? void 0 : _b.customOSVersion;
}
else {
if (this._osVersion === undefined) {
this._osVersion = tizen.systeminfo.getCapability("http://tizen.org/feature/platform.version");
}
return this._osVersion || "";
}
}
get language() {
return this._language || "";
}
get countryCode() {
return this._countryCode || "";
}
get appStore() {
var _a, _b;
return (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.customAppStore) !== null && _b !== void 0 ? _b : "tizen";
}
openLink(link) {
const appControl = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/view", link);
tizen.application.launchAppControl(appControl, null, () => {
SwrveLogger_1.default.info("launch application control succeed");
}, (e) => {
SwrveLogger_1.default.error("launch application control failed. reason: " + e.message);
});
}
getLanguage() {
if (this._language === undefined) {
return this.loadLocale().then(() => this._language || "");
}
return Promise.resolve(this._language || "");
}
getCountryCode() {
if (this._countryCode === undefined) {
return this.loadLocale().then(() => this._countryCode || "");
}
return Promise.resolve(this._countryCode || "");
}
getScreenHeight() {
if (this._screenHeight === undefined) {
return this.loadDisplay().then(() => this._screenHeight || 1080);
}
return Promise.resolve(this._screenHeight || 1080);
}
getScreenWidth() {
if (this._screenWidth === undefined) {
return this.loadDisplay().then(() => this._screenWidth || 1920);
}
return Promise.resolve(this._screenWidth || 1920);
}
getKeymapping() {
return this.tizenKeyMapping;
}
supportsHDR() {
return webapis.avinfo.isHdrTvSupport();
}
initNetworkListener() {
return webapis.network.addNetworkStateChangeListener((value) => {
if (value === webapis.network.NetworkState.GATEWAY_DISCONNECTED) {
this.triggerNetworkChange(IPlatform_1.NETWORK_DISCONNECTED);
}
else if (value === webapis.network.NetworkState.GATEWAY_CONNECTED) {
this.triggerNetworkChange(IPlatform_1.NETWORK_CONNECTED);
}
});
}
removeNetworkListener(handle) {
webapis.network.removeNetworkStateChangeListener(handle);
}
getDeviceProperty(property) {
switch (property) {
case "language":
return this.getLanguage();
case "countryCode":
return this.getCountryCode();
case "deviceHeight":
return this.getScreenHeight();
case "deviceWidth":
return this.getScreenWidth();
default:
return undefined;
}
}
loadLocale() {
return new Promise((resolve, reject) => tizen.systeminfo.getPropertyValue("LOCALE", (result) => {
this._language = result.language.split("_")[0];
this._countryCode = result.country.replace(/\..*$/, "").split("_")[1].toLowerCase();
resolve(result);
}));
}
loadDisplay() {
return new Promise((resolve, reject) => tizen.systeminfo.getPropertyValue("DISPLAY", (result) => {
this._screenHeight = (result.resolutionHeight > 0) ? result.resolutionHeight : 1080;
this._screenWidth = (result.resolutionWidth > 0) ? result.resolutionWidth : 1920;
resolve(result);
}));
}
}
exports.default = SamsungPlatform;