expo 54.0.0-canary-20250722-599a28f → 54.0.0-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/ExpoReactHostFactory.kt +1 -7
- package/android/src/main/java/expo/modules/ReactActivityDelegateWrapper.kt +8 -8
- package/android/src/main/java/expo/modules/ReactNativeHostWrapper.kt +0 -5
- package/android/src/test/resources/robolectric.properties +1 -0
- package/build/Expo.d.ts +9 -1
- package/build/Expo.d.ts.map +1 -1
- package/build/async-require/fetchAsync.native.d.ts.map +1 -1
- package/build/async-require/hmr.d.ts.map +1 -1
- package/build/winter/FormData.d.ts.map +1 -1
- package/build/winter/fetch/RequestUtils.d.ts.map +1 -1
- package/build/winter/fetch/convertFormData.d.ts.map +1 -1
- package/build/winter/installGlobal.d.ts +25 -0
- package/build/winter/installGlobal.d.ts.map +1 -0
- package/bundledNativeModules.json +94 -92
- package/devtools.d.ts +1 -1
- package/devtools.js +1 -1
- package/internal/babel-preset.d.ts +2 -0
- package/internal/babel-preset.js +2 -0
- package/internal/unstable-autolinking-exports.d.ts +2 -0
- package/internal/unstable-autolinking-exports.js +2 -0
- package/internal/unstable-expo-updates-cli-exports.d.ts +2 -0
- package/internal/unstable-expo-updates-cli-exports.js +2 -0
- package/ios/AppDelegates/ExpoAppDelegate.swift +1 -1
- package/ios/AppDelegates/ExpoReactNativeFactory.swift +2 -2
- package/ios/AppDelegates/ExpoReactNativeFactoryDelegate.swift +1 -1
- package/ios/AppDelegates/RCTAppDelegateUmbrella.h +5 -0
- package/ios/Fetch/ExpoFetchCustomExtension.swift +1 -1
- package/ios/Fetch/ExpoFetchModule.swift +3 -3
- package/ios/Fetch/ExpoURLSessionTask.swift +2 -2
- package/ios/Fetch/NativeRequest.swift +1 -1
- package/ios/Fetch/NativeResponse.swift +2 -2
- package/package.json +27 -24
- package/src/Expo.ts +4 -0
- package/src/async-require/fetchAsync.native.ts +48 -10
- package/src/async-require/hmr.ts +1 -2
- package/src/async-require/messageSocket.native.ts +0 -3
- package/src/winter/FormData.ts +1 -9
- package/src/winter/fetch/RequestUtils.ts +15 -1
- package/src/winter/fetch/__tests__/convertFormData-test.native.ts +1 -3
- package/src/winter/fetch/convertFormData.ts +56 -27
- package/src/winter/installGlobal.ts +109 -0
- package/src/winter/runtime.native.ts +1 -20
- package/template.tgz +0 -0
- package/build/devtools/DevToolsPluginClient.d.ts +0 -72
- package/build/devtools/DevToolsPluginClient.d.ts.map +0 -1
- package/build/devtools/DevToolsPluginClientFactory.d.ts +0 -16
- package/build/devtools/DevToolsPluginClientFactory.d.ts.map +0 -1
- package/build/devtools/DevToolsPluginClientImplApp.d.ts +0 -15
- package/build/devtools/DevToolsPluginClientImplApp.d.ts.map +0 -1
- package/build/devtools/DevToolsPluginClientImplBrowser.d.ts +0 -14
- package/build/devtools/DevToolsPluginClientImplBrowser.d.ts.map +0 -1
- package/build/devtools/MessageFramePacker.d.ts +0 -50
- package/build/devtools/MessageFramePacker.d.ts.map +0 -1
- package/build/devtools/ProtocolVersion.d.ts +0 -7
- package/build/devtools/ProtocolVersion.d.ts.map +0 -1
- package/build/devtools/WebSocketBackingStore.d.ts +0 -10
- package/build/devtools/WebSocketBackingStore.d.ts.map +0 -1
- package/build/devtools/WebSocketWithReconnect.d.ts +0 -81
- package/build/devtools/WebSocketWithReconnect.d.ts.map +0 -1
- package/build/devtools/devtools.types.d.ts +0 -42
- package/build/devtools/devtools.types.d.ts.map +0 -1
- package/build/devtools/getConnectionInfo.d.ts +0 -6
- package/build/devtools/getConnectionInfo.d.ts.map +0 -1
- package/build/devtools/getConnectionInfo.native.d.ts +0 -6
- package/build/devtools/getConnectionInfo.native.d.ts.map +0 -1
- package/build/devtools/index.d.ts +0 -12
- package/build/devtools/index.d.ts.map +0 -1
- package/build/devtools/logger.d.ts +0 -6
- package/build/devtools/logger.d.ts.map +0 -1
- package/src/devtools/DevToolsPluginClient.ts +0 -240
- package/src/devtools/DevToolsPluginClientFactory.ts +0 -73
- package/src/devtools/DevToolsPluginClientImplApp.ts +0 -56
- package/src/devtools/DevToolsPluginClientImplBrowser.ts +0 -38
- package/src/devtools/MessageFramePacker.ts +0 -235
- package/src/devtools/ProtocolVersion.ts +0 -6
- package/src/devtools/WebSocketBackingStore.ts +0 -10
- package/src/devtools/WebSocketWithReconnect.ts +0 -318
- package/src/devtools/__tests__/DevToolsPluginClient-test.ts +0 -285
- package/src/devtools/__tests__/DevToolsPluginClientFactory-test.ts +0 -120
- package/src/devtools/__tests__/MessageFramePack-test.node.ts +0 -157
- package/src/devtools/__tests__/MockWebSocket.ts +0 -100
- package/src/devtools/__tests__/WebSocketWithReconnect-test.node.ts +0 -184
- package/src/devtools/__tests__/logger-test.ts +0 -20
- package/src/devtools/devtools.types.ts +0 -50
- package/src/devtools/getConnectionInfo.native.ts +0 -18
- package/src/devtools/getConnectionInfo.ts +0 -16
- package/src/devtools/index.ts +0 -53
- package/src/devtools/logger.ts +0 -29
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { DevToolsPluginClient } from './DevToolsPluginClient';
|
|
2
|
-
/**
|
|
3
|
-
* The DevToolsPluginClient for the browser -> app communication.
|
|
4
|
-
*/
|
|
5
|
-
export declare class DevToolsPluginClientImplBrowser extends DevToolsPluginClient {
|
|
6
|
-
private browserClientId;
|
|
7
|
-
/**
|
|
8
|
-
* Initialize the connection.
|
|
9
|
-
* @hidden
|
|
10
|
-
*/
|
|
11
|
-
initAsync(): Promise<void>;
|
|
12
|
-
private startHandshake;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=DevToolsPluginClientImplBrowser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DevToolsPluginClientImplBrowser.d.ts","sourceRoot":"","sources":["../../src/devtools/DevToolsPluginClientImplBrowser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D;;GAEG;AACH,qBAAa,+BAAgC,SAAQ,oBAAoB;IACvE,OAAO,CAAC,eAAe,CAAiC;IAExD;;;OAGG;IACY,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAKzC,OAAO,CAAC,cAAc;CAmBvB"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A message frame packer that serializes a messageKey and a payload into either a JSON string
|
|
3
|
-
* (fast path) or a binary format (for complex payloads).
|
|
4
|
-
*
|
|
5
|
-
* Fast Path (JSON.stringify/JSON.parse):
|
|
6
|
-
* - For simple payloads (e.g., strings, numbers, null, undefined, or plain objects), the packer
|
|
7
|
-
* uses `JSON.stringify` for serialization and `JSON.parse` for deserialization, ensuring
|
|
8
|
-
* optimal performance.
|
|
9
|
-
*
|
|
10
|
-
* Binary Format:
|
|
11
|
-
* - For more complex payloads (e.g., Uint8Array, ArrayBuffer, Blob), the packer uses a binary
|
|
12
|
-
* format with the following structure:
|
|
13
|
-
*
|
|
14
|
-
* +------------------+-------------------+----------------------------+--------------------------+
|
|
15
|
-
* | 4 bytes (Uint32) | Variable length | 1 byte (Uint8) | Variable length |
|
|
16
|
-
* | MessageKeyLength | MessageKey (JSON) | PayloadTypeIndicator (enum)| Payload (binary data) |
|
|
17
|
-
* +------------------+-------------------+----------------------------+--------------------------+
|
|
18
|
-
*
|
|
19
|
-
* 1. MessageKeyLength (4 bytes):
|
|
20
|
-
* - A 4-byte unsigned integer indicating the length of the MessageKey JSON string.
|
|
21
|
-
*
|
|
22
|
-
* 2. MessageKey (Variable length):
|
|
23
|
-
* - The JSON string representing the message key, encoded as UTF-8.
|
|
24
|
-
*
|
|
25
|
-
* 3. PayloadTypeIndicator (1 byte):
|
|
26
|
-
* - A single byte enum value representing the type of the payload (e.g., Uint8Array, String,
|
|
27
|
-
* Object, ArrayBuffer, Blob).
|
|
28
|
-
*
|
|
29
|
-
* 4. Payload (Variable length):
|
|
30
|
-
* - The actual payload data, which can vary in type and length depending on the PayloadType.
|
|
31
|
-
*/
|
|
32
|
-
type MessageKeyTypeBase = string | object;
|
|
33
|
-
type PayloadType = Uint8Array | string | number | null | undefined | object | ArrayBuffer | Blob;
|
|
34
|
-
interface MessageFrame<T extends MessageKeyTypeBase> {
|
|
35
|
-
messageKey: T;
|
|
36
|
-
payload?: PayloadType;
|
|
37
|
-
}
|
|
38
|
-
export declare class MessageFramePacker<T extends MessageKeyTypeBase> {
|
|
39
|
-
private textEncoder;
|
|
40
|
-
private textDecoder;
|
|
41
|
-
pack({ messageKey, payload }: MessageFrame<T>): string | Uint8Array | Promise<Uint8Array>;
|
|
42
|
-
unpack(packedData: string | ArrayBuffer): MessageFrame<T>;
|
|
43
|
-
private isFastPathPayload;
|
|
44
|
-
private payloadToUint8Array;
|
|
45
|
-
private packImpl;
|
|
46
|
-
private deserializePayload;
|
|
47
|
-
private static getPayloadTypeIndicator;
|
|
48
|
-
}
|
|
49
|
-
export {};
|
|
50
|
-
//# sourceMappingURL=MessageFramePacker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MessageFramePacker.d.ts","sourceRoot":"","sources":["../../src/devtools/MessageFramePacker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAIH,KAAK,kBAAkB,GAAG,MAAM,GAAG,MAAM,CAAC;AAC1C,KAAK,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;AAajG,UAAU,YAAY,CAAC,CAAC,SAAS,kBAAkB;IACjD,UAAU,EAAE,CAAC,CAAC;IACd,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED,qBAAa,kBAAkB,CAAC,CAAC,SAAS,kBAAkB;IAC1D,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,WAAW,CAAqB;IAEjC,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IA2BzF,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC;IA0BhE,OAAO,CAAC,iBAAiB;IAczB,OAAO,CAAC,mBAAmB;IAuB3B,OAAO,CAAC,QAAQ;IA8BhB,OAAO,CAAC,kBAAkB;IAoC1B,OAAO,CAAC,MAAM,CAAC,uBAAuB;CAqBvC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A transport protocol version between the app and the webui.
|
|
3
|
-
* It shows a warning in handshaking stage if the version is different between the app and the webui.
|
|
4
|
-
* The value should be increased when the protocol is changed.
|
|
5
|
-
*/
|
|
6
|
-
export declare const PROTOCOL_VERSION = 1;
|
|
7
|
-
//# sourceMappingURL=ProtocolVersion.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProtocolVersion.d.ts","sourceRoot":"","sources":["../../src/devtools/ProtocolVersion.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,IAAI,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The backing store for the WebSocket connection and reference count.
|
|
3
|
-
* This is used for connection multiplexing.
|
|
4
|
-
*/
|
|
5
|
-
export declare class WebSocketBackingStore {
|
|
6
|
-
ws: WebSocket | null;
|
|
7
|
-
refCount: number;
|
|
8
|
-
constructor(ws?: WebSocket | null, refCount?: number);
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=WebSocketBackingStore.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketBackingStore.d.ts","sourceRoot":"","sources":["../../src/devtools/WebSocketBackingStore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,qBAAqB;IAEvB,EAAE,EAAE,SAAS,GAAG,IAAI;IACpB,QAAQ,EAAE,MAAM;gBADhB,EAAE,GAAE,SAAS,GAAG,IAAW,EAC3B,QAAQ,GAAE,MAAU;CAE9B"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { DevToolsPluginClientOptions } from './devtools.types';
|
|
2
|
-
export interface Options {
|
|
3
|
-
/**
|
|
4
|
-
* Reconnect interval in milliseconds.
|
|
5
|
-
* @default 1500
|
|
6
|
-
*/
|
|
7
|
-
retriesInterval?: number;
|
|
8
|
-
/**
|
|
9
|
-
* The maximum number of retries.
|
|
10
|
-
* @default 200
|
|
11
|
-
*/
|
|
12
|
-
maxRetries?: number;
|
|
13
|
-
/**
|
|
14
|
-
* The timeout in milliseconds for the WebSocket connecting.
|
|
15
|
-
*/
|
|
16
|
-
connectTimeout?: number;
|
|
17
|
-
/**
|
|
18
|
-
* The error handler.
|
|
19
|
-
* @default throwing an error
|
|
20
|
-
*/
|
|
21
|
-
onError?: (error: Error) => void;
|
|
22
|
-
/**
|
|
23
|
-
* The callback to be called when the WebSocket is reconnected.
|
|
24
|
-
* @default no-op
|
|
25
|
-
*/
|
|
26
|
-
onReconnect?: (reason: string) => void;
|
|
27
|
-
/**
|
|
28
|
-
* The [`binaryType`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType).
|
|
29
|
-
*/
|
|
30
|
-
binaryType?: DevToolsPluginClientOptions['websocketBinaryType'];
|
|
31
|
-
}
|
|
32
|
-
export declare class WebSocketWithReconnect implements WebSocket {
|
|
33
|
-
readonly url: string;
|
|
34
|
-
private readonly retriesInterval;
|
|
35
|
-
private readonly maxRetries;
|
|
36
|
-
private readonly connectTimeout;
|
|
37
|
-
private readonly onError;
|
|
38
|
-
private readonly onReconnect;
|
|
39
|
-
private ws;
|
|
40
|
-
private retries;
|
|
41
|
-
private connectTimeoutHandle;
|
|
42
|
-
private isClosed;
|
|
43
|
-
private sendQueue;
|
|
44
|
-
private lastCloseEvent;
|
|
45
|
-
private eventListeners;
|
|
46
|
-
private readonly wsBinaryType?;
|
|
47
|
-
constructor(url: string, options?: Options);
|
|
48
|
-
close(code?: number, reason?: string): void;
|
|
49
|
-
addEventListener(event: 'message', listener: (event: WebSocketMessageEvent) => void): void;
|
|
50
|
-
addEventListener(event: 'open', listener: () => void): void;
|
|
51
|
-
addEventListener(event: 'error', listener: (event: WebSocketErrorEvent) => void): void;
|
|
52
|
-
addEventListener(event: 'close', listener: (event: WebSocketCloseEvent) => void): void;
|
|
53
|
-
removeEventListener(event: string, listener: (event: any) => void): void;
|
|
54
|
-
private connect;
|
|
55
|
-
send(data: string | ArrayBufferView | Blob | ArrayBufferLike): void;
|
|
56
|
-
private emitEvent;
|
|
57
|
-
private handleOpen;
|
|
58
|
-
private handleMessage;
|
|
59
|
-
private handleError;
|
|
60
|
-
private handleClose;
|
|
61
|
-
private handleConnectTimeout;
|
|
62
|
-
private clearConnectTimeoutIfNeeded;
|
|
63
|
-
private reconnectIfNeeded;
|
|
64
|
-
private wsClose;
|
|
65
|
-
get readyState(): number;
|
|
66
|
-
readonly CONNECTING = 0;
|
|
67
|
-
readonly OPEN = 1;
|
|
68
|
-
readonly CLOSING = 2;
|
|
69
|
-
readonly CLOSED = 3;
|
|
70
|
-
get binaryType(): BinaryType;
|
|
71
|
-
get bufferedAmount(): number;
|
|
72
|
-
get extensions(): string;
|
|
73
|
-
get protocol(): string;
|
|
74
|
-
ping(): void;
|
|
75
|
-
dispatchEvent(event: Event): boolean;
|
|
76
|
-
set onclose(_value: ((e: WebSocketCloseEvent) => any) | null);
|
|
77
|
-
set onerror(_value: ((e: Event) => any) | null);
|
|
78
|
-
set onmessage(_value: ((e: WebSocketMessageEvent) => any) | null);
|
|
79
|
-
set onopen(_value: (() => any) | null);
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=WebSocketWithReconnect.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketWithReconnect.d.ts","sourceRoot":"","sources":["../../src/devtools/WebSocketWithReconnect.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { WebSocketBackingStore } from './WebSocketBackingStore';
|
|
2
|
-
/**
|
|
3
|
-
* The connection info for devtools plugins client.
|
|
4
|
-
*/
|
|
5
|
-
export interface ConnectionInfo {
|
|
6
|
-
/** Indicates the sender towards the devtools plugin. */
|
|
7
|
-
sender: 'app' | 'browser';
|
|
8
|
-
/** Dev server address. */
|
|
9
|
-
devServer: string;
|
|
10
|
-
/** The plugin name. */
|
|
11
|
-
pluginName: string;
|
|
12
|
-
/**
|
|
13
|
-
* The backing store for the WebSocket connection. Exposed for testing.
|
|
14
|
-
* If not provided, the default singleton instance will be used.
|
|
15
|
-
* @hidden
|
|
16
|
-
*/
|
|
17
|
-
wsStore?: WebSocketBackingStore;
|
|
18
|
-
/**
|
|
19
|
-
* The transport protocol version between the app and the webui.
|
|
20
|
-
*/
|
|
21
|
-
protocolVersion: number;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Options for the devtools plugin client.
|
|
25
|
-
*/
|
|
26
|
-
export interface DevToolsPluginClientOptions {
|
|
27
|
-
/**
|
|
28
|
-
* The underlying WebSocket [`binaryType`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType).
|
|
29
|
-
*/
|
|
30
|
-
websocketBinaryType?: 'arraybuffer' | 'blob';
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* The handshake messages for the devtools plugin client.
|
|
34
|
-
* @hidden
|
|
35
|
-
*/
|
|
36
|
-
export interface HandshakeMessageParams {
|
|
37
|
-
protocolVersion: number;
|
|
38
|
-
pluginName: string;
|
|
39
|
-
method: 'handshake' | 'terminateBrowserClient';
|
|
40
|
-
browserClientId: string;
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=devtools.types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.types.d.ts","sourceRoot":"","sources":["../../src/devtools/devtools.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,wDAAwD;IACxD,MAAM,EACF,KAAK,GACL,SAAS,CAAC;IAEd,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;IAElB,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAEhC;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,mBAAmB,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;CAC9C;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,WAAW,GAAG,wBAAwB,CAAC;IAC/C,eAAe,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getConnectionInfo.d.ts","sourceRoot":"","sources":["../../src/devtools/getConnectionInfo.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,wBAAgB,iBAAiB,IAAI,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAQtE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getConnectionInfo.native.d.ts","sourceRoot":"","sources":["../../src/devtools/getConnectionInfo.native.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,wBAAgB,iBAAiB,IAAI,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAUtE"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { DevToolsPluginClient } from './DevToolsPluginClient';
|
|
2
|
-
import { getDevToolsPluginClientAsync } from './DevToolsPluginClientFactory';
|
|
3
|
-
import type { DevToolsPluginClientOptions } from './devtools.types';
|
|
4
|
-
export { getDevToolsPluginClientAsync, DevToolsPluginClient };
|
|
5
|
-
export type { DevToolsPluginClientOptions };
|
|
6
|
-
export type { EventSubscription } from './DevToolsPluginClient';
|
|
7
|
-
export { setEnableLogging } from './logger';
|
|
8
|
-
/**
|
|
9
|
-
* A React hook to get the DevToolsPluginClient instance.
|
|
10
|
-
*/
|
|
11
|
-
export declare function useDevToolsPluginClient(pluginName: string, options?: DevToolsPluginClientOptions): DevToolsPluginClient | null;
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/devtools/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,CAAC;AAC9D,YAAY,EAAE,2BAA2B,EAAE,CAAC;AAE5C,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,2BAA2B,GACpC,oBAAoB,GAAG,IAAI,CAkC7B"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare function log(...params: Parameters<typeof console.log>): void;
|
|
2
|
-
export declare function debug(...params: Parameters<typeof console.debug>): void;
|
|
3
|
-
export declare function info(...params: Parameters<typeof console.info>): void;
|
|
4
|
-
export declare function warn(...params: Parameters<typeof console.info>): void;
|
|
5
|
-
export declare function setEnableLogging(enabled: boolean): void;
|
|
6
|
-
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/devtools/logger.ts"],"names":[],"mappings":"AAEA,wBAAgB,GAAG,CAAC,GAAG,MAAM,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC,QAI5D;AAED,wBAAgB,KAAK,CAAC,GAAG,MAAM,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,KAAK,CAAC,QAIhE;AAED,wBAAgB,IAAI,CAAC,GAAG,MAAM,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,IAAI,CAAC,QAI9D;AAED,wBAAgB,IAAI,CAAC,GAAG,MAAM,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,IAAI,CAAC,QAI9D;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,QAEhD"}
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { MessageFramePacker } from './MessageFramePacker';
|
|
2
|
-
import { WebSocketBackingStore } from './WebSocketBackingStore';
|
|
3
|
-
import { WebSocketWithReconnect } from './WebSocketWithReconnect';
|
|
4
|
-
import type {
|
|
5
|
-
ConnectionInfo,
|
|
6
|
-
DevToolsPluginClientOptions,
|
|
7
|
-
HandshakeMessageParams,
|
|
8
|
-
} from './devtools.types';
|
|
9
|
-
import * as logger from './logger';
|
|
10
|
-
import { blobToArrayBufferAsync } from '../utils/blobUtils';
|
|
11
|
-
|
|
12
|
-
interface MessageFramePackerMessageKey {
|
|
13
|
-
pluginName: string;
|
|
14
|
-
method: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface EventSubscription {
|
|
18
|
-
remove(): void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* This client is for the Expo DevTools Plugins to communicate between the app and the DevTools webpage hosted in a browser.
|
|
23
|
-
* All the code should be both compatible with browsers and React Native.
|
|
24
|
-
*/
|
|
25
|
-
export abstract class DevToolsPluginClient {
|
|
26
|
-
private listeners: Record<string, undefined | Set<(params: any) => void>>;
|
|
27
|
-
|
|
28
|
-
private static defaultWSStore: WebSocketBackingStore = new WebSocketBackingStore();
|
|
29
|
-
private readonly wsStore: WebSocketBackingStore = DevToolsPluginClient.defaultWSStore;
|
|
30
|
-
|
|
31
|
-
protected isClosed = false;
|
|
32
|
-
protected retries = 0;
|
|
33
|
-
private readonly messageFramePacker: MessageFramePacker<MessageFramePackerMessageKey> =
|
|
34
|
-
new MessageFramePacker();
|
|
35
|
-
|
|
36
|
-
public constructor(
|
|
37
|
-
public readonly connectionInfo: ConnectionInfo,
|
|
38
|
-
private readonly options?: DevToolsPluginClientOptions
|
|
39
|
-
) {
|
|
40
|
-
this.wsStore = connectionInfo.wsStore || DevToolsPluginClient.defaultWSStore;
|
|
41
|
-
this.listeners = Object.create(null);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Initialize the connection.
|
|
46
|
-
* @hidden
|
|
47
|
-
*/
|
|
48
|
-
public async initAsync(): Promise<void> {
|
|
49
|
-
if (this.wsStore.ws == null) {
|
|
50
|
-
this.wsStore.ws = await this.connectAsync();
|
|
51
|
-
}
|
|
52
|
-
this.wsStore.refCount += 1;
|
|
53
|
-
this.wsStore.ws.addEventListener('message', this.handleMessage);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Close the connection.
|
|
58
|
-
*/
|
|
59
|
-
public async closeAsync(): Promise<void> {
|
|
60
|
-
this.isClosed = true;
|
|
61
|
-
this.wsStore.ws?.removeEventListener('message', this.handleMessage);
|
|
62
|
-
this.wsStore.refCount -= 1;
|
|
63
|
-
if (this.wsStore.refCount < 1) {
|
|
64
|
-
this.wsStore.ws?.close();
|
|
65
|
-
this.wsStore.ws = null;
|
|
66
|
-
}
|
|
67
|
-
this.listeners = Object.create(null);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Send a message to the other end of DevTools.
|
|
72
|
-
* @param method A method name.
|
|
73
|
-
* @param params any extra payload.
|
|
74
|
-
*/
|
|
75
|
-
public sendMessage(method: string, params: any) {
|
|
76
|
-
if (this.wsStore.ws?.readyState === WebSocket.CLOSED) {
|
|
77
|
-
logger.warn('Unable to send message in a disconnected state.');
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const messageKey: MessageFramePackerMessageKey = {
|
|
81
|
-
pluginName: this.connectionInfo.pluginName,
|
|
82
|
-
method,
|
|
83
|
-
};
|
|
84
|
-
const packedData = this.messageFramePacker.pack({ messageKey, payload: params });
|
|
85
|
-
if (!(packedData instanceof Promise)) {
|
|
86
|
-
this.wsStore.ws?.send(packedData);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
packedData.then((data) => {
|
|
90
|
-
this.wsStore.ws?.send(data);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Subscribe to a message from the other end of DevTools.
|
|
96
|
-
* @param method Subscribe to a message with a method name.
|
|
97
|
-
* @param listener Listener to be called when a message is received.
|
|
98
|
-
*/
|
|
99
|
-
public addMessageListener(method: string, listener: (params: any) => void): EventSubscription {
|
|
100
|
-
const listenersForMethod = this.listeners[method] || (this.listeners[method] = new Set());
|
|
101
|
-
listenersForMethod.add(listener);
|
|
102
|
-
return {
|
|
103
|
-
remove: () => {
|
|
104
|
-
this.listeners[method]?.delete(listener);
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Subscribe to a message from the other end of DevTools just once.
|
|
111
|
-
* @param method Subscribe to a message with a method name.
|
|
112
|
-
* @param listener Listener to be called when a message is received.
|
|
113
|
-
*/
|
|
114
|
-
public addMessageListenerOnce(method: string, listener: (params: any) => void): void {
|
|
115
|
-
const wrappedListenerOnce = (params: any): void => {
|
|
116
|
-
listener(params);
|
|
117
|
-
this.listeners[method]?.delete(wrappedListenerOnce);
|
|
118
|
-
};
|
|
119
|
-
this.addMessageListener(method, wrappedListenerOnce);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Internal handshake message sender.
|
|
124
|
-
* @hidden
|
|
125
|
-
*/
|
|
126
|
-
protected sendHandshakeMessage(params: HandshakeMessageParams) {
|
|
127
|
-
if (this.wsStore.ws?.readyState === WebSocket.CLOSED) {
|
|
128
|
-
logger.warn('Unable to send message in a disconnected state.');
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
this.wsStore.ws?.send(JSON.stringify({ ...params, __isHandshakeMessages: true }));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Internal handshake message listener.
|
|
136
|
-
* @hidden
|
|
137
|
-
*/
|
|
138
|
-
protected addHandskakeMessageListener(
|
|
139
|
-
listener: (params: HandshakeMessageParams) => void
|
|
140
|
-
): EventSubscription {
|
|
141
|
-
const messageListener = (event: MessageEvent) => {
|
|
142
|
-
if (typeof event.data !== 'string') {
|
|
143
|
-
// binary data is not coming from the handshake messages.
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const data = JSON.parse(event.data);
|
|
148
|
-
if (!data.__isHandshakeMessages) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
delete data.__isHandshakeMessages;
|
|
152
|
-
const params = data as HandshakeMessageParams;
|
|
153
|
-
if (params.pluginName && params.pluginName !== this.connectionInfo.pluginName) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
listener(params);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
this.wsStore.ws?.addEventListener('message', messageListener);
|
|
160
|
-
return {
|
|
161
|
-
remove: () => {
|
|
162
|
-
this.wsStore.ws?.removeEventListener('message', messageListener);
|
|
163
|
-
},
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Returns whether the client is connected to the server.
|
|
169
|
-
*/
|
|
170
|
-
public isConnected(): boolean {
|
|
171
|
-
return this.wsStore.ws?.readyState === WebSocket.OPEN;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* The method to create the WebSocket connection.
|
|
176
|
-
*/
|
|
177
|
-
protected connectAsync(): Promise<WebSocket> {
|
|
178
|
-
return new Promise((resolve, reject) => {
|
|
179
|
-
const endpoint = 'expo-dev-plugins/broadcast';
|
|
180
|
-
const ws = new WebSocketWithReconnect(`ws://${this.connectionInfo.devServer}/${endpoint}`, {
|
|
181
|
-
binaryType: this.options?.websocketBinaryType,
|
|
182
|
-
onError: (e: unknown) => {
|
|
183
|
-
if (e instanceof Error) {
|
|
184
|
-
console.warn(`Error happened from the WebSocket connection: ${e.message}\n${e.stack}`);
|
|
185
|
-
} else {
|
|
186
|
-
console.warn(`Error happened from the WebSocket connection: ${JSON.stringify(e)}`);
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
ws.addEventListener('open', () => {
|
|
191
|
-
resolve(ws);
|
|
192
|
-
});
|
|
193
|
-
ws.addEventListener('error', (e) => {
|
|
194
|
-
reject(e);
|
|
195
|
-
});
|
|
196
|
-
ws.addEventListener('close', (e: WebSocketCloseEvent) => {
|
|
197
|
-
logger.info('WebSocket closed', e.code, e.reason);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
protected handleMessage = async (event: WebSocketMessageEvent) => {
|
|
203
|
-
let data: ArrayBuffer | string;
|
|
204
|
-
if (typeof event.data === 'string') {
|
|
205
|
-
data = event.data;
|
|
206
|
-
} else if (event.data instanceof ArrayBuffer) {
|
|
207
|
-
data = event.data;
|
|
208
|
-
} else if (ArrayBuffer.isView(event.data)) {
|
|
209
|
-
data = event.data.buffer as ArrayBuffer;
|
|
210
|
-
} else if (event.data instanceof Blob) {
|
|
211
|
-
data = await blobToArrayBufferAsync(event.data);
|
|
212
|
-
} else {
|
|
213
|
-
logger.warn('Unsupported received data type in handleMessageImpl');
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
const { messageKey, payload, ...rest } = this.messageFramePacker.unpack(data);
|
|
217
|
-
// @ts-expect-error: `__isHandshakeMessages` is a private field that is not part of the MessageFramePacker type.
|
|
218
|
-
if (rest?.__isHandshakeMessages === true) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
if (messageKey.pluginName && messageKey.pluginName !== this.connectionInfo.pluginName) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const listenersForMethod = this.listeners[messageKey.method];
|
|
226
|
-
if (listenersForMethod) {
|
|
227
|
-
for (const listener of listenersForMethod) {
|
|
228
|
-
listener(payload);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Get the WebSocket backing store. Exposed for testing.
|
|
235
|
-
* @hidden
|
|
236
|
-
*/
|
|
237
|
-
public getWebSocketBackingStore(): WebSocketBackingStore {
|
|
238
|
-
return this.wsStore;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import type { DevToolsPluginClient } from './DevToolsPluginClient';
|
|
2
|
-
import { DevToolsPluginClientImplApp } from './DevToolsPluginClientImplApp';
|
|
3
|
-
import { DevToolsPluginClientImplBrowser } from './DevToolsPluginClientImplBrowser';
|
|
4
|
-
import type { ConnectionInfo, DevToolsPluginClientOptions } from './devtools.types';
|
|
5
|
-
import { getConnectionInfo } from './getConnectionInfo';
|
|
6
|
-
|
|
7
|
-
const instanceMap: Record<string, DevToolsPluginClient | Promise<DevToolsPluginClient>> = {};
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Factory of DevToolsPluginClient based on sender types.
|
|
11
|
-
* @hidden
|
|
12
|
-
*/
|
|
13
|
-
export async function createDevToolsPluginClient(
|
|
14
|
-
connectionInfo: ConnectionInfo,
|
|
15
|
-
options?: DevToolsPluginClientOptions
|
|
16
|
-
): Promise<DevToolsPluginClient> {
|
|
17
|
-
let client: DevToolsPluginClient;
|
|
18
|
-
if (connectionInfo.sender === 'app') {
|
|
19
|
-
client = new DevToolsPluginClientImplApp(connectionInfo, options);
|
|
20
|
-
} else {
|
|
21
|
-
client = new DevToolsPluginClientImplBrowser(connectionInfo, options);
|
|
22
|
-
}
|
|
23
|
-
await client.initAsync();
|
|
24
|
-
return client;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Public API to get the DevToolsPluginClient instance.
|
|
29
|
-
*/
|
|
30
|
-
export async function getDevToolsPluginClientAsync(
|
|
31
|
-
pluginName: string,
|
|
32
|
-
options?: DevToolsPluginClientOptions
|
|
33
|
-
): Promise<DevToolsPluginClient> {
|
|
34
|
-
const connectionInfo = getConnectionInfo();
|
|
35
|
-
|
|
36
|
-
let instance: DevToolsPluginClient | Promise<DevToolsPluginClient> | null =
|
|
37
|
-
instanceMap[pluginName];
|
|
38
|
-
if (instance != null) {
|
|
39
|
-
if (instance instanceof Promise) {
|
|
40
|
-
return instance;
|
|
41
|
-
}
|
|
42
|
-
if (
|
|
43
|
-
instance.isConnected() === false ||
|
|
44
|
-
instance.connectionInfo.devServer !== connectionInfo.devServer
|
|
45
|
-
) {
|
|
46
|
-
await instance.closeAsync();
|
|
47
|
-
delete instanceMap[pluginName];
|
|
48
|
-
instance = null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (instance == null) {
|
|
52
|
-
const instancePromise = createDevToolsPluginClient({ ...connectionInfo, pluginName }, options);
|
|
53
|
-
instanceMap[pluginName] = instancePromise;
|
|
54
|
-
instance = await instancePromise;
|
|
55
|
-
instanceMap[pluginName] = instance;
|
|
56
|
-
}
|
|
57
|
-
return instance;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Internal testing API to cleanup all DevToolsPluginClient instances.
|
|
62
|
-
*/
|
|
63
|
-
export function cleanupDevToolsPluginInstances() {
|
|
64
|
-
for (const pluginName of Object.keys(instanceMap)) {
|
|
65
|
-
const instance = instanceMap[pluginName];
|
|
66
|
-
delete instanceMap[pluginName];
|
|
67
|
-
if (instance instanceof Promise) {
|
|
68
|
-
instance.then((instance) => instance.closeAsync());
|
|
69
|
-
} else {
|
|
70
|
-
instance.closeAsync();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { DevToolsPluginClient } from './DevToolsPluginClient';
|
|
2
|
-
import * as logger from './logger';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The DevToolsPluginClient for the app -> browser communication.
|
|
6
|
-
*/
|
|
7
|
-
export class DevToolsPluginClientImplApp extends DevToolsPluginClient {
|
|
8
|
-
// Map of pluginName -> browserClientId
|
|
9
|
-
private browserClientMap: Record<string, string> = {};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Initialize the connection.
|
|
13
|
-
* @hidden
|
|
14
|
-
*/
|
|
15
|
-
override async initAsync(): Promise<void> {
|
|
16
|
-
await super.initAsync();
|
|
17
|
-
this.addHandshakeHandler();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
private addHandshakeHandler() {
|
|
21
|
-
this.addHandskakeMessageListener((params) => {
|
|
22
|
-
if (params.method === 'handshake') {
|
|
23
|
-
const { pluginName, protocolVersion } = params;
|
|
24
|
-
|
|
25
|
-
// [0] Check protocol version
|
|
26
|
-
if (protocolVersion !== this.connectionInfo.protocolVersion) {
|
|
27
|
-
// Use console.warn than logger because we want to show the warning even logging is disabled.
|
|
28
|
-
console.warn(
|
|
29
|
-
`Received an incompatible devtools plugin handshake message - pluginName[${pluginName}]`
|
|
30
|
-
);
|
|
31
|
-
this.terminateBrowserClient(pluginName, params.browserClientId);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// [1] Terminate duplicated browser clients for the same plugin
|
|
36
|
-
const previousBrowserClientId = this.browserClientMap[pluginName];
|
|
37
|
-
if (previousBrowserClientId != null && previousBrowserClientId !== params.browserClientId) {
|
|
38
|
-
logger.info(
|
|
39
|
-
`Terminate the previous browser client connection - previousBrowserClientId[${previousBrowserClientId}]`
|
|
40
|
-
);
|
|
41
|
-
this.terminateBrowserClient(pluginName, previousBrowserClientId);
|
|
42
|
-
}
|
|
43
|
-
this.browserClientMap[pluginName] = params.browserClientId;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private terminateBrowserClient(pluginName: string, browserClientId: string) {
|
|
49
|
-
this.sendHandshakeMessage({
|
|
50
|
-
protocolVersion: this.connectionInfo.protocolVersion,
|
|
51
|
-
method: 'terminateBrowserClient',
|
|
52
|
-
browserClientId,
|
|
53
|
-
pluginName,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|