@getcobrowse/react-native

中文文档
1.0.0发布于 2026/10/20MITTypeScriptESM + CJS近 30 天下载 4619

Cobrowse screen sharing SDK for React Native

原始使用文档
文档目录16 节
  1. Installation
  2. iOS Setup (Expo)
  3. iOS Setup (Bare React Native)
  4. Android Setup
  5. Usage
  6. Basic Setup (2 lines)
  7. Track Current Screen
  8. Using the Hook
  9. Auto-Accept (Kiosk Mode)
  10. Floating Sharing Indicator
  11. Custom Share Request UI
  12. Callbacks
  13. API Reference
  14. <CobrowseProvider>
  15. useCobrowse()
  16. CobrowseState

@getcobrowse/react-native

React Native SDK for Cobrowse screen sharing. Enables agents to view a customer's mobile screen in real-time with annotations, cursors, and highlights.

Uses native screen capture (ReplayKit on iOS, MediaProjection on Android) via Daily.js.

Installation

# Install the SDK
npm install @getcobrowse/react-native

# Install peer dependencies
npm install @daily-co/react-native-daily-js @daily-co/react-native-webrtc react-native-svg

iOS Setup (Expo)

Add the config plugin to your app.json or app.config.js:

{
  "expo": {
    "plugins": [
      ["@getcobrowse/react-native/plugin/withCobrowseBroadcast", {
        "appGroup": "group.com.yourcompany.yourapp.cobrowse"
      }]
    ]
  }
}

Then rebuild:

npx expo prebuild --clean
npx expo run:ios --device

Important: Screen sharing requires a real device — it does not work in the iOS Simulator. You also need a development build, not Expo Go.

iOS Setup (Bare React Native)

iOS screen sharing requires a Broadcast Upload Extension. Daily's SDK handles all the IPC and frame encoding — you just need to create the target and wire it up.

1. Create the extension target:

In Xcode: File → New → Target → Broadcast Upload Extension. Name it CobrowseBroadcast. Uncheck "Include UI Extension".

2. Replace SampleHandler.swift:

Replace the generated SampleHandler.swift with:

import ReactNativeDailyJSScreenShareExtension

public class SampleHandler: DailyRPHandler {
  override init() {
    super.init(appGroupIdentifier: "group.com.yourcompany.yourapp.cobrowse")
  }
}

3. Configure App Groups:

In Xcode, enable the "App Groups" capability for both your main app target and the CobrowseBroadcast extension target. Add the same group identifier to both.

4. Add to Info.plist:

In your main app's Info.plist:

<key>RTCAppGroupIdentifier</key>
<string>group.com.yourcompany.yourapp.cobrowse</string>
<key>DailyScreenCaptureExtensionBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).CobrowseBroadcast</string>

5. Install pods and rebuild:

cd ios && pod install && cd ..

Important: Screen sharing requires a real device — it does not work in the iOS Simulator.

Android Setup

Add to AndroidManifest.xml:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />

Register the foreground service in your manifest:

<service
  android:name="com.daily.reactlibrary.DailyOngoingMeetingService"
  android:foregroundServiceType="mediaProjection" />

Usage

Basic Setup (2 lines)

Wrap your app with CobrowseProvider:

import { CobrowseProvider } from '@getcobrowse/react-native'

export default function App() {
  return (
    <CobrowseProvider
      serverUrl="https://cobrowse.owner.sh"
      metadata={{ email: user.email, name: user.name }}
    >
      <YourApp />
    </CobrowseProvider>
  )
}

That's it. The SDK will:

  • Register presence on the cobrowse dashboard
  • Show a modal when an agent requests screen sharing
  • Handle native screen capture via ReplayKit/MediaProjection
  • Display agent annotations (cursor, highlights, pointers) as an overlay

Track Current Screen

Pass screenName to show what screen the user is on in the dashboard:

<CobrowseProvider
  serverUrl="https://cobrowse.owner.sh"
  metadata={{ email: user.email }}
  screenName={currentRouteName}
>

Using the Hook

Access cobrowse state and controls from any component:

import { useCobrowse } from '@getcobrowse/react-native'

function SupportButton() {
  const { state, agentName, stop } = useCobrowse()

  if (state === 'sharing') {
    return (
      <Button onPress={stop}>
        Stop sharing with {agentName}
      </Button>
    )
  }

  return null
}

Auto-Accept (Kiosk Mode)

Skip the permission modal and auto-accept share requests:

