npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

oca-sdk-mobile-livechat-rn

v1.0.1

Published

React Native bridge for OCA Livechat SDK - Android native module wrapping Jetpack Compose livechat widget

Downloads

207

Readme

OCA SDK Mobile Livechat - React Native

React Native bridge for OCA Livechat SDK — integrates Android native livechat widget (Jetpack Compose) into React Native apps via Native Module.

Installation

npm install oca-sdk-mobile-livechat-rn
# or
yarn add oca-sdk-mobile-livechat-rn

Android Setup

1. Firebase Configuration (Required for Push Notifications)

  1. Go to Firebase Console
  2. Create a project or use existing one
  3. Add your Android app with package name matching your appId
  4. Download google-services.json
  5. Place it in android/app/google-services.json

2. Add Google Services Plugin

Add to android/build.gradle:

dependencies {
    classpath("com.google.gms:google-services:4.4.0")
}

Add to android/app/build.gradle:

apply plugin: "com.google.gms.google-services"

3. Build Android

cd android && ./gradlew assembleRelease

Quick Start

Provider Setup

Wrap your app with LivechatProvider:

import React from 'react';
import { LivechatProvider } from 'oca-sdk-mobile-livechat-rn';

function App() {
  return (
    <LivechatProvider>
      <YourApp />
    </LivechatProvider>
  );
}

Initialize and Use

import { useLivechat } from 'oca-sdk-mobile-livechat-rn';

function ChatButton() {
  const { initialize, openChat, isInitialized } = useLivechat();

  const handleStartChat = async () => {
    // Initialize SDK (call once)
    await initialize({
      appId: 'com.yourapp',
      ocaKey: 'YOUR_OCA_KEY',
      enablePollingFallback: true,
      pollingIntervalMs: 3000,
    });

    // Open chat screen
    await openChat();
  };

  return (
    <Button
      title="Start Chat"
      onPress={handleStartChat}
      disabled={!isInitialized}
    />
  );
}

API Reference

Livechat Class

initialize(config: LivechatConfig): Promise<void>

Initialize the SDK with tenant configuration. Must be called before other methods.

await Livechat.initialize({
  appId: 'com.yourapp',
  ocaKey: 'YOUR_OCA_KEY',
  userAgent: 'Android-SDK/1.0', // optional
  enablePollingFallback: false, // optional
  pollingIntervalMs: 3000, // optional
});

openChat(): Promise<void>

Open the native chat screen (Jetpack Compose Activity).

closeChat(): Promise<void>

Close the chat screen.

sendMessage(text: string, callbackData?: string): Promise<void>

Send a text message to the agent.

endSession(): Promise<void>

End the active chat session.

registerPushToken(token: string): Promise<void>

Register FCM token for push notifications.

unregisterPushToken(): Promise<void>

Unregister push token.

onEvent(listener: (event: LivechatEvent) => void): () => void

Subscribe to SDK events. Returns unsubscribe function.

const unsubscribe = Livechat.onEvent((event) => {
  switch (event.type) {
    case 'onStateChanged':
      console.log('State:', event.state);
      break;
    case 'onMessageReceived':
      console.log('Message:', event.message);
      break;
    case 'onError':
      console.error('Error:', event.message);
      break;
  }
});

// Later: unsubscribe();

removeAllListeners(): void

Remove all event listeners. Call during cleanup.

React Hooks

useLivechat()

Access Livechat context. Must be used within <LivechatProvider>.

const {
  state,           // Current SDK state
  isInitialized,   // Whether SDK is initialized
  error,           // Last error message
  initialize,      // Initialize function
  openChat,        // Open chat function
  closeChat,       // Close chat function
  sendMessage,     // Send message function
  endSession,      // End session function
  registerPushToken,
  unregisterPushToken,
} = useLivechat();

useLivechatEvent(listener)

Subscribe to Livechat events with automatic cleanup.

useLivechatEvent((event) => {
  if (event.type === 'onStateChanged') {
    console.log('State:', event.state);
  }
});

Events

| Event | Payload | Description | |-------|---------|-------------| | onStateChanged | { state: LivechatState } | SDK state changed | | onMessageReceived | { message: string } | New message from agent | | onError | { message: string } | Error occurred |

LivechatState

  • idle - SDK not initialized
  • loading - SDK is loading
  • configuration_loaded - SDK ready to open chat
  • chat_active - Chat screen is open
  • error - Error state
  • unauthorized - Authentication failed

Configuration

LivechatConfig

| Property | Type | Required | Default | Description | |----------|------|----------|---------|-------------| | appId | string | Yes | - | Android package name | | ocaKey | string | Yes | - | OCA tenant key | | userAgent | string | No | "Android-SDK/1.0" | Custom user agent | | enablePollingFallback | boolean | No | false | Enable polling fallback | | pollingIntervalMs | number | No | 3000 | Polling interval (ms) |

Troubleshooting

"The package doesn't seem to be linked"

  • Rebuild the app after installing the package
  • Ensure npx react-native config shows the package
  • Check that android/build.gradle includes the library

"No current activity available"

  • Ensure the app is in foreground when calling SDK methods
  • Check that MainActivity is properly initialized

Push notifications not working

  • Verify google-services.json is in android/app/
  • Check Firebase project configuration
  • Ensure FCM token is registered: Livechat.registerPushToken(token)

License

MIT