Files
shoptime/com.twin.app.shoptime/src/lunaSend/common.js
2024-07-01 13:35:15 +09:00

298 lines
8.2 KiB
JavaScript

import appinfo from "../../webos-meta/appinfo.json";
import LS2Request from "./LS2Request";
export const getConnectionStatus = ({ onSuccess, onFailure, onComplete }) => {
if (process.env.REACT_APP_MODE === "DEBUG") {
console.log("LUNA SEND getConnectionStatus");
return "Some Hard Coded Mock Data";
} else {
return new LS2Request().send({
service: "luna://com.webos.service.connectionmanager",
method: "getStatus",
subscribe: true,
parameters: {},
onSuccess,
onFailure,
onComplete,
});
}
};
export const createToast = (message) => {
if (typeof window === "object" && !window.PalmSystem) {
console.log("LUNA SEND createToast message", message);
return;
}
return new LS2Request().send({
service: "luna://com.webos.notification",
method: "createToast",
parameters: {
message: message,
iconUrl: "",
noaction: true,
},
onSuccess: (res) => {
console.log("LUNA SEND createToast success", message);
},
onFailure: (err) => {
console.log("LUNA SEND createToast failed", err);
},
});
};
let httpHeaderHandler = null;
export const getHttpHeaderForServiceRequest = ({
onSuccess,
onFailure,
onComplete,
}) => {
if (
typeof window === "object" &&
window.PalmSystem &&
process.env.REACT_APP_MODE !== "DEBUG"
) {
if (httpHeaderHandler) {
httpHeaderHandler.cancel();
}
httpHeaderHandler = new LS2Request().send({
service: "luna://com.webos.service.sdx",
method: "getHttpHeaderForServiceRequest",
subscribe: true,
parameters: {},
onSuccess,
onFailure,
onComplete,
});
return httpHeaderHandler;
} else {
onSuccess({
HOST: "GB.nextlgsdp.com",
"X-User-Number": "US2210240095608",
Authorization:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJuZXh0bGdzZHAuY29tIiwiYXVkIjoibmV4dGxnc2RwLmNvbSIsImlhdCI6MTcwNzc4NTUyNSwiZXhwIjoxNzA3NzkyNzI1LCJtYWNBZGRyZXNzIjoiZWVkMDQ2NjdiNjUzOWU3YmQxMDA1OTljYjBkYTI5ZjRjZTgyZGZlOGZkNzIzMDAxZGVmMjg4NWRkNWZiODRmNWNiMzZlM2QwNzYzNWZjZGJjYWNjNGVjMzI5NWIwNjZjOTMwNmNmNDI1ZGQzMmQ2MDMxMjc1NWNkOTIyNjEwMzcifQ.vqPdYGnN46diesDBLzA4UhACCJVdIycLs7wZu9M55Hc",
"X-Authentication": "MkOLvUocrJ69RH/iV1ZABJhjR2g=",
"X-Device-ID":
"OemUY5qbPITZv96QKlxrtcqT6ypeX6us2qANLng3/0QCUhv2mecK1UDTMYb/hjpjey9dC/kFycc/5R8u+oK56JIWyYC4V278z64YDPKbDXIsd+eECvyf+Rdm8BneIUPM",
"X-Device-Product": "webOSTV 5.0",
"X-Device-Platform": "W20P",
"X-Device-Model": "HE_DTV_W20P_AFADATAA",
"X-Device-Eco-Info": "1",
"X-Device-Country": "GB",
"X-Device-Language": "en-GB",
"X-Device-Netcast-Platform-Version": "6.0.0",
"X-Device-Publish-Flag": "N",
"X-Device-Fck": "253",
"X-Device-Eula":
"additionalDataAllowed,takeOnAllowed,networkAllowed,generalTermsAllowed,chpAllowed,customAdAllowed,acrOnAllowed,voice2Allowed,voiceAllowed,acrAdAllowed",
});
}
};
export const getSystemSettings = (
parameters,
{ onSuccess, onFailure, onComplete }
) => {
if (
typeof window === "object" &&
window.PalmSystem &&
process.env.REACT_APP_MODE !== "DEBUG"
) {
return new LS2Request().send({
service: "luna://com.webos.settingsservice",
method: "getSystemSettings",
subscribe: true,
parameters: parameters,
onSuccess,
onFailure,
onComplete,
});
} else if (typeof window === "object") {
const language =
typeof window.navigator === "object"
? window.navigator.language || window.navigator.userLanguage
: "en-US";
const res = {
settings: {
smartServiceCountryCode2: language.split("-")[1],
captionEnable: true,
},
returnValue: true,
};
onSuccess(res);
onComplete(res);
}
};
export function checkValidCountry(ricCode, country) {
if (ricCode === "aic") {
if (country === "US") return true;
else return false;
} else if (ricCode === "eic") {
if (country === "GB" || country === "DE") return true;
else return false;
} else if (ricCode === "ruc") {
if (country === "RU") return true;
else return false;
} else {
if (country === "US") {
return true;
} else {
return false;
}
}
}
// 3.0 ~ 4.5
export const setSubtitleEnable = (
mediaId,
captionEnable,
{ onSuccess, onFailure, onComplete }
) => {
if (
typeof window === "object" &&
window.PalmSystem &&
process.env.REACT_APP_MODE !== "DEBUG"
) {
if (captionEnable) {
return new LS2Request().send({
service: "luna://com.webos.service.tv.subtitle",
method: "enableSubtitle",
parameters: { pipelineId: mediaId },
onSuccess,
onFailure,
onComplete,
});
} else {
return new LS2Request().send({
service: "luna://com.webos.service.tv.subtitle",
method: "disableSubtitle",
parameters: { pipelineId: mediaId },
onSuccess,
onFailure,
onComplete,
});
}
}
};
// 5.0
export const setSubtitleEnableOver5 = (
mediaId,
captionEnable,
{ onSuccess, onFailure, onComplete }
) => {
if (typeof window === "object" && window.PalmSystem) {
return new LS2Request().send({
service: "luna://com.webos.media",
method: "setSubtitleEnable",
parameters: { enable: captionEnable, mediaId: mediaId },
onSuccess,
onFailure,
onComplete,
});
}
};
// system Alert
export const addReservation = (data) => {
if (typeof window === "object" && !window.PalmSystem) {
console.log("LUNA SEND addReservation data", data);
return;
}
return new LS2Request().send({
service: "luna://com.webos.service.tvReservationAgent",
method: "add",
parameters: {
scheduleType: "LGShopping",
startTime: {
year: data.startTime.year,
month: data.startTime.month,
day: data.startTime.day,
hour: data.startTime.hour,
minute: data.startTime.minute,
second: data.startTime.second,
},
callback: {
method: "luna://com.webos.notification/createAlert",
params: {
message: data.params.message,
buttons: [
{
label: data.params.buttons[0].label,
onclick: "luna://com.webos.applicationManager/launch",
params: {
id: window.PalmSystem.identifier ?? appinfo.id,
params: data.params.launch,
},
},
{
label: data.params.buttons[1].label,
},
],
// todo pyh, delete, test case
autoTimeout: 60 * 5,
// autoTimeout: 30,
},
},
information: {
showId: data.params.showId,
chinId: data.params.chanId,
},
},
onSuccess: (res) => {
console.log("LUNA SEND addReservation success", res);
},
onFailure: (err) => {
console.log("LUNA SEND addReservation failed", err);
},
});
};
export const deleteReservation = (scheduleIdList) => {
if (typeof window === "object" && !window.PalmSystem) {
console.log("LUNA SEND deleteReservation scheduleIdList", scheduleIdList);
return;
}
return new LS2Request().send({
service: "luna://com.webos.service.tvReservationAgent",
method: "delete",
parameters: {
scheduleIdList: scheduleIdList,
},
onSuccess: (res) => {
console.log("LUNA SEND deleteReservation success", res);
},
onFailure: (err) => {
console.log("LUNA SEND deleteReservation failed", err);
},
});
};
export const searchReservation = (chanId) => {
if (typeof window === "object" && !window.PalmSystem) {
console.log("LUNA SEND searchReservation chanId", chanId);
return;
}
return new LS2Request().send({
service: "luna://com.palm.db",
method: "search",
parameters: {
query: {
from: "com.webos.service.tvReservationAgent.info:1",
orderBy: "startTime",
filter: [{ prop: "reserveType", op: "=", val: 6 }], // 6 LG Shopping 전용.
},
},
onSuccess: (res) => {
console.log("LUNA SEND searchReservation success", res);
},
onFailure: (err) => {
console.log("LUNA SEND searchReservation failed", err);
},
});
};