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 🙏

© 2024 – Pkg Stats / Ryan Hefner

customchatreact

v1.1.0

Published

React component library for embedding Rocket.Chat in React applications, providing customizable and feature-rich chat interfaces with easy React integration.

Downloads

4

Readme

EmbeddedChat

An easy to use full-stack component embedding Rocket.Chat into your webapp.

EmbeddedChat is a full-stack React component node module of the RocketChat application that is fully configurable, extensible, and flexible for use. It is tightly bound with the RocketChat server using Rocket.Chat nodejs SDK and its UI fully customisable.

embeddedchatwall

Installation

npm install @embeddedchat/react
# or
yarn add @embeddedchat/react

Importing the Component

Import the EmbeddedChat component into your file:

import { EmbeddedChat } from '@embeddedchat/react';

Basic Usage

To use the EmbeddedChat component, include it in your component's render method or return statement. Here's a basic example:

<EmbeddedChat
  host="http://your-rocketchat-server.com"
  roomId="YOUR_ROOM_ID"
/>

Props

  • isClosable (boolean): If true, the chat window can be closed. Defaults to false.
  • setClosableState (function): Callback to handle the closable state.
  • moreOpts (boolean): It adds a kebab menu with added functionalities like showing pinned, starred, thread messages. Defaults to false.
  • width (string): Width of the chat window. Defaults to '100%'.
  • height (string): Height of the chat window. Defaults to '50vh'.
  • host (string): The URL of your RocketChat server.
  • roomId (string): ID of the chat room.
  • channelName (string): The fallback channel name to be present on the chat.
  • anonymousMode (boolean): Enable anonymous mode. Defaults to false.
  • toastBarPosition (string): Position of the toast bar. Defaults to 'bottom right'.
  • showRoles (boolean): Display user roles. Defaults to false.
  • showAvatar (boolean): Show user avatars. Defaults to false.
  • enableThreads (boolean): Enable chat threads. Defaults to false.
  • theme (object): Theme object for styling.
  • className (string): Additional CSS class for styling.
  • style (object): Inline styles for the chat window.
  • hideHeader (boolean): Hide the chat header. Defaults to false.
  • auth (object): Authentication configuration.

Authentication

The EmbeddedChat component offers three distinct authentication modes to cater to different requirements for accessing RocketChat. Below is a detailed guide on how to implement each authentication flow.

1. Token Authentication Flow

Token authentication allows users to authenticate using a service-specific access token. There are two ways to use token authentication:

a. Using accessToken and expiresIn:
auth: {
  flow: 'TOKEN',
  credentials: {
    serviceName: "your-service-name",
    accessToken: "accessToken",
    expiresIn: 3600,
  },
}
  • serviceName: The name of your authentication service.
  • accessToken: The access token obtained from your authentication service.
  • expiresIn: The duration in seconds for which the token is valid.
b. Using resume:
auth: {
  flow: 'TOKEN',
  credentials: {
    resume: 'resumeToken',
  },
}
  • resume: A resume token to be used for authentication.

In both cases, the credentials are posted to the /api/v1/login endpoint of the RocketChat server.

2. Password Authentication Flow

The password method displays a modal where users can enter their username and password:

auth: {
  flow: 'PASSWORD',
}

This method is straightforward and does not require additional configuration for the auth prop. When this flow is active, a modal dialog prompts users for their RocketChat username and password.

3. OAuth Authentication Flow

To use RocketChat's OAuth authentication, ensure the EmbeddedChat app is installed and configured on your RocketChat server:

auth: {
  flow: 'OAUTH',
}

This method utilizes the OAuth configuration set up in RocketChat, providing a seamless authentication experience.

Integrating with EmbeddedChat

When implementing any of these authentication methods in EmbeddedChat, include the auth prop with the desired configuration:

<EmbeddedChat
  host="http://your-rocketchat-server.com"
  roomId="YOUR_ROOM_ID"
  auth={{
    flow: 'TOKEN', // or 'PASSWORD' or 'OAUTH'
    credentials: {
      // Include if using TOKEN flow
    },
  }}
/>

Ensure that the host and roomId props are set according to your RocketChat server and the specific room you want to connect to.

Theming and Customization

You can pass a theme object to customize the appearance according to your application's design:

<EmbeddedChat
  // ...other props
  theme={myCustomTheme}
/>

Follow theming.md to know more about EmbeddedChat's theming.

Handling the Closable State

If isClosable is true, provide a setClosableState function to manage the state when the chat window is closed:

<EmbeddedChat
  isClosable={true}
  setClosableState={handleClose}
  // ...other props
/>

Development

Follow this EmbeddedChat Readme to setup EmbeddedChat for development.

Conclusion

The EmbeddedChat component offers a flexible and feature-rich solution for integrating RocketChat into your application. Customize it according to your needs to enhance your app's chat functionality.