Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TM] Add spec for BlobModule #24909

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Libraries/Blob/BlobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

const Blob = require('./Blob');
const BlobRegistry = require('./BlobRegistry');
const {BlobModule} = require('../BatchedBridge/NativeModules');
import NativeBlobModule from './NativeBlobModule';

import type {BlobData, BlobOptions, BlobCollector} from './BlobTypes';

Expand Down Expand Up @@ -53,7 +53,7 @@ class BlobManager {
/**
* If the native blob module is available.
*/
static isAvailable = !!BlobModule;
static isAvailable = !!NativeBlobModule;

/**
* Create blob from existing array of blobs.
Expand Down Expand Up @@ -92,7 +92,7 @@ class BlobManager {
}
}, 0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot call NativeBlobModule.createFromParts because property createFromParts is missing in null or undefined [1].

BlobModule.createFromParts(items, blobId);
NativeBlobModule.createFromParts(items, blobId);

return BlobManager.createFromOptions({
blobId,
Expand Down Expand Up @@ -131,38 +131,38 @@ class BlobManager {
if (BlobRegistry.has(blobId)) {
return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot call NativeBlobModule.release because property release is missing in null or undefined [1].

}
BlobModule.release(blobId);
NativeBlobModule.release(blobId);
}

/**
* Inject the blob content handler in the networking module to support blob
* requests and responses.
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot call NativeBlobModule.addNetworkingHandler because property addNetworkingHandler is missing in null or undefined [1].

static addNetworkingHandler(): void {
BlobModule.addNetworkingHandler();
NativeBlobModule.addNetworkingHandler();
}

/**
* Indicate the websocket should return a blob for incoming binary
* messages.
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot call NativeBlobModule.addWebSocketHandler because property addWebSocketHandler is missing in null or undefined [1].

static addWebSocketHandler(socketId: number): void {
BlobModule.addWebSocketHandler(socketId);
NativeBlobModule.addWebSocketHandler(socketId);
}

/**
* Indicate the websocket should no longer return a blob for incoming
* binary messages.
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot call NativeBlobModule.removeWebSocketHandler because property removeWebSocketHandler is missing in null or undefined [1].

static removeWebSocketHandler(socketId: number): void {
BlobModule.removeWebSocketHandler(socketId);
NativeBlobModule.removeWebSocketHandler(socketId);
}

/**
* Send a blob message to a websocket.
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot call NativeBlobModule.sendOverSocket because property sendOverSocket is missing in null or undefined [1].

static sendOverSocket(blob: Blob, socketId: number): void {
BlobModule.sendOverSocket(blob.data, socketId);
NativeBlobModule.sendOverSocket(blob.data, socketId);
}
}

Expand Down
26 changes: 26 additions & 0 deletions Libraries/Blob/NativeBlobModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/

'use strict';

import type {TurboModule} from 'RCTExport';
import * as TurboModuleRegistry from 'TurboModuleRegistry';

export interface Spec extends TurboModule {
+getConstants: () => {|BLOB_URI_SCHEME: string, BLOB_URI_HOST: ?string|};
+addNetworkingHandler: () => void;
+addWebSocketHandler: (id: number) => void;
+removeWebSocketHandler: (id: number) => void;
+sendOverSocket: (blob: Object, id: number) => void;
+createFromParts: (parts: Array<Object>, blobId: string) => void;
+release: (blobId: string) => void;
}

export default TurboModuleRegistry.get<Spec>('BlobModule');
14 changes: 9 additions & 5 deletions Libraries/Blob/URL.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@

const Blob = require('./Blob');

const {BlobModule} = require('../BatchedBridge/NativeModules');
import NativeBlobModule from './NativeBlobModule';

let BLOB_URL_PREFIX = null;

if (BlobModule && typeof BlobModule.BLOB_URI_SCHEME === 'string') {
BLOB_URL_PREFIX = BlobModule.BLOB_URI_SCHEME + ':';
if (typeof BlobModule.BLOB_URI_HOST === 'string') {
BLOB_URL_PREFIX += `//${BlobModule.BLOB_URI_HOST}/`;
if (
NativeBlobModule &&
typeof NativeBlobModule.getConstants().BLOB_URI_SCHEME === 'string'
) {
const constants = NativeBlobModule.getConstants();
BLOB_URL_PREFIX = constants.BLOB_URI_SCHEME + ':';
if (typeof constants.BLOB_URI_HOST === 'string') {
BLOB_URL_PREFIX += `//${constants.BLOB_URI_HOST}/`;
}
}

Expand Down
3 changes: 1 addition & 2 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ const mockNativeModules = {
},
},
BlobModule: {
BLOB_URI_SCHEME: 'content',
BLOB_URI_HOST: null,
getConstants: () => ({BLOB_URI_SCHEME: 'content', BLOB_URI_HOST: null}),
addNetworkingHandler: jest.fn(),
enableBlobSupport: jest.fn(),
disableBlobSupport: jest.fn(),
Expand Down