UNPKG

livelists-node-js

Version:
51 lines 2.37 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChannelClient = void 0; const TwirpRPC_1 = require("../common/TwirpRPC"); const RPCPackages_1 = require("../common/const/RPCPackages"); const channel_1 = require("../proto/channel"); const BaseService_1 = __importDefault(require("./BaseService")); const ChannelErrors_1 = require("./errors/ChannelErrors"); const svc = 'ChannelService'; class ChannelClient extends BaseService_1.default { constructor({ apiHost, apiKey, secretKey, }) { super(apiKey, secretKey); this.rpc = new TwirpRPC_1.TwirpRpc({ host: apiHost, pkg: RPCPackages_1.RPCPackages.Channel, }); } createChannel({ identifier, maxParticipants, customData, }) { return __awaiter(this, void 0, void 0, function* () { const req = channel_1.CreateChannelReq.toJSON({ maxParticipants, identifier, customData: customData ? { data: customData } : undefined, }); const response = yield this.rpc.request({ service: svc, method: 'CreateChannel', data: req, headers: this.rootAuthHeader(), }); if (response.errors.length > 0 || !response.channel) { throw new ChannelErrors_1.CreateChannelError(response); } return response.channel; }); } } exports.ChannelClient = ChannelClient; //# sourceMappingURL=ChannelClient.js.map