UNPKG

@intuitionrobotics/google-services

Version:
29 lines 1.12 kB
import { Module } from "@intuitionrobotics/ts-common"; import { PubSub } from "@google-cloud/pubsub"; import { AuthModule } from "./AuthModule.js"; import { GoogleAuth } from "google-auth-library"; class PubSubModule_Class extends Module { constructor() { super("PubSubModule"); } project(projectId, authKey = projectId) { const authObject = AuthModule.getAuth(authKey, []); const auth = authObject.auth; const pubSub = new PubSub({ projectId, auth }); return { createTopic: async (topicName) => { const [topic] = await pubSub.createTopic(topicName); return topic; }, topic: (topicName, options) => { const topic = pubSub.topic(topicName, options); return { publishJson: async (json) => topic.publishMessage(json), publish: async (buffer) => topic.publishMessage({ data: buffer }) }; } }; } } export const PubSubModule = new PubSubModule_Class(); //# sourceMappingURL=PubSubModule.js.map