A lightweight realtime SDK for connecting to the Wireblob realtime network using a Pusher-compatible protocol.
Wire is built as a wrapper around pusher-js, providing:
- simpler configuration
- Wireblob-first defaults
- browser support
- Node.js support
- React Native compatibility
- Web Worker compatibility
- future extensibility without breaking API compatibility
npm install @wireblob/wireyarn add @wireblob/wirepnpm add @wireblob/wireimport Wire from '@wireblob/wire';
const wire = new Wire('YOUR_APP_KEY', {
host: 'eu-central-1.wireblob.com',
secure: true
});
const channel = wire.subscribe('chat');
channel.bind('message', (data) => {
console.log(data);
});const WireModule = require('@wireblob/wire');
const Wire = WireModule.default || WireModule;
const wire = new Wire('YOUR_APP_KEY', {
host: 'eu-central-1.wireblob.com',
secure: true
});
const channel = wire.subscribe('chat');
channel.bind('message', (data) => {
console.log(data);
});The CDN file is a self-contained browser bundle.
<script src="https://cdn.jsdelivr.net/npm/@wireblob/wire/lib/umd/wire.min.js"></script>
<script>
const wire = new Wire('YOUR_APP_KEY', {
host: 'eu-central-1.wireblob.com',
secure: true
});
const channel = wire.subscribe('chat');
channel.bind('message', (data) => {
console.log(data);
});
</script>new Wire(appKey, options)| Parameter | Type | Required | Description |
|---|---|---|---|
appKey |
string |
Yes | Application public key |
options |
object |
No | Connection options |
| Option | Type | Default | Description |
|---|---|---|---|
host |
string |
eu-central-1.wireblob.com |
Wireblob server hostname |
secure |
boolean |
true |
Use secure websocket connection |
wsPort |
number |
80 |
WebSocket port |
wssPort |
number |
443 |
Secure WebSocket port |
enabledTransports |
array |
['ws', 'wss'] |
Allowed transports |
authEndpoint |
string |
null |
Private/presence auth endpoint |
auth |
object |
{} |
Additional auth configuration |
const channel = wire.subscribe('chat-room');channel.bind('message', (data) => {
console.log(data);
});Sends a real-time event over the existing WebSocket connection. Requires a private- or presence- channel and the event name must start with client-.
const channel = wire.subscribe('private-chat');
channel.trigger('client-message', { text: 'Hello world' });Sends an event via the Wireblob HTTP REST API. Requires appId, key, and secret. Never expose your secret in browser code.
import Wire from '@wireblob/wire';
// use this instead of import if using with commonJs
// const WireModule = require('@wireblob/wire');
// const Wire = WireModule.default || WireModule;
const wire = new Wire({
appId: 'YOUR_APP_ID',
key: 'YOUR_APP_KEY',
secret: 'YOUR_APP_SECRET',
host: 'eu-central-1.wireblob.com',
secure: true
});
// Single channel
await wire.trigger('chat', 'message', { text: 'Hello from server' });
// Multiple channels
await wire.trigger(['chat', 'notifications'], 'message', { text: 'Broadcast' });wire.unsubscribe('chat-room');wire.connection.bind('connected', () => {
console.log('Connected');
});wire.connection.bind('error', (error) => {
console.error(error);
});wire.connection.bind('disconnected', () => {
console.log('Disconnected');
});wire.connect();
wire.disconnect();const channel = wire.subscribe('private-chat');const channel = wire.subscribe('presence-room');
channel.bind('pusher:subscription_succeeded', (members) => {
console.log(members);
});const wire = new Wire('YOUR_APP_KEY', {
host: 'eu-central-1.wireblob.com',
secure: true,
wsPort: 80,
wssPort: 443,
enabledTransports: ['ws', 'wss'],
authEndpoint: '/broadcasting/auth',
auth: {
headers: {
Authorization: 'Bearer TOKEN'
}
}
});Enable internal Pusher logging:
Wire.logToConsole = true;Wire is:
- protocol-compatible with Pusher Channels
- transport-compatible with standard WebSocket infrastructure
- designed for Wireblob-native extensions
Current implementation:
- wraps
pusher-js - applies Wireblob defaults
- exposes a stable SDK surface
Future versions may introduce:
- native Wire transport
- SSE support
- QUIC/WebTransport
- MQTT adapters
- custom protocol optimizations
| Platform | Supported |
|---|---|
| Browser | Yes |
| Node.js | Yes |
| React Native | Yes |
| Web Workers | Yes |
- Pusher - Protocol and transport compatibility