URL and Token provider
Summary: Use an URLProvider paired with a token provider for attempts to establish a websocket connection. This gives extra flexibility whenever a token is not available or changes as the ReconnectingWebSocket will call the URLProvider after each unsuccessful connection. Reviewed By: antonk52 Differential Revision: D50220329 fbshipit-source-id: f53993a90c9c0f64bf213019b6b8af5fa818048d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8cc35d74ef
commit
db4d15ed05
@@ -34,20 +34,26 @@ async function start() {
|
||||
setLoggerInstance(logger);
|
||||
|
||||
const params = new URL(location.href).searchParams;
|
||||
let token = params.get('token');
|
||||
if (!token) {
|
||||
console.info(
|
||||
'[flipper-client][ui-browser] Get token from manifest instead',
|
||||
);
|
||||
const manifestResponse = await fetch('manifest.json');
|
||||
const manifest = await manifestResponse.json();
|
||||
token = manifest.token;
|
||||
}
|
||||
|
||||
console.info(
|
||||
'[flipper-client][ui-browser] Token is available: ',
|
||||
token?.length != 0,
|
||||
);
|
||||
const tokenProvider = async () => {
|
||||
const providerParams = new URL(location.href).searchParams;
|
||||
let token = providerParams.get('token');
|
||||
if (!token) {
|
||||
console.info(
|
||||
'[flipper-client][ui-browser] Get token from manifest instead',
|
||||
);
|
||||
const manifestResponse = await fetch('manifest.json');
|
||||
const manifest = await manifestResponse.json();
|
||||
token = manifest.token;
|
||||
}
|
||||
|
||||
console.info(
|
||||
'[flipper-client][ui-browser] Token is available: ',
|
||||
token?.length != 0,
|
||||
);
|
||||
|
||||
return token;
|
||||
};
|
||||
|
||||
const openPlugin = params.get('open-plugin');
|
||||
if (openPlugin) {
|
||||
@@ -66,13 +72,11 @@ async function start() {
|
||||
cachedDeepLinkURL = deeplinkURL.toString();
|
||||
}
|
||||
|
||||
const searchParams = new URLSearchParams({token: token ?? ''});
|
||||
|
||||
console.info('[flipper-client][ui-browser] Create WS client');
|
||||
const flipperServer = await createFlipperServer(
|
||||
location.hostname,
|
||||
parseInt(location.port, 10),
|
||||
searchParams,
|
||||
tokenProvider,
|
||||
(state: FlipperServerState) => {
|
||||
switch (state) {
|
||||
case FlipperServerState.CONNECTING:
|
||||
@@ -213,7 +217,7 @@ async function initializePWA() {
|
||||
// getLogger() is not yet created when the electron app starts.
|
||||
// we can't create it here yet, as the real logger is wired up to
|
||||
// the redux store and the rest of the world. So we create a delegating logger
|
||||
// that uses a simple implementation until the real one comes available
|
||||
// that uses a simple implementation until the real one comes available.
|
||||
function createDelegatedLogger(): Logger {
|
||||
const naiveLogger: Logger = {
|
||||
track(...args: [any, any, any?, any?]) {
|
||||
|
||||
Reference in New Issue
Block a user