const client = newSkubber({
serverUrl: 'https://sps.skubber.com',
apiKey: 'mps_YOUR_API_KEY',
apiSecret: 'YOUR_API_SECRET'
});
// Connect with a userId — e.g., the logged-in user in your appawait client.connect('user123');
console.log('Connected!');
The SDK automatically fetches a JWT token and renews it before it expires. You never have to handle tokens yourself.
📱 Step 4 - Receive pushes
// Direct push to this user
client.on('push', msg => {
console.log(`[${msg.type}] ${msg.title}: ${msg.message}`);
console.log('Extra data:', msg.payload);
});
// Track connection status
client.on('connected', () => console.log('Online'));
client.on('disconnected', () => console.log('Offline'));
client.on('reconnected', () => console.log('Reconnected'));
📤 Step 5 - Subscribe to a channel
Channels are namespaced: use a prefix for your app, e.g. myapp/general.
const ch = client.subscribe('myapp/general');
// Receive messages on this channel
ch.bind('message', msg => {
console.log(`[${msg.sender}] ${msg.title}: ${msg.message}`);
});
// Presence: who's online in this channel?
ch.bind('user:list', users => console.log('Online:', users));
ch.bind('user:joined', (uid, meta) => console.log(uid, 'has joined'));
ch.bind('user:left', uid => console.log(uid, 'has left the channel'));
📤 Step 6 - Send a message via channel
Required: Your API key must have the push:send scope.
// Send a chat message to the channelawait ch.send({
type: Skubber.PushType.Chat,
title: 'user123', // username as title
message: 'Hello everyone!',
payload: { avatarUrl: '...' } // optional extra data
});