xref: /expo/home/kernel/Kernel.ts (revision bb8f4f99)
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[] = NativeKernel.sdkVersions;
17
18export const iosClientReleaseType: ExpoClientReleaseType =
19  NativeKernel.IOSClientReleaseType || ExpoClientReleaseType.UNKNOWN;
20
21export async function openURLAsync(url: string): Promise<void> {
22  // ExponentKernel.openURL exists on iOS, and it's the same as Linking.openURL except it will never
23  // validate whether Expo can open this URL. This addresses cases where, e.g., someone types in a
24  // http://localhost URL directly into the URL bar. We know they implicitly expect Expo to open
25  // this, even though it won't validate as an Expo URL. By contrast, Linking.openURL would pass
26  // such a URL on to the system URL handler.
27  if (NativeKernel.openURL) {
28    await NativeKernel.openURL(url);
29  } else {
30    await Linking.openURL(url);
31  }
32}
33
34export function selectQRReader(): void {
35  NativeKernel.selectQRReader();
36}
37
38export type KernelSession = {
39  sessionSecret: string;
40};
41
42export async function getSessionAsync(): Promise<KernelSession | null> {
43  return await NativeKernel.getSessionAsync();
44}
45
46export async function setSessionAsync(session: KernelSession): Promise<void> {
47  await NativeKernel.setSessionAsync(session);
48}
49
50export async function removeSessionAsync(): Promise<void> {
51  await NativeKernel.removeSessionAsync();
52}
53
54export function onEventSuccess(eventId: string, result: object): void {
55  NativeKernel.onEventSuccess(eventId, result);
56}
57
58export function onEventFailure(eventId: string, message: string): void {
59  NativeKernel.onEventFailure(eventId, message);
60}
61