UNPKG

@intuitionrobotics/google-services

Version:
41 lines 2.06 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PubSubModule = void 0; const ts_common_1 = require("@intuitionrobotics/ts-common"); const pubsub_1 = require("@google-cloud/pubsub"); const AuthModule_1 = require("./AuthModule"); class PubSubModule_Class extends ts_common_1.Module { constructor() { super("PubSubModule"); } project(projectId, authKey = projectId) { const authObject = AuthModule_1.AuthModule.getAuth(authKey, []); const auth = authObject.auth; // @ts-ignore const pubSub = new pubsub_1.PubSub({ projectId, auth }); return { createTopic: (topicName) => __awaiter(this, void 0, void 0, function* () { const [topic] = yield pubSub.createTopic(topicName); return topic; }), topic: (topicName, options) => { const topic = pubSub.topic(topicName, options); return { publishJson: (json) => __awaiter(this, void 0, void 0, function* () { return topic.publishMessage(json); }), publish: (buffer) => __awaiter(this, void 0, void 0, function* () { return topic.publishMessage({ data: buffer }); }) }; } }; } } exports.PubSubModule = new PubSubModule_Class(); //# sourceMappingURL=PubSubModule.js.map