mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
|
import type { KubeAuthUpdate } from "../../common/cluster-types";
|
|
import type { Cluster } from "../../common/cluster/cluster";
|
|
import broadcastMessageInjectable from "../../common/ipc/broadcast-message.injectable";
|
|
import { loggerInjectable } from "@k8slens/logger";
|
|
|
|
export type BroadcastConnectionUpdate = (update: KubeAuthUpdate) => void;
|
|
|
|
const broadcastConnectionUpdateInjectable = getInjectable({
|
|
id: "broadcast-connection-update",
|
|
instantiate: (di, cluster): BroadcastConnectionUpdate => {
|
|
const broadcastMessage = di.inject(broadcastMessageInjectable);
|
|
const logger = di.inject(loggerInjectable);
|
|
|
|
return (update) => {
|
|
logger.debug(`[CLUSTER]: broadcasting connection update`, { ...update, meta: cluster.getMeta() });
|
|
broadcastMessage(`cluster:${cluster.id}:connection-update`, update);
|
|
};
|
|
},
|
|
lifecycle: lifecycleEnum.keyedSingleton({
|
|
getInstanceKey: (di, cluster: Cluster) => cluster.id,
|
|
}),
|
|
});
|
|
|
|
export default broadcastConnectionUpdateInjectable;
|