<CobrowseProvider
  serverUrl="https://cobrowse.owner.sh"
  metadata={{ deviceId: 'kiosk-001' }}
  autoAccept
>

Floating Sharing Indicator

Use the built-in SharingIndicator component:

import { SharingIndicator } from '@getcobrowse/react-native'

function MyScreen() {
  return (
    <View>
      {/* Your content */}
      <View style={{ position: 'absolute', bottom: 40, alignSelf: 'center' }}>
        <SharingIndicator />
      </View>
    </View>
  )
}

Custom Share Request UI

Disable the built-in modal and handle requests yourself:

import { CobrowseProvider, useCobrowse } from '@getcobrowse/react-native'

function App() {
  return (
    <CobrowseProvider
      serverUrl="https://cobrowse.owner.sh"
      metadata={{ email: user.email }}
      onShareRequest={(agentName) => {
        // Custom notification, bottom sheet, etc.
      }}
      autoAccept={false}
    >
      <CustomShareUI />
    </CobrowseProvider>
  )
}

function CustomShareUI() {
  const { state, agentName, acceptShare, declineShare } = useCobrowse()

  if (state !== 'share_requested') return null

  return (
    <BottomSheet>
      <Text>{agentName} wants to view your screen</Text>
      <Button onPress={acceptShare}>Allow</Button>
      <Button onPress={declineShare}>Decline</Button>
    </BottomSheet>
  )
}

Callbacks

<CobrowseProvider
  serverUrl="https://cobrowse.owner.sh"
  metadata={{ email: user.email }}
  onStateChange={(state) => analytics.track('cobrowse_state', { state })}
  onShareRequest={(agentName) => console.log(`${agentName} wants to share`)}
  onAnnotation={(event) => {
    // event.type: 'cursor' | 'highlight' | 'pointer' | 'clear' | 'cursor-hide'
  }}
>

API Reference

<CobrowseProvider>

PropTypeRequiredDescription
serverUrlstringYesCobrowse server URL
metadataRecord<string, unknown>NoUser identification metadata
screenNamestringNoCurrent screen name for dashboard
autoAcceptbooleanNoAuto-accept share requests
onShareRequest(agentName: string) => voidNoCalled when agent requests share
onStateChange(state: CobrowseState) => voidNoCalled on state transitions
onAnnotation(event: AnnotationEvent) => voidNoCalled when annotation received

useCobrowse()

Returns a CobrowseHandle:

PropertyTypeDescription
stateCobrowseStateCurrent SDK state
agentNamestring | nullName of requesting/viewing agent
acceptShare() => voidAccept pending share request
declineShare() => voidDecline pending share request
stop() => Promise<void>Stop active screen share
setMetadata(metadata) => voidUpdate user metadata
setScreenName(name) => voidUpdate current screen name
annotationsAnnotation[]Current highlight annotations
pointerAnimationsPointerAnimation[]Current pointer ripples
cursorCursorPositionAgent cursor position

CobrowseState

'idle' | 'tracking' | 'share_requested' | 'connecting' | 'sharing' | 'stopping'

版本与发布记录

@getcobrowse/react-native 共发布 16 个版本,首次发布于 2026/03/15;过去 12 个月发布了 16 个版本。

版本发布日期距今
1.0.0latest2026/10/2027 天前
0.1.142026/05/136 个月前
0.1.132026/04/147 个月前
0.1.122026/04/147 个月前
0.1.112026/04/147 个月前
0.1.102026/04/147 个月前

关于 @getcobrowse/react-native 的常见问题

@getcobrowse/react-native 是什么?

Cobrowse screen sharing SDK for React Native

如何安装 @getcobrowse/react-native?

在项目目录运行 npm install @getcobrowse/react-native,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.0.0)、react-native(>=0.72.0)、react-native-svg(>=13.0.0)、@daily-co/react-native-webrtc(^124.0.6-daily.1)、@daily-co/react-native-daily-js(^0.84.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@getcobrowse/react-native 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@getcobrowse/react-native 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@getcobrowse/react-native 可以商用吗?

@getcobrowse/react-native 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@getcobrowse/react-native 的下载量有多少?

根据 npm 官方下载统计,@getcobrowse/react-native 在 2026/10/17 – 2026/11/15 这 30 天内被下载 4,619 次,日均约 154 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@getcobrowse/react-native 还在维护吗?

最新版本 1.0.0 发布于 2026/10/20(27 天前);至今共发布 16 个版本,其中过去 12 个月发布了 16 个;首次发布于 2026/03/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。