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

fileverse-sync

v1.0.0

Published

The Fileverse Sync is a TypeScript-based package that enables real-time collaboration using Yjs for data synchronization and WebSockets for communication. This package provides a state machine (`syncMachine`) for handling synchronization logic and a React

Downloads

4

Readme

Fileverse Sync

The Fileverse Sync is a TypeScript-based package that enables real-time collaboration using Yjs for data synchronization and WebSockets for communication. This package provides a state machine (syncMachine) for handling synchronization logic and a React hook (useSyncMachine) for easy integration with React applications.

Features

  • Real-time collaboration: Utilize WebSockets for instant updates.
  • Data synchronization: Sync data across clients using Yjs.
  • State management: Handle connection states with XState.
  • Encryption: Secure data transmission with encryption and decryption capabilities.

Installation

Install the package using npm or yarn:

npm install @fileverse-dev/sync
or
yarn add @fileverse-dev/sync

Usage

SyncCore

The syncCore is an interpreted instance of the syncMachine for managing the synchronization state.

Example

import { syncCore } from ' @fileverse-dev/sync';

const sync = syncCore.start({
  roomId: 'fileverse'
});

sync.send({ type: 'CONNECT', data: { username: 'your-username', roomKey: 'aes-encryption-key' } });

sync.onTransition(state => {
  console.log(state.value);
});

useSyncMachine

The useSyncMachine hook simplifies the integration of the synchronization logic into React applications.

Example

import React, { useEffect } from 'react';
import { useSyncMachine } from 'fileverse-sync-client';

const App = () => {
  const { connect, disconnect, isConnected, ydoc } = useSyncMachine({ roomKey: 'your-room-key', wsUrl: 'wss//your-websocket-service' });

  useEffect(() => {
    connect('your-username', 'your-room-id');

    return () => {
      disconnect();
    };
  }, [connect, disconnect]);

  return (
    <div>
      <h1>{isConnected ? 'Connected' : 'Disconnected'}</h1>
      {/* Render your collaborative content here */}
    </div>
  );
};

export default App;

API

syncMachine

A state machine for managing the synchronization state.

States

  • disconnected: The initial state. The machine transitions here when disconnected.
  • connecting: The machine transitions here while attempting to connect.
  • send_initial_update: State for sending the initial update after connecting.
  • updating: State for sending updates.
  • connected: The machine transitions here when connected.
  • disconnecting: The machine transitions here while disconnecting.

Events

  • CONNECT: Initiates the connection process.
  • SEND_UPDATE: Sends an update.
  • UPDATE_COMMIT: Commits an update.
  • ROOM_MEMBERSHIP_CHANGE: Updates room members.
  • MESSAGE_RECEIVED: Processes a received message.
  • CONTENT_UPDATE: Applies a content update.
  • SEND_INIT_UPDATE: Sends the initial update.
  • DISCONNECT: Initiates the disconnection process.
  • AWARENESS_UPDATE: Applies an awareness state update.
  • INIT_AWARENESS: Initializes the awareness state.
  • RESET_STATE: Resets the state.

Actions

  • initSync: Initializes synchronization context.
  • setConnectState: Sets the connection state.
  • handleReset: Handles resetting the state.
  • handleAwareness: Handles awareness initialization.
  • applyAwarenessState: Applies the awareness state.
  • processMessage: Processes a received message.
  • updateRoomMembers: Updates the room members.
  • applyUpdate: Applies an update to the document.

useSyncMachine

Hook

  • connect(username: string, roomId: string): void
    • Connects to the WebSocket.
  • disconnect(): void
    • Disconnects from the WebSocket.
  • isConnected: boolean
    • Connection status.
  • ydoc: Y.Doc
    • Yjs document.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.