@graineai/inapp-react-native 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,6 +27,7 @@ export interface GraineVoiceApi {
27
27
  connected: boolean;
28
28
  connecting: boolean;
29
29
  muted: boolean;
30
+ ready: boolean;
30
31
  start: () => void;
31
32
  end: () => void;
32
33
  setMuted: (m: boolean) => void;
@@ -66,9 +66,11 @@ export function GraineVoiceLauncher({ webView: WebView, autoStart = false, trans
66
66
  });
67
67
  }, [client, post]);
68
68
  useEffect(() => {
69
- if (ready)
70
- pushContext();
71
- }, [ready, pushContext]);
69
+ if (!ready)
70
+ return;
71
+ pushContext();
72
+ return client.on("screen", () => pushContext());
73
+ }, [client, ready, pushContext]);
72
74
  const beginCall = useCallback(async () => {
73
75
  if (client.isConnected) {
74
76
  console.warn("[graine] The provider has its own connection open while GraineVoiceLauncher " +
@@ -116,7 +118,8 @@ export function GraineVoiceLauncher({ webView: WebView, autoStart = false, trans
116
118
  case "graine:ready":
117
119
  setReady(true);
118
120
  pushContext();
119
- if (autoStart && !startedRef.current) {
121
+ if ((autoStart || pendingStartRef.current) && !startedRef.current) {
122
+ pendingStartRef.current = false;
120
123
  startedRef.current = true;
121
124
  void beginCall();
122
125
  }
@@ -156,14 +159,20 @@ export function GraineVoiceLauncher({ webView: WebView, autoStart = false, trans
156
159
  }
157
160
  }
158
161
  }, [autoStart, beginCall, client, onCaption, onCallState, onMicDenied, onTransport, onError, onEnded, post, pushContext]);
162
+ const pendingStartRef = useRef(false);
159
163
  const api = {
160
164
  connected,
161
165
  connecting,
162
166
  muted,
167
+ ready: !!voiceAgentId && ready,
163
168
  start: useCallback(() => {
164
169
  setConnecting(true);
170
+ if (!ready) {
171
+ pendingStartRef.current = true;
172
+ return;
173
+ }
165
174
  void beginCall();
166
- }, [beginCall]),
175
+ }, [beginCall, ready]),
167
176
  end: useCallback(() => post({ type: "graine:end-call" }), [post]),
168
177
  setMuted: useCallback((m) => {
169
178
  setMutedState(m);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graineai/inapp-react-native",
3
- "version": "0.17.0",
3
+ "version": "0.19.0",
4
4
  "type": "module",
5
5
  "description": "Graine in-app agent for React Native \u2014 an agent that sees the screen your customer is on and can act on it.",
6
6
  "license": "MIT",