import { Logger, LogLevelDesc } from 'loglevel'; import { Decoder } from '@nuintun/qrcode'; declare abstract class FrameProcessor { protected _ctx: CanvasRenderingContext2D | null; protected _canvas: HTMLCanvasElement; protected _width: number; protected _height: number; protected _log: Logger; constructor(); /** * Sets the specified frame on the canvas. * * @param {HTMLVideoElement | HTMLImageElement | ImageBitmap} source - The source to draw on the canvas. * @throws Will throw an error if an unsupported frame type is provided. */ protected setFrame( source: HTMLVideoElement | HTMLImageElement | ImageBitmap ): void; /** * Retrieves QR code data from the current frame. * * @returns {QRCode | null} The decoded QR code data, or null if no data was found. */ protected getFrameData(): ReturnType | null; abstract read(file?: File): Promise; } type MediaType = 'display' | 'camera'; type MediaOptions = DisplayMediaStreamOptions | MediaStreamConstraints; /** * A class that processes WebRTC media streams, such as video from a camera or display, * and extracts QR code data from the frames. * * @extends FrameProcessor */ declare class WebRTCProcessor extends FrameProcessor { protected _video: HTMLVideoElement | undefined; protected _track: MediaStreamTrack | undefined; protected _mediaType: MediaType; protected _mediaOptions: MediaOptions; protected _allFrames: Set; protected _numExpectedFrames: number | undefined; /** * Creates an instance of WebRTCProcessor. * * @param {MediaType} [mediaType='display'] - Type of media to process ('display' or 'camera'). * @param {MediaOptions} [options={ video: true, audio: false }] - Media stream options for capturing video/audio. */ constructor(mediaType?: MediaType, options?: MediaOptions); /** * Cleans up by removing the canvas and video elements. */ protected destroy(): void; /** * Processes all frames and decodes QR codes from the video stream. * * @returns {Promise} A promise that resolves with an array of QR code data strings. */ protected processAllFrames(): Promise; /** * Processes a single frame, decodes it, and updates the QR code data set. */ protected processSingleFrame(): void; /** * Starts the video element and begins capturing the video stream. * If no track has been set, it selects the first available track. * * @returns {Promise} A promise that resolves when the video starts playing. */ protected startVideo(): Promise; /** * Captures video tracks from the media stream based on the selected media type. * * @returns {Promise} A promise that resolves with the video tracks. */ getStreamTracks(): Promise; /** * Sets the media stream track for processing. * * @param {MediaStreamTrack} track - The media stream track to set. */ setStreamTrack(track: MediaStreamTrack): void; /** * Reads and processes the video stream to extract and decode QR codes. * * @returns {Promise} A promise that resolves with the decoded QR code data as a string. */ read(): Promise; } /** * Class for processing image or GIF files to extract QR code data. * * @extends FrameProcessor */ declare class FileProcessor extends FrameProcessor { protected _file?: File; /** * Constructs a new FileProcessor instance. */ constructor(); /** * Cleans up by removing the canvas element from the DOM. */ protected destroy(): void; /** * Processes a single image frame and extracts QR code data. * * @returns {Promise} A promise that resolves to the extracted QR code data, or an empty string if no data is found. */ protected processSingleFrame(file: File): Promise; /** * Processes all frames in a GIF file and extracts QR code data from each frame. * * @returns {Promise} A promise that resolves to an array of QR code data from each frame. */ protected processAllFrames(): Promise; /** * Determines whether the provided file is a GIF image. * * @param {File} file - The file to check. * @returns {boolean} True if the file is a GIF, false otherwise. */ protected isGIF(file: File): boolean; /** * Reads and processes the file (either single frame or GIF) to extract QR code data. * * @param {File} file - The file to process. * @returns {Promise} A promise that resolves to the processed QR code data as a string. */ read(file: File): Promise; } interface ReaderProps { logLevel: LogLevelDesc; frameProcessor: FrameProcessor; } /** * Class representing a Reader. */ declare class Reader { private log; opts: ReaderProps; /** * Creates an instance of Reader. * * @param {Partial} [opts={}] - The options for the Reader. */ constructor(opts?: Partial); /** * Reads a frame using the frame processor. * * @param {File} [file] - The file to read. * @returns {Promise} - A promise that resolves to the read frame. */ read(file?: File): Promise; } export { FileProcessor, FrameProcessor, Reader, WebRTCProcessor };