react-native
Version:
A framework for building native apps using React
66 lines (57 loc) • 2 kB
JavaScript
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
import type {TurboModule} from '../../../../Libraries/TurboModule/RCTExport';
import type {UnsafeObject} from '../../../../Libraries/Types/CodegenTypes';
import * as TurboModuleRegistry from '../../../../Libraries/TurboModule/TurboModuleRegistry';
export type Constants = {BLOB_URI_SCHEME: ?string, BLOB_URI_HOST: ?string};
export interface Spec extends TurboModule {
readonly getConstants: () => Constants;
readonly addNetworkingHandler: () => void;
readonly addWebSocketHandler: (id: number) => void;
readonly removeWebSocketHandler: (id: number) => void;
readonly sendOverSocket: (blob: UnsafeObject, socketID: number) => void;
readonly createFromParts: (
parts: Array<UnsafeObject>,
withId: string,
) => void;
readonly release: (blobId: string) => void;
}
const NativeModule = TurboModuleRegistry.get<Spec>('BlobModule');
let constants = null;
let NativeBlobModule = null;
if (NativeModule != null) {
NativeBlobModule = {
getConstants(): Constants {
if (constants == null) {
constants = NativeModule.getConstants();
}
return constants;
},
addNetworkingHandler(): void {
NativeModule.addNetworkingHandler();
},
addWebSocketHandler(id: number): void {
NativeModule.addWebSocketHandler(id);
},
removeWebSocketHandler(id: number): void {
NativeModule.removeWebSocketHandler(id);
},
sendOverSocket(blob: UnsafeObject, socketID: number): void {
NativeModule.sendOverSocket(blob, socketID);
},
createFromParts(parts: Array<UnsafeObject>, withId: string): void {
NativeModule.createFromParts(parts, withId);
},
release(blobId: string): void {
NativeModule.release(blobId);
},
};
}
export default NativeBlobModule as ?Spec;