2023-04-20 04:20:00 -06:00
|
|
|
import Ably from "ably";
|
|
|
|
import { env } from "~/env.mjs";
|
2023-07-11 17:22:54 -06:00
|
|
|
import type { EventType } from "../utils/types";
|
2023-04-20 04:20:00 -06:00
|
|
|
|
|
|
|
const ably = new Ably.Realtime.Promise(env.ABLY_PRIVATE_KEY);
|
|
|
|
|
|
|
|
export const publishToChannel = async (
|
|
|
|
channel: string,
|
|
|
|
event: EventType,
|
|
|
|
message: string
|
|
|
|
) => {
|
|
|
|
const channelName = ably.channels.get(`${env.APP_ENV}-${channel}`);
|
|
|
|
await channelName.publish(event, message);
|
|
|
|
};
|