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

fiction-chat-client

v1.0.6

Published

Fiction Chat Client is the frontend component for integrating real-time chat into your application. It pairs with `fiction-chat-server` for a complete chat solution with WebSocket support for interactive and responsive user experiences.

Downloads

408

Readme

Fiction Chat Client

Fiction Chat Client is the frontend component for integrating real-time chat into your application. It pairs with fiction-chat-server for a complete chat solution with WebSocket support for interactive and responsive user experiences.

Note: This package is intended to be used with fiction-chat-server, which provides the backend chat functionality for a complete setup.

Installation

Install the package using npm:

bash
Copy code
npm install fiction-chat-client

Configuration

To use Fiction Chat Client, import it into your application and configure the necessary properties. The component requires a valid token for authentication and URLs for the chat server and WebSocket.

Example Setup

'use client';
import { FictionChatClient } from 'fiction-chat-client';
import React, { useState, useEffect } from 'react';

export default function Home() {
  const [token, setToken] = useState('');

  useEffect(() => {
    console.log(token);
  }, [token]);

  return (
    <main>  
      <h1 className='text-3xl font-bold text-red-500'>Welcome to My Next.js App</h1>  
      <p>This is a simple React page built with Next.js</p>  
      <input  
        className='border-2'  
        type="text"  
        value={token}  
        onChange={(e) => setToken(e.target.value)}
      />
      <div className='flex flex-row w-full border-2 h-screen'>
        <FictionChatClient   
          authToken={token}   
          contentContainerClassName=' '   
          chatServerUrl={process.env.NEXT_PUBLIC_CHAT_SERVER_URL}   
          chatWsUrl={process.env.NEXT_PUBLIC_CHAT_WS_URL}
        />
      </div>
    </main>
  );
}

Note: Replace the placeholder token input with a real session token for production use.

Additional Hook: createConversation

To initiate a conversation before rendering the main component, use the createConversation hook by passing the recipient’s user ID:

javascript

import { createConversation } from 'fiction-chat-client';

// Example usage:  
const conversationId = createConversation(toId); // toId: recipient's user ID

Environment Variables

Set the following environment variables in your frontend project to connect to the backend chat server and WebSocket:

  • NEXT_PUBLIC_CHAT_SERVER_URL: The URL path for the chat route on your server, configured in the backend setup. For example, if your backend route is defined at /api/chat, the value would be https://yourserver.com/api/chat.
  • NEXT_PUBLIC_CHAT_WS_URL: The WebSocket URL to establish real-time chat, matching the websocketPort defined in your backend configuration. For example, if WEBSOCKET_PORT is set to 8080, this would be wss://yourserver.com:8080.

Ensure these variables match the route and WebSocket port in the backend implementation for seamless integration.

Example Implementation

For a complete frontend implementation with Fiction Chat Client in a Next.js application, refer to the page.js file here in the fiction-chat-example repository.

Support

For any questions or issues, contact us: