@nexirift/pulsar-js
v2026.1.7-ptb.1
Published
Misskey SDK for JavaScript
Readme
@nexirift/pulsar.js
Strongly-typed official Pulsar SDK for browsers/Node.js.
Official Pulsar SDK for JavaScript (TypeScript). Works on browsers and Node.js.
The following features are provided:
- User authentication
- API requests
- Streaming
- Utility functions
- Various Pulsar type definitions
Compatible with Pulsar version 2025.12.14-ptb.1 and above.
Install
npm i @nexirift/pulsar-jsUsage
It is convenient to import everything together as follows:
import * as Misskey from '@nexirift/pulsar-js';For convenience, subsequent code examples assume that you have imported * as Misskey as shown above.
However, this import method prevents tree-shaking, so for use cases where code size is important, we recommend individual imports like the following:
import { api as misskeyApi } from '@nexirift/pulsar-js';Authenticate
todo
API request
When using the API, initialize an instance of the APIClient class with the server information and access token, then call the request method of that instance to make requests.
const cli = new Misskey.api.APIClient({
origin: 'https://pulsar.test',
credential: 'TOKEN',
});
const meta = await cli.request('meta', { detail: true });The first argument to request is the endpoint name to call, and the second argument is the parameter object. The response is returned as a Promise.
Streaming
pulsar.js streaming provides two classes.
One is the Stream class, which manages the streaming connection itself, and the other is the Channel class, which represents the concept of a channel on the stream.
When using streaming, first initialize an instance of the Stream class, then use the methods of the Stream instance to obtain instances of the Channel class.
const stream = new Misskey.Stream('https://pulsar.test', { token: 'TOKEN' });
const mainChannel = stream.useChannel('main');
mainChannel.on('notification', notification => {
console.log('notification received', notification);
});The connection will automatically reconnect if disconnected.
Connecting to a channel
To connect to a channel, use the useChannel method of the Stream class.
Without parameters
const stream = new Misskey.Stream('https://pulsar.test', { token: 'TOKEN' });
const mainChannel = stream.useChannel('main');With parameters
const stream = new Misskey.Stream('https://pulsar.test', { token: 'TOKEN' });
const chatChannel = stream.useChannel('chat', {
other: 'xxxxxxxxxx',
});Disconnecting from a channel
Call the dispose method of the Channel class.
const stream = new Misskey.Stream('https://pulsar.test', { token: 'TOKEN' });
const mainChannel = stream.useChannel('main');
mainChannel.dispose();Receiving messages
The Channel class extends EventEmitter, and when a message is received from the server, it emits the payload with the received event name.
const stream = new Misskey.Stream('https://pulsar.test', { token: 'TOKEN' });
const mainChannel = stream.useChannel('main');
mainChannel.on('notification', notification => {
console.log('notification received', notification);
});Sending messages
You can use the send method of the Channel class to send messages to the server.
const stream = new Misskey.Stream('https://pulsar.test', { token: 'TOKEN' });
const chatChannel = stream.useChannel('chat', {
other: 'xxxxxxxxxx',
});
chatChannel.send('read', {
id: 'xxxxxxxxxx'
});Connection established event
The _connected_ event of the Stream class is available.
const stream = new Misskey.Stream('https://pulsar.test', { token: 'TOKEN' });
stream.on('_connected_', () => {
console.log('connected');
});Connection disconnected event
The _disconnected_ event of the Stream class is available.
const stream = new Misskey.Stream('https://pulsar.test', { token: 'TOKEN' });
stream.on('_disconnected_', () => {
console.log('disconnected');
});Connection state
You can check it with the state property of the Stream class.
initializing: Before connection is establishedconnected: Connection completedreconnecting: Reconnecting

