UNPKG

2.52 kBTypeScriptView Raw
1import { Polling } from "./polling.js";
2import { Emitter } from "@socket.io/component-emitter";
3import type { SocketOptions } from "../socket.js";
4import type { CookieJar } from "../globals.node.js";
5import type { RawData } from "engine.io-parser";
6export declare abstract class BaseXHR extends Polling {
7 protected readonly xd: boolean;
8 private pollXhr;
9 /**
10 * XHR Polling constructor.
11 *
12 * @param {Object} opts
13 * @package
14 */
15 constructor(opts: any);
16 /**
17 * Creates a request.
18 *
19 * @private
20 */
21 abstract request(opts?: Record<string, any>): any;
22 /**
23 * Sends data.
24 *
25 * @param {String} data to send.
26 * @param {Function} called upon flush.
27 * @private
28 */
29 doWrite(data: any, fn: any): void;
30 /**
31 * Starts a poll cycle.
32 *
33 * @private
34 */
35 doPoll(): void;
36}
37interface RequestReservedEvents {
38 success: () => void;
39 data: (data: RawData) => void;
40 error: (err: number | Error, context: unknown) => void;
41}
42export type RequestOptions = SocketOptions & {
43 method?: string;
44 data?: RawData;
45 xd: boolean;
46 cookieJar: CookieJar;
47};
48export declare class Request extends Emitter<Record<never, never>, Record<never, never>, RequestReservedEvents> {
49 private readonly createRequest;
50 private readonly _opts;
51 private readonly _method;
52 private readonly _uri;
53 private readonly _data;
54 private _xhr;
55 private setTimeoutFn;
56 private _index;
57 static requestsCount: number;
58 static requests: {};
59 /**
60 * Request constructor
61 *
62 * @param {Object} options
63 * @package
64 */
65 constructor(createRequest: (opts: RequestOptions) => XMLHttpRequest, uri: string, opts: RequestOptions);
66 /**
67 * Creates the XHR object and sends the request.
68 *
69 * @private
70 */
71 private _create;
72 /**
73 * Called upon error.
74 *
75 * @private
76 */
77 private _onError;
78 /**
79 * Cleans up house.
80 *
81 * @private
82 */
83 private _cleanup;
84 /**
85 * Called upon load.
86 *
87 * @private
88 */
89 private _onLoad;
90 /**
91 * Aborts the request.
92 *
93 * @package
94 */
95 abort(): void;
96}
97/**
98 * HTTP long-polling based on the built-in `XMLHttpRequest` object.
99 *
100 * Usage: browser
101 *
102 * @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
103 */
104export declare class XHR extends BaseXHR {
105 constructor(opts: any);
106 request(opts?: Record<string, any>): Request;
107}
108export {};