@kvaser/canking-api
Version:
CanKing API to communicate with the CanKing service using Node.js.
117 lines (116 loc) • 4.2 kB
TypeScript
/**
* This module includes CanKing data provider React components.
* The CanKingDataProvider component is needed to be at the root of the component tree to
* make it possible to use the CanKing UI Controls.
*
* @example
* ```tsx
* const container = document.getElementById('root') as HTMLElement;
* const root = createRoot(container);
* root.render(
* <React.StrictMode>
* <CanKingDataProvider>
* <App />
* </CanKingDataProvider>
* </React.StrictMode>,
* );
* ```
*
* @packageDocumentation
*/
import React from 'react';
import { Device, NodeStatus, LogMessage, MeasurementSetup, OnlineStatus, IUserSettings, IWorkspacePaneData } from '../models';
/**
* Possible CanKing event channels for an extension to listen to.
*/
type extensionEventChannels = 'devices-changed' | 'new-log-messages' | 'online-status-changed' | 'periodic-trans-started' | 'periodic-trans-stopped' | 'new-measurement-data' | 'new-measurement-status' | 'user-settings-changed' | 'meas-setup-changed' | 'workspace-panes-changed';
/**
* Starts a subscription to an event raised by CanKing.
*
* @typeParam T - Type of the data that will be sent by the event.
* @param key - A unique key for this subscription, this key should be used when calling removeEventListener to unsubcribe
* from the event. The uuid package can be used for generating unique keys.
* @param event - The event channel to subscibe to.
* @param callback - A callback that will be called when new data arrives on the channel.
* @param options - Optional options including following options:
* numberOfHistoryFrames - used when adding a 'new-measurement-data' event listener to control number of frames to read from history at initialization.
* @returns A promise that will resolve with start values for the event.
* @internal
*/
export declare function addEventListener<T>(key: string, event: extensionEventChannels, callback: (data: T) => void, options?: {
numberOfHistoryFrames?: number;
}): Promise<T>;
/**
* Unsubscribes from an event.
*
* @param key - The key that was used when addEventListener was called.
* @param event - The event channel to unsubscribe from.
* @internal
*/
export declare const removeEventListener: (key: string, event: extensionEventChannels) => Promise<void>;
/**
* The UserSettings context
* @internal
*/
export declare const UserSettingsContext: React.Context<IUserSettings>;
/**
* The Devices context
* @internal
*/
export declare const DevicesContext: React.Context<Device[]>;
/**
* The MeasurementStatus context
* @internal
*/
export declare const MeasurementStatusContext: React.Context<NodeStatus[]>;
/**
* The MeasurementSetup context
* @internal
*/
export declare const MeasurementSetupContext: React.Context<MeasurementSetup>;
/**
* The OnlineStatus context
* @internal
*/
export declare const OnlineStatusContext: React.Context<OnlineStatus>;
/**
* The RunningPeriodicTransmissions context
* @internal
*/
export declare const RunningPeriodicTransmissionsContext: React.Context<string[]>;
/**
* The LogMessages context
* @internal
*/
export declare const LogMessagesContext: React.Context<LogMessage[]>;
/**
* The WorkspacePanes context
* @internal
*/
export declare const WorkspacePanesContext: React.Context<[IWorkspacePaneData[], React.Dispatch<React.SetStateAction<IWorkspacePaneData[]>>]>;
/**
* Creates a data provider to access CanKing data.
* The CanKingDataProvider component is needed to be at the root of the component tree to
* make it possible to use the CanKing UI Controls.
*
* @example
* ```tsx
* const container = document.getElementById('root') as HTMLElement;
* const root = createRoot(container);
* root.render(
* <React.StrictMode>
* <CanKingDataProvider>
* <App />
* </CanKingDataProvider>
* </React.StrictMode>,
* );
* ```
*
* @param props Component properties.
* @returns The CanKingDataProvider React component.
*/
declare const CanKingDataProvider: ({ initialUserSettings, children, }: {
initialUserSettings?: IUserSettings;
children?: React.ReactNode;
}) => import("react/jsx-runtime").JSX.Element;
export default CanKingDataProvider;