# Expo quickstart

> A new Expo app in a call with a browser in about ten minutes: camera, microphone and everyone else's video, on the iOS Simulator, an Android emulator or a phone.

This builds a small Expo app that starts or joins a call. A browser on
[demo.synento.com](https://demo.synento.com) can join the same call, so you can
see both sides at once.

To skip setting up a server, it gets its tokens from the public demo's routes.
That is only for trying it out: your own app gets them from your server (see
[Tokens come from your server](https://synento.com/docs/guides/react-native.md)).

You need Node 22, and Xcode (for iOS) or Android Studio (for Android).

## 1. Create the app

```bash
npx create-expo-app@latest my-call --template blank-typescript
cd my-call
npx expo install @synento/react-native expo-device
```

## 2. Add the config plugin

In `app.json`, add the plugin to `expo`. It writes the camera and microphone
permission prompts:

```json
{
  "expo": {
    "plugins": ["@synento/react-native"]
  }
}
```

## 3. Replace `App.tsx`

```tsx
import {
  SynentoLocalPreview,
  SynentoProvider,
  SynentoVideoView,
  useConnectionState,
  useLocalCamera,
  useParticipants,
} from "@synento/react-native";
import * as Device from "expo-device";
import { useEffect, useMemo, useRef, useState } from "react";
import { Button, Platform, StatusBar, Text, TextInput, View } from "react-native";

// The public demo's token routes: for trying Synento out only. Your app calls
// its own server here, which holds the API key.
const DEMO = "https://demo.synento.com";

async function post(path: string, body: object) {
  const res = await fetch(`${DEMO}${path}`, {
    body: JSON.stringify(body),
    headers: { "Content-Type": "application/json" },
    method: "POST",
  });
  const json = await res.json();
  if (!res.ok) throw new Error(json.error ?? `${path} failed (${res.status})`);
  return json;
}

// Room for the status bar (a real app would use react-native-safe-area-context).
const top = Platform.OS === "android" ? (StatusBar.currentHeight ?? 24) : 54;

// The iOS Simulator has no camera: send a moving test pattern there.
const source = Platform.OS === "ios" && !Device.isDevice ? "testPattern" : "camera";

export default function App() {
  const [sessionId, setSessionId] = useState("");
  const [joined, setJoined] = useState<string | null>(null);
  const userId = useMemo(() => `phone-${Math.random().toString(36).slice(2, 8)}`, []);
  const getToken = useMemo(
    () => () => post("/api/connection", { sessionId: joined, userId }),
    [joined, userId],
  );

  if (!joined) {
    return (
      <View style={{ flex: 1, gap: 12, justifyContent: "center", padding: 24 }}>
        <Button
          title="Start a new call"
          onPress={async () => setJoined((await post("/api/sessions", { name: "Expo" })).sessionId)}
        />
        <TextInput
          autoCapitalize="none"
          onChangeText={setSessionId}
          placeholder="or paste a session ID"
          style={{ borderWidth: 1, padding: 8 }}
          value={sessionId}
        />
        <Button disabled={!sessionId} title="Join" onPress={() => setJoined(sessionId.trim())} />
      </View>
    );
  }

  return (
    <SynentoProvider getToken={getToken} userId={userId}>
      <Call sessionId={joined} onLeave={() => setJoined(null)} />
    </SynentoProvider>
  );
}

function Call({ sessionId, onLeave }: { sessionId: string; onLeave: () => void }) {
  const { state, error } = useConnectionState();
  const participants = useParticipants();
  const camera = useLocalCamera();
  const [problem, setProblem] = useState<string | null>(null);

  const started = useRef(false);
  const { publish } = camera;
  useEffect(() => {
    if (state !== "connected" || started.current) return;
    started.current = true;
    publish({ source }).catch((e: Error) => setProblem(e.message));
  }, [state, publish]);

  return (
    <View style={{ backgroundColor: "black", flex: 1, paddingBottom: 24, paddingTop: top }}>
      <Text selectable style={{ color: "white", padding: 8 }}>
        {state} · session {sessionId}
        {(problem ?? error) ? `\n${problem ?? error?.message}` : ""}
      </Text>
      <View style={{ flex: 1 }}>
        {participants.map((id) => (
          <SynentoVideoView key={id} participantId={id} style={{ flex: 1 }} />
        ))}
        <SynentoLocalPreview
          style={{ bottom: 12, height: 160, position: "absolute", right: 12, width: 120 }}
        />
      </View>
      <View style={{ flexDirection: "row", justifyContent: "space-around", padding: 8 }}>
        <Button
          title={camera.microphoneEnabled ? "Mute" : "Unmute"}
          onPress={() => camera.setMicrophoneEnabled(!camera.microphoneEnabled)}
        />
        <Button title="Flip" onPress={camera.flip} />
        <Button title="Leave" onPress={onLeave} />
      </View>
    </View>
  );
}
```

## 4. Run it

The SDK has native code, so it runs in a development build, not Expo Go:

```bash
npx expo run:ios        # or: npx expo run:android
```

Allow the camera and microphone when asked, then tap **Start a new call**. The
session ID appears at the top. Open [demo.synento.com](https://demo.synento.com)
in a browser, paste that ID, and join: each side sees and hears the other.

To run it on your own phone, connect it with a cable and add `--device`.

## Next

- Move token minting to your server, then point `getToken` at it.
- The [React Native guide](https://synento.com/docs/guides/react-native.md) covers the whole API:
  replay, delay statistics, the config plugin's options, and platform limits.
