1 | import { Polling } from "./polling.js";
|
2 | import { Emitter } from "@socket.io/component-emitter";
|
3 | import type { SocketOptions } from "../socket.js";
|
4 | import type { CookieJar } from "../globals.node.js";
|
5 | import type { RawData } from "engine.io-parser";
|
6 | export declare abstract class BaseXHR extends Polling {
|
7 | protected readonly xd: boolean;
|
8 | private pollXhr;
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
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 |
|
32 |
|
33 |
|
34 |
|
35 | doPoll(): void;
|
36 | }
|
37 | interface RequestReservedEvents {
|
38 | success: () => void;
|
39 | data: (data: RawData) => void;
|
40 | error: (err: number | Error, context: unknown) => void;
|
41 | }
|
42 | export type RequestOptions = SocketOptions & {
|
43 | method?: string;
|
44 | data?: RawData;
|
45 | xd: boolean;
|
46 | cookieJar: CookieJar;
|
47 | };
|
48 | export 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 |
|
61 |
|
62 |
|
63 |
|
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 | */
|
104 | export declare class XHR extends BaseXHR {
|
105 | constructor(opts: any);
|
106 | request(opts?: Record<string, any>): Request;
|
107 | }
|
108 | export {};
|