UNPKG

@mathrunet/masamune

Version:

Manages packages for the server portion (NodeJS) of the Masamune framework.

144 lines 6.17 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); 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 }); const functions = __importStar(require("firebase-functions/v2")); const agora_token_1 = require("agora-token"); /** * Obtain an Agora.io security token. * * Agora.ioのセキュリティトークンを取得します。 * * @param process.env.AGORA_APP_ID * AppID for Agora. * Log in to the following URL and create a project. * After the project is created, the AppID can be copied. * * Agora用のAppID。 * 下記URLにログインし、プロジェクトを作成します。 * プロジェクト作成後、AppIDをコピーすることができます。 * * https://console.agora.io/projects * * @param process.env.AGORA_APP_CERTIFICATE * AppCertificate for Agora. * You can obtain the certificate after entering the project you created and activating it in Security -> App certificate. * * Agora用のAppCertificate。 * 作成したプロジェクトに入り、Security -> App certificateにて有効化した後取得できます。 * * https://console.agora.io/projects * * @param name * Channel name. * * チャンネル名。 * * @param uid * User ID. either `acount` or one will be used. * * ユーザーID。`acount`とどちらかが利用されます。 * * @param account * Account name. Either `acount` or one of the two will be used. * * アカウント名。`acount`とどちらかが利用されます。 * * @param role * Role. You can specify either "audience" or "broadcaster". * * 役割。"audience"か"broadcaster"が指定できます。 */ module.exports = (regions, options, data) => { var _a, _b, _c, _d; return functions.https.onCall({ region: (_a = options.region) !== null && _a !== void 0 ? _a : regions, timeoutSeconds: options.timeoutSeconds, memory: options.memory, minInstances: options.minInstances, concurrency: options.concurrency, maxInstances: options.maxInstances, serviceAccount: (_b = options === null || options === void 0 ? void 0 : options.serviceAccount) !== null && _b !== void 0 ? _b : undefined, enforceAppCheck: (_c = options.enforceAppCheck) !== null && _c !== void 0 ? _c : undefined, consumeAppCheckToken: (_d = options.consumeAppCheckToken) !== null && _d !== void 0 ? _d : undefined, }, (query) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b; try { const appId = (_a = process.env.AGORA_APP_ID) !== null && _a !== void 0 ? _a : ""; const appCertificate = (_b = process.env.AGORA_APP_CERTIFICATE) !== null && _b !== void 0 ? _b : ""; const expirationTimeInSeconds = 3600; let role = agora_token_1.RtcRole.PUBLISHER; if (query.data.role === "audience") { role = agora_token_1.RtcRole.SUBSCRIBER; } const channelName = query.data.name; const uid = query.data.uid; const account = query.data.account; if (!channelName) { throw new functions.https.HttpsError("invalid-argument", "Channel is invalid."); } if (uid) { const token = agora_token_1.RtcTokenBuilder.buildTokenWithUid(appId, appCertificate, channelName, uid, role, expirationTimeInSeconds, expirationTimeInSeconds); return { channel: channelName, token: token, }; } else if (account) { const token = agora_token_1.RtcTokenBuilder.buildTokenWithUserAccount(appId, appCertificate, channelName, account, role, expirationTimeInSeconds, expirationTimeInSeconds); return { channel: channelName, token: token, }; } else { throw new functions.https.HttpsError("invalid-argument", "uid or account is required."); } } catch (err) { console.error(err); throw err; } })); }; //# sourceMappingURL=agora_token.js.map