[v3 js] add and send x-wails-client-id

The constant x-wails-client-id is generated once on startup and then
sent with each request to the Wails host.  It is used primarily by
the server plugin to distinguish different remote sessions.
This commit is contained in:
Travis McLane
2023-09-28 12:14:54 -05:00
parent a9d4a393ba
commit 7e1d685167
2 changed files with 12 additions and 7 deletions
+5 -3
View File
@@ -1,6 +1,6 @@
/*
_ __ _ __
| | / /___ _(_) /____
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
@@ -15,6 +15,7 @@ import * as Application from './application';
import * as Screens from './screens';
import * as System from './system';
import {Plugin, Call, callErrorCallback, callCallback, CallByID, CallByName} from "./calls";
import {clientId} from './runtime';
import {newWindow} from "./window";
import {dispatchWailsEvent, Emit, Off, OffAll, On, Once, OnMultiple} from "./events";
import {dialogCallback, dialogErrorCallback, Error, Info, OpenFile, Question, SaveFile, Warning,} from "./dialogs";
@@ -25,6 +26,7 @@ import {setupDrag, endDrag} from "./drag";
window.wails = {
...newRuntime(null),
Capabilities: {},
clientId: clientId,
};
fetch("/wails/capabilities").then((response) => {
@@ -92,4 +94,4 @@ setupDrag();
document.addEventListener("DOMContentLoaded", function() {
reloadWML();
});
});
+7 -4
View File
@@ -1,6 +1,6 @@
/*
_ __ _ __
| | / /___ _(_) /____
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
@@ -9,6 +9,7 @@ The electron alternative for Go
*/
/* jshint esversion: 9 */
import { nanoid } from 'nanoid/non-secure';
const runtimeURL = window.location.origin + "/wails/runtime";
// Object Names
@@ -23,6 +24,7 @@ export const objectNames = {
Screens: 7,
System: 8,
}
export let clientId = nanoid();
function runtimeCall(method, windowName, args) {
let url = new URL(runtimeURL);
@@ -38,6 +40,8 @@ function runtimeCall(method, windowName, args) {
if (args) {
url.searchParams.append("args", JSON.stringify(args));
}
fetchOptions.headers["x-wails-client-id"] = clientId;
return new Promise((resolve, reject) => {
fetch(url, fetchOptions)
.then(response => {
@@ -75,6 +79,7 @@ function runtimeCallWithID(objectID, method, windowName, args) {
if (args) {
url.searchParams.append("args", JSON.stringify(args));
}
fetchOptions.headers["x-wails-client-id"] = clientId;
return new Promise((resolve, reject) => {
fetch(url, fetchOptions)
.then(response => {
@@ -98,5 +103,3 @@ export function newRuntimeCallerWithID(object, windowName) {
return runtimeCallWithID(object, method, windowName, args);
};
}