xref: /expo/home/kernel/Kernel.ts (revision 52c7ee12)
1import { Linking, NativeModules } from 'react-native';
2
3import MockKernel from './MockKernel';
4
5const NativeKernel = NativeModules.ExponentKernel || MockKernel;
6
7export enum ExpoClientReleaseType {
8  UNKNOWN = 'UNKNOWN',
9  SIMULATOR = 'SIMULATOR',
10  ENTERPRISE = 'ENTERPRISE',
11  DEVELOPMENT = 'DEVELOPMENT',
12  AD_HOC = 'ADHOC',
13  APPLE_APP_STORE = 'APPLE_APP_STORE',
14}
15
16export const sdkVersions: string = Array.isArray(NativeKernel.sdkVersions)
17  ? NativeKernel.sdkVersions.join(',')
18  : NativeKernel.sdkVersions;
19
20export const iosClientReleaseType: ExpoClientReleaseType =
21  NativeKernel.IOSClientReleaseType || ExpoClientReleaseType.UNKNOWN;
22
23export async function openURLAsync(url: string): Promise<void> {
24  // ExponentKernel.openURL exists on iOS, and it's the same as Linking.openURL except it will never
25  // validate whether Expo can open this URL. This addresses cases where, e.g., someone types in a
26  // http://localhost URL directly into the URL bar. We know they implicitly expect Expo to open
27  // this, even though it won't validate as an Expo URL. By contrast, Linking.openURL would pass
28  // such a URL on to the system URL handler.
29  if (NativeKernel.openURL) {
30    await NativeKernel.openURL(url);
31  } else {
32    await Linking.openURL(url);
33  }
34}
35
36export function selectQRReader(): void {
37  NativeKernel.selectQRReader();
38}
39
40export type KernelSession = {
41  sessionSecret: string;
42};
43
44export async function getSessionAsync(): Promise<KernelSession | null> {
45  return await NativeKernel.getSessionAsync();
46}
47
48export async function setSessionAsync(session: KernelSession): Promise<void> {
49  await NativeKernel.setSessionAsync(session);
50}
51
52export async function removeSessionAsync(): Promise<void> {
53  await NativeKernel.removeSessionAsync();
54}
55
56export function onEventSuccess(eventId: string, result: object): void {
57  NativeKernel.onEventSuccess(eventId, result);
58}
59
60export function onEventFailure(eventId: string, message: string): void {
61  NativeKernel.onEventFailure(eventId, message);
62}
63