Client
Usage
Common client patterns for channels, auth, and events.
Subscribe and Bind
const channel = pusher.subscribe("public-updates");
channel.bind("price-updated", (data) => {
console.log(data);
});
Private/Presence Auth
const pusher = new Pusher("app-key", {
cluster: "mt1",
wsHost: "127.0.0.1",
wsPort: 6001,
forceTLS: false,
channelAuthorization: {
endpoint: "https://api.example.com/pusher/auth",
transport: "fetch",
},
});
User Signin
const pusher = new Pusher("app-key", {
cluster: "mt1",
wsHost: "127.0.0.1",
wsPort: 6001,
forceTLS: false,
userAuthentication: {
endpoint: "https://api.example.com/pusher/user-auth",
transport: "fetch",
},
});
pusher.signin();
Client Events
const channel = pusher.subscribe("private-chat");
channel.trigger("client-message", { text: "hello" });
Client event names must start with client-.
Global Events
pusher.bind_global((eventName, data) => {
console.log(eventName, data);
});