51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
export const RPC = {
|
|
__session: "none",
|
|
__invoke: async function (method, params) {
|
|
const __this = this;
|
|
const resp = await fetch(
|
|
"/rpc",
|
|
{
|
|
method: "POST",
|
|
mode: "cors",
|
|
cache: "no-cache",
|
|
credentials: "include",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"X-Auth": __this.__session
|
|
},
|
|
redirect: "follow",
|
|
referrerPolicy: "no-referrer",
|
|
body: JSON.stringify({
|
|
jsonrpc: '2.0',
|
|
method: method,
|
|
params: params,
|
|
id: __this.__id++
|
|
})
|
|
}
|
|
);
|
|
const success = resp.status === 200;
|
|
const result = (success ? (await resp.json()).result : {
|
|
"error": true,
|
|
"code": resp.status,
|
|
"status": resp.statusText,
|
|
"body": await resp.text()
|
|
});
|
|
|
|
return {
|
|
"result": result,
|
|
"success": success
|
|
};
|
|
},
|
|
__id: 1,
|
|
|
|
TestSession: async function () {
|
|
return (await this.__invoke("TestSession", [])).success;
|
|
},
|
|
GetCurrentScene: async function () {
|
|
return (await this.__invoke("GetCurrentScene", [])).result;
|
|
},
|
|
|
|
GetSceneHierarchy: async function (sceneName) {
|
|
return (await this.__invoke("GetSceneHierarchy", [sceneName])).result;
|
|
},
|
|
} |