Skip to content

Fix #133 Add React Native Support #193

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

monadoid
Copy link

@monadoid monadoid commented Jul 10, 2025

Fixes #133

What's New

  • React Native shims for both core and realtime packages
    • agents-realtime: Now we export the relevant webRTC classes for each shim, react-native-webrtc is a peer dependency for the new RN shim.
    • agents-core: I used event-target-shim, events, @ungap/structured-clone and react-native-uuid for polyfills. I figured that because they're in the shim, they will get tree-shaken for other environments.

How It Works

WebRTC classes are now exposed through the shims with react-native-webrtc as a peer dependency. Users don't need to change anything about how they use the SDK; it just works.

Testing

I've tested this thoroughly in a create-expo-app starter project and everything works great - WebRTC connections, audio handling, etc. I didn't add integration tests here since that seemed like it might be too much setup complexity for the repo, but I'm totally happy to create a standalone example repo if the maintainers would find that helpful!

The React Native shim automatically calls registerGlobals() when imported, which sets up the WebRTC globals. I believe that users could still call registerGlobals() within their RN app again if they wanted to. In my testing, everything worked without needing to call registerGlobals() in the app code.

Notes / Improvements

Note that when running in expo, I see:

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
 WARN  Require cycle: .yalc/@openai/agents-core/dist/tracing/provider.mjs -> .yalc/@openai/agents-core/dist/tracing/context.mjs -> .yalc/@openai/agents-core/dist/tracing/provider.mjs

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
 WARN  Require cycle: .yalc/@openai/agents-core/dist/agent.mjs -> .yalc/@openai/agents-core/dist/run.mjs -> .yalc/@openai/agents-core/dist/agent.mjs

These warnings are due to the fact that there is some circular importing going on where the shims are imported into mcp.ts, but mcp also imports from the shims. I figured this wasn't in scope for this PR.

monadoid added 4 commits July 9, 2025 14:41
- Add RN shim with react-native-webrtc peer dependency
- Shims now export webRTC classes, and implementation imports these instead of globals
- Only call document in browser environment
Copy link

changeset-bot bot commented Jul 10, 2025

🦋 Changeset detected

Latest commit: 15665c6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@openai/agents-realtime Minor
@openai/agents-core Minor
@openai/agents Patch
@openai/agents-openai Minor
@openai/agents-extensions Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@seratch seratch changed the title Add React Native Support Fix #133 Add React Native Support Jul 10, 2025
@seratch seratch requested a review from dkundel-openai July 10, 2025 08:45
registerGlobals,
} from 'react-native-webrtc';

registerGlobals();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we are using the globals which is good so I would say let's drop the registerGlobals() that way it's still up to the implementor if they want to register them for additional use cases rather than us magically importing them

import type { EventEmitterEvents, Timeout, Timer } from './interface';

import { EventEmitter as NodeEventEmitter } from 'events';
import 'event-target-shim';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need EventTarget as a shim in React Native?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The Realtime SDK does not work with React Native
3 participants