pingerchips-js-server
v2.0.0
Published
Pingerchips server SDK for Node.js - trigger events and authenticate users
Downloads
7
Maintainers
Readme
Pingerchips Server SDK
Server-side SDK for triggering events and authenticating users with Pingerchips.
Installation
npm install pingerchips-js-serverUsage
Initialize
import PingerchipsServer from 'pingerchips-js-server';
const pingerchips = new PingerchipsServer('app_id', 'app_secret', {
appKey: 'app_key',
endpoint: 'https://pinger-processor.pingerchips.com/api'
});Trigger Events
Send events to channels from your server:
await pingerchips.trigger('lobby', 'message', {
text: 'Hello from server!',
timestamp: Date.now()
});Authenticate Users (Private/Presence Channels)
Implement an auth endpoint on your server:
import express from 'express';
const app = express();
app.use(express.json());
app.post('/auth', (req, res) => {
const { socket_id, channel_name, auth_info } = req.body;
// Validate user from session/token
const user = validateUser(auth_info);
if (!user) {
return res.status(403).json({ error: 'Unauthorized' });
}
// For presence channels, provide user data
const userData = channel_name.startsWith('presence-') ? {
user_id: user.id,
user_info: {
name: user.name,
avatar: user.avatar
}
} : null;
// Sign authentication with Pingerchips
const authData = pingerchips.authenticate(socket_id, channel_name, userData);
res.json(authData);
});API Reference
new PingerchipsServer(appId, appSecret, options)
Create a new server instance.
Options:
appKey- Your app key (required for authentication)endpoint- API endpoint URLtoken- API token for internal endpointsmtls- mTLS configuration for secure connections
trigger(channel, event, data)
Send an event to a channel.
await pingerchips.trigger('my-channel', 'my-event', { message: 'Hello' });authenticate(socketId, channelName, userData?)
Generate signed authentication for private/presence channels.
Parameters:
socketId- Socket ID from clientchannelName- Channel name (e.g., "private-chat" or "presence-lobby")userData- User data for presence channels (must includeuser_id)
Returns:
{
auth: "app_key:hmac_signature",
channel_data: "{\"user_id\":\"123\",...}" // presence channels only
}mTLS Support
For secure server-to-server communication:
const pingerchips = new PingerchipsServer('app_id', 'app_secret', {
endpoint: 'https://pinger-processor.pingerchips.com/api',
mtls: {
enabled: true,
cert: '/path/to/client-cert.pem',
key: '/path/to/client-key.pem',
ca: '/path/to/ca-cert.pem'
}
});License
MIT
