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

@digitaldefiance/eecp-client

v0.1.1

Published

Browser client library with React hooks for EECP

Readme

@digitaldefiance/eecp-client

Browser client library with React hooks for collaborative editing. Provides WebSocket connection management, key storage in IndexedDB, collaborative editor with change subscriptions, and automatic reconnection with exponential backoff.

Features

  • EECPClient with WebSocket connection management
  • ClientKeyManager with IndexedDB storage
  • CollaborativeEditor with real-time change subscriptions
  • React hooks: useWorkspace, useCollaboration
  • Automatic reconnection with exponential backoff

Installation

npm install @digitaldefiance/eecp-client
# or
yarn add @digitaldefiance/eecp-client

Key Classes

EECPClient

Main client class for connecting to EECP workspaces.

import { EECPClient } from '@digitaldefiance/eecp-client';

const client = new EECPClient({
  serverUrl: 'wss://your-server.com',
  workspaceId: 'workspace-id',
  participantKey: 'participant-key',
});

// Connect to workspace
await client.connect();

// Insert text
await client.insert(0, 'Hello, world!');

// Delete text
await client.delete(7, 6);

// Get current text
const text = client.getText();

// Disconnect
await client.disconnect();

ClientKeyManager

Manages cryptographic keys with IndexedDB persistence.

import { ClientKeyManager } from '@digitaldefiance/eecp-client';

const keyManager = new ClientKeyManager();

// Initialize with workspace credentials
await keyManager.initialize(workspaceId, masterKey);

// Keys are automatically stored in IndexedDB
// and retrieved on subsequent sessions

// Get current temporal key
const currentKey = await keyManager.getCurrentKey();

// Clear all keys
await keyManager.clearKeys();

CollaborativeEditor

High-level editor interface with change notifications.

import { CollaborativeEditor } from '@digitaldefiance/eecp-client';

const editor = new CollaborativeEditor(client);

// Subscribe to changes
const unsubscribe = editor.onChange((text) => {
  console.log('Document updated:', text);
});

// Insert text
await editor.insert(0, 'Hello');

// Delete text
await editor.delete(0, 5);

// Unsubscribe
unsubscribe();

React Hooks

useWorkspace

Hook for managing workspace connection.

import { useWorkspace } from '@digitaldefiance/eecp-client';

function MyComponent() {
  const {
    client,
    connected,
    error,
    connect,
    disconnect,
  } = useWorkspace({
    serverUrl: 'wss://your-server.com',
    workspaceId: 'workspace-id',
    participantKey: 'participant-key',
  });

  return (
    <div>
      {connected ? (
        <button onClick={disconnect}>Disconnect</button>
      ) : (
        <button onClick={connect}>Connect</button>
      )}
      {error && <div>Error: {error.message}</div>}
    </div>
  );
}

useCollaboration

Hook for collaborative editing with real-time updates.

import { useCollaboration } from '@digitaldefiance/eecp-client';

function CollaborativeTextEditor() {
  const {
    text,
    insert,
    deleteText,
    connected,
  } = useCollaboration({
    serverUrl: 'wss://your-server.com',
    workspaceId: 'workspace-id',
    participantKey: 'participant-key',
  });

  const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
    const newText = e.target.value;
    // Calculate diff and apply operations
    // (simplified example)
    if (newText.length > text.length) {
      insert(text.length, newText.slice(text.length));
    } else if (newText.length < text.length) {
      deleteText(newText.length, text.length - newText.length);
    }
  };

  return (
    <textarea
      value={text}
      onChange={handleChange}
      disabled={!connected}
    />
  );
}

Complete Example

import React, { useEffect } from 'react';
import { useCollaboration } from '@digitaldefiance/eecp-client';

function App() {
  const {
    text,
    insert,
    deleteText,
    connected,
    error,
    participants,
  } = useCollaboration({
    serverUrl: 'wss://localhost:3000',
    workspaceId: 'my-workspace',
    participantKey: 'my-key',
    autoConnect: true,
  });

  return (
    <div>
      <h1>Collaborative Editor</h1>
      
      <div>
        Status: {connected ? '🟢 Connected' : '🔴 Disconnected'}
      </div>
      
      {error && <div>Error: {error.message}</div>}
      
      <div>
        Participants: {participants.length}
      </div>
      
      <textarea
        value={text}
        onChange={(e) => {
          // Handle text changes
          const newText = e.target.value;
          // Apply diff as operations
        }}
        disabled={!connected}
        style={{ width: '100%', height: '400px' }}
      />
    </div>
  );
}

IndexedDB Storage

The client automatically stores keys in IndexedDB for persistence across sessions:

  • Database: eecp-client
  • Store: keys
  • Keys stored: Master key, temporal keys, workspace metadata

Keys are automatically loaded on reconnection, enabling seamless session recovery.

Automatic Reconnection

The client includes exponential backoff for automatic reconnection:

  • Initial retry: 1 second
  • Maximum retry: 30 seconds
  • Exponential backoff with jitter
  • Automatic state recovery after reconnection

Testing

The package includes 150+ tests covering:

  • WebSocket connection management
  • Key storage and retrieval
  • Collaborative editing operations
  • React hooks behavior
  • Reconnection logic
  • Error handling

Run tests:

npm test
# or
yarn test

Technology Stack

  • TypeScript - Type-safe implementation
  • React 19 - Modern React with hooks
  • WebSocket - Real-time communication
  • IndexedDB - Client-side key storage

Related Packages

License

MIT