Registry / messaging / dcrf-client

dcrf-client

JSON →
library1.1.0jsnpmunverified

A TypeScript WebSocket client for Django Channels v2 APIs powered by djangochannelsrestframework. Version 1.1.0 provides a simple, promise-based interface for CRUD operations and subscriptions, with automatic reconnection (using reconnecting-websocket with backoff) and subscription restart. Key differentiators: request queuing before connection, custom subscribe actions, and full TypeScript support. Active development, monthly releases.

npm install dcrf-client
INSTALL
IMPORT
SIG · DCRF-CLIENT
D
dcrf-client
messagingjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dcrf
import dcrf from 'dcrf-client'
const dcrf = require('dcrf-client')
ESM default import since v1.0. CommonJS require works but is not recommended for TypeScript.
connect
import { connect } from 'dcrf-client'
import dcrf from 'dcrf-client'; const connect = dcrf.connect;
Named export available; don't destructure from default import.
createClient
import { createClient } from 'dcrf-client'
import createClient from 'dcrf-client'
createClient is a named export, not default. Use named import syntax.
DcrfClient
import type { DcrfClient } from 'dcrf-client'
import { DcrfClient } from 'dcrf-client'
Type import only; DcrfClient is an interface, not a value.

Demonstrates connecting to a WebSocket endpoint, performing CRUD operations, subscribing to updates with a callback, cancelling a subscription, and making custom stream requests.

import { connect } from 'dcrf-client'; import WebSocket from 'ws'; // if in Node.js const client = connect('wss://example.com/ws', { // options }); // CRUD client.create('people', { name: 'Alex' }).then(person => { console.log('Created:', person); }).catch(err => console.error(err)); client.retrieve('people', 4).then(person => { console.log('Retrieved:', person); }); client.update('people', 4, { name: 'John' }).then(person => { console.log('Updated:', person); }); client.patch('people', 4, { name: 'Jake' }).then(person => { console.log('Patched:', person); }); client.delete('people', 4).then(() => { console.log('Deleted'); }); // Subscribe const sub = client.subscribe('people', 1, (data, action) => { console.log('Action:', action, 'Data:', data); }); // Cancel subscription sub.cancel(); // Request arbitrary stream client.request('mystream', { key: 'value' }).then(response => { console.log('Response:', response); });
Debug
Known issues
breakingIn version 1.1.0, the 'reconnecting-websocket' dependency was updated to v4, which changed the WebSocket constructor signature. If you pass a custom WebSocket via options.websocket.WebSocket, ensure it conforms to the WebSocket standard (no custom properties like 'type' required earlier).
fix
If using a custom WebSocket, ensure it does not rely on removed properties. Default behavior unchanged.
affects: >=1.1.0 <1.2.0
deprecatedThe 'createClient' function is deprecated in favor of 'connect' as of v1.1.0. 'createClient' still works but may be removed in future.
fix
Use 'connect' instead of 'createClient'.
affects: >=1.1.0
gotchaThe client does not automatically infer stream names from the URL; you must specify the model/stream name in CRUD methods (e.g., 'people'). If you use a custom multiplexer stream name, use 'request' directly.
fix
Always pass the stream name as the first argument to CRUD methods. For custom streams, use 'client.request(streamName, payload)'.
affects: >=1.0.0
gotchaIn Node.js environments, the global WebSocket is not available. You must provide a WebSocket constructor via options, e.g., using 'ws' package.
fix
Install 'ws' and pass it in options: connect('wss://...', { websocket: { WebSocket: require('ws') } })
affects: >=1.0.0
breakingPrior to v1.0, the package was JavaScript only and used different import paths. Upgrading to TypeScript version requires changing imports and type annotations.
fix
Update imports to ESM default import style. Consult upgrade guide in changelog.
affects: <1.0.0
Errors
Common errors & fixes
Error: WebSocket is not defined
Node.js does not have a native WebSocket; you need to provide one via options.
fix
const WebSocket = require('ws'); const client = dcrf.connect('wss://...', { websocket: { WebSocket } });
Error: Invalid JSON response: undefined
The server returned a non-JSON message or an unexpected format.
fix
Check server logs; ensure the endpoint is a valid Django Channels WebSocket. Also verify you are connecting to the correct URL.
TypeError: client.create is not a function
Incorrect import: likely used default import and then tried to call client.create on the default export (which is an object with connect/createClient).
fix
Use named import: import { connect } from 'dcrf-client'; const client = connect('wss://...');
Error: The stream 'undefined' does not exist
CRUD method called without a stream name, e.g., client.create({...}) instead of client.create('people', {...}).
fix
Always provide stream name as first argument.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
reconnecting-websocketrequiredHandles WebSocket reconnection with exponential backoff
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
dcrf-client — npm install dcrf-client · libregistry