import { Connection } from "@zenpub/javascript/dist/cjs";
const connection = new Connection({
authorization: "TOKEN",
address: "HOST",
port: 1000,
secure: true, // SSL
debug: false, // Skip logging
secret: "SECRET", // For server applications
});
const instance = await connection.connect();
try {
const channel = await instance.subscribe("notifications");
channel.on((message: string) => {
console.log(message);
})
} catch (e: any) {
console.log("Unauthorized");
}
try {
const channel = await instance.private("notifications");
channel.on((message: string) => {
console.log(message);
})
} catch (e: any) {
console.log("Unauthorized");
}
If secret
isn't passed as option then:
const channel = "notifications";
const input = `${instance.session.id}@private.${channel}`;
const secret = "secret";
const hash = Encrypt.make(secret, input);
const channel = await instance.private(channel, hash);