UNPKG

@fishjam-cloud/js-server-sdk

Version:
1,539 lines (1,537 loc) 221 kB
import { package_default } from "./chunk-3EYSX4WM.mjs"; // ../fishjam-openapi/dist/index.js var BASE_PATH = "https://fishjam.io/api/v1/connect".replace(/\/+$/, ""); var Configuration = class { constructor(configuration = {}) { this.configuration = configuration; } set config(configuration) { this.configuration = configuration; } get basePath() { return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH; } get fetchApi() { return this.configuration.fetchApi; } get middleware() { return this.configuration.middleware || []; } get queryParamsStringify() { return this.configuration.queryParamsStringify || querystring; } get username() { return this.configuration.username; } get password() { return this.configuration.password; } get apiKey() { const apiKey = this.configuration.apiKey; if (apiKey) { return typeof apiKey === "function" ? apiKey : () => apiKey; } return void 0; } get accessToken() { const accessToken = this.configuration.accessToken; if (accessToken) { return typeof accessToken === "function" ? accessToken : async () => accessToken; } return void 0; } get headers() { return this.configuration.headers; } get credentials() { return this.configuration.credentials; } }; var DefaultConfig = new Configuration(); var BaseAPI = class _BaseAPI { constructor(configuration = DefaultConfig) { this.configuration = configuration; this.middleware = configuration.middleware; } static jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; middleware; withMiddleware(...middlewares) { const next = this.clone(); next.middleware = next.middleware.concat(...middlewares); return next; } withPreMiddleware(...preMiddlewares) { const middlewares = preMiddlewares.map((pre) => ({ pre })); return this.withMiddleware(...middlewares); } withPostMiddleware(...postMiddlewares) { const middlewares = postMiddlewares.map((post) => ({ post })); return this.withMiddleware(...middlewares); } /** * Check if the given MIME is a JSON MIME. * JSON MIME examples: * application/json * application/json; charset=UTF8 * APPLICATION/JSON * application/vnd.company+json * @param mime - MIME (Multipurpose Internet Mail Extensions) * @return True if the given MIME is JSON, false otherwise. */ isJsonMime(mime) { if (!mime) { return false; } return _BaseAPI.jsonRegex.test(mime); } async request(context, initOverrides) { const { url, init } = await this.createFetchParams(context, initOverrides); const response = await this.fetchApi(url, init); if (response && (response.status >= 200 && response.status < 300)) { return response; } throw new ResponseError(response, "Response returned an error code"); } async createFetchParams(context, initOverrides) { let url = this.configuration.basePath + context.path; if (context.query !== void 0 && Object.keys(context.query).length !== 0) { url += "?" + this.configuration.queryParamsStringify(context.query); } const headers = Object.assign({}, this.configuration.headers, context.headers); Object.keys(headers).forEach((key) => headers[key] === void 0 ? delete headers[key] : {}); const initOverrideFn = typeof initOverrides === "function" ? initOverrides : async () => initOverrides; const initParams = { method: context.method, headers, body: context.body, credentials: this.configuration.credentials }; const overriddenInit = { ...initParams, ...await initOverrideFn({ init: initParams, context }) }; let body; if (isFormData(overriddenInit.body) || overriddenInit.body instanceof URLSearchParams || isBlob(overriddenInit.body)) { body = overriddenInit.body; } else if (this.isJsonMime(headers["Content-Type"])) { body = JSON.stringify(overriddenInit.body); } else { body = overriddenInit.body; } const init = { ...overriddenInit, body }; return { url, init }; } fetchApi = async (url, init) => { let fetchParams = { url, init }; for (const middleware of this.middleware) { if (middleware.pre) { fetchParams = await middleware.pre({ fetch: this.fetchApi, ...fetchParams }) || fetchParams; } } let response = void 0; try { response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); } catch (e) { for (const middleware of this.middleware) { if (middleware.onError) { response = await middleware.onError({ fetch: this.fetchApi, url: fetchParams.url, init: fetchParams.init, error: e, response: response ? response.clone() : void 0 }) || response; } } if (response === void 0) { if (e instanceof Error) { throw new FetchError(e, "The request failed and the interceptors did not return an alternative response"); } else { throw e; } } } for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ fetch: this.fetchApi, url: fetchParams.url, init: fetchParams.init, response: response.clone() }) || response; } } return response; }; /** * Create a shallow clone of `this` by constructing a new instance * and then shallow cloning data members. */ clone() { const constructor = this.constructor; const next = new constructor(this.configuration); next.middleware = this.middleware.slice(); return next; } }; function isBlob(value) { return typeof Blob !== "undefined" && value instanceof Blob; } function isFormData(value) { return typeof FormData !== "undefined" && value instanceof FormData; } var ResponseError = class extends Error { constructor(response, msg) { super(msg); this.response = response; const actualProto = new.target.prototype; if (Object.setPrototypeOf) { Object.setPrototypeOf(this, actualProto); } } name = "ResponseError"; }; var FetchError = class extends Error { constructor(cause, msg) { super(msg); this.cause = cause; const actualProto = new.target.prototype; if (Object.setPrototypeOf) { Object.setPrototypeOf(this, actualProto); } } name = "FetchError"; }; var RequiredError = class extends Error { constructor(field, msg) { super(msg); this.field = field; const actualProto = new.target.prototype; if (Object.setPrototypeOf) { Object.setPrototypeOf(this, actualProto); } } name = "RequiredError"; }; function querystring(params, prefix = "") { return Object.keys(params).map((key) => querystringSingleKey(key, params[key], prefix)).filter((part) => part.length > 0).join("&"); } function querystringSingleKey(key, value, keyPrefix = "") { const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key); if (value instanceof Array) { const multiValue = value.map((singleValue) => encodeURIComponent(String(singleValue))).join(`&${encodeURIComponent(fullKey)}=`); return `${encodeURIComponent(fullKey)}=${multiValue}`; } if (value instanceof Set) { const valueAsArray = Array.from(value); return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; } if (value instanceof Object) { return querystring(value, fullKey); } return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`; } var JSONApiResponse = class { constructor(raw, transformer = (jsonValue) => jsonValue) { this.raw = raw; this.transformer = transformer; } async value() { return this.transformer(await this.raw.json()); } }; var VoidApiResponse = class { constructor(raw) { this.raw = raw; } async value() { return void 0; } }; var CredentialsApi = class extends BaseAPI { /** * Creates request options for validateCredentials without sending the request */ async validateCredentialsRequestOpts() { const queryParameters = {}; const headerParameters = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/validate`; return { path: urlPath, method: "GET", headers: headerParameters, query: queryParameters }; } /** * Returns 200 if the provided Fishjam Management Token is valid, 404 otherwise. * Validate Fishjam Management Token */ async validateCredentialsRaw(initOverrides) { const requestOptions = await this.validateCredentialsRequestOpts(); const response = await this.request(requestOptions, initOverrides); return new VoidApiResponse(response); } /** * Returns 200 if the provided Fishjam Management Token is valid, 404 otherwise. * Validate Fishjam Management Token */ async validateCredentials(initOverrides) { await this.validateCredentialsRaw(initOverrides); } }; function MoqAccessFromJSON(json) { return MoqAccessFromJSONTyped(json, false); } function MoqAccessFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "connection_url": json["connection_url"], "token": json["token"] }; } function MoqAccessConfigToJSON(json) { return MoqAccessConfigToJSONTyped(json, false); } function MoqAccessConfigToJSONTyped(value, ignoreDiscriminator = false) { if (value == null) { return value; } return { "publishPath": value["publishPath"], "subscribePath": value["subscribePath"] }; } var MoQApi = class extends BaseAPI { /** * Creates request options for createMoqAccess without sending the request */ async createMoqAccessRequestOpts(requestParameters) { const queryParameters = {}; const headerParameters = {}; headerParameters["Content-Type"] = "application/json"; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/moq/access`; return { path: urlPath, method: "POST", headers: headerParameters, query: queryParameters, body: MoqAccessConfigToJSON(requestParameters["moqAccessConfig"]) }; } /** * Issue a short-lived JWT for a Media over QUIC client. * Create MoQ access */ async createMoqAccessRaw(requestParameters, initOverrides) { const requestOptions = await this.createMoqAccessRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new JSONApiResponse(response, (jsonValue) => MoqAccessFromJSON(jsonValue)); } /** * Issue a short-lived JWT for a Media over QUIC client. * Create MoQ access */ async createMoqAccess(requestParameters = {}, initOverrides) { const response = await this.createMoqAccessRaw(requestParameters, initOverrides); return await response.value(); } }; function AudioSampleRateToJSON(value) { return value; } function AudioFormatToJSON(value) { return value; } function AgentOutputToJSON(json) { return AgentOutputToJSONTyped(json, false); } function AgentOutputToJSONTyped(value, ignoreDiscriminator = false) { if (value == null) { return value; } return { "audioFormat": AudioFormatToJSON(value["audioFormat"]), "audioSampleRate": AudioSampleRateToJSON(value["audioSampleRate"]) }; } function SubscribeModeFromJSON(json) { return SubscribeModeFromJSONTyped(json, false); } function SubscribeModeFromJSONTyped(json, ignoreDiscriminator) { return json; } function SubscribeModeToJSON(value) { return value; } function PeerOptionsAgentToJSON(json) { return PeerOptionsAgentToJSONTyped(json, false); } function PeerOptionsAgentToJSONTyped(value, ignoreDiscriminator = false) { if (value == null) { return value; } return { "output": AgentOutputToJSON(value["output"]), "subscribeMode": SubscribeModeToJSON(value["subscribeMode"]) }; } function PeerConfigAgentToJSON(json) { return PeerConfigAgentToJSONTyped(json, false); } function PeerConfigAgentToJSONTyped(value, ignoreDiscriminator = false) { if (value == null) { return value; } return { "options": PeerOptionsAgentToJSON(value["options"]), "type": value["type"] }; } function PeerOptionsVapiToJSON(json) { return PeerOptionsVapiToJSONTyped(json, false); } function PeerOptionsVapiToJSONTyped(value, ignoreDiscriminator = false) { if (value == null) { return value; } return { "apiKey": value["apiKey"], "callId": value["callId"], "subscribeMode": SubscribeModeToJSON(value["subscribeMode"]) }; } function PeerConfigVAPIToJSON(json) { return PeerConfigVAPIToJSONTyped(json, false); } function PeerConfigVAPIToJSONTyped(value, ignoreDiscriminator = false) { if (value == null) { return value; } return { "options": PeerOptionsVapiToJSON(value["options"]), "type": value["type"] }; } function PeerOptionsWebRTCToJSON(json) { return PeerOptionsWebRTCToJSONTyped(json, false); } function PeerOptionsWebRTCToJSONTyped(value, ignoreDiscriminator = false) { if (value == null) { return value; } return { "metadata": value["metadata"], "subscribeMode": SubscribeModeToJSON(value["subscribeMode"]) }; } function PeerConfigWebRTCToJSON(json) { return PeerConfigWebRTCToJSONTyped(json, false); } function PeerConfigWebRTCToJSONTyped(value, ignoreDiscriminator = false) { if (value == null) { return value; } return { "options": PeerOptionsWebRTCToJSON(value["options"]), "type": value["type"] }; } function PeerConfigToJSON(json) { return PeerConfigToJSONTyped(json, false); } function PeerConfigToJSONTyped(value, ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["type"]) { case "agent": return Object.assign({}, PeerConfigAgentToJSON(value), { "type": "agent" }); case "vapi": return Object.assign({}, PeerConfigVAPIToJSON(value), { "type": "vapi" }); case "webrtc": return Object.assign({}, PeerConfigWebRTCToJSON(value), { "type": "webrtc" }); default: return value; } } function SubscriptionsFromJSON(json) { return SubscriptionsFromJSONTyped(json, false); } function SubscriptionsFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "peers": json["peers"], "tracks": json["tracks"] }; } var PeerStatus = { Connected: "connected", Disconnected: "disconnected" }; function PeerStatusFromJSON(json) { return PeerStatusFromJSONTyped(json, false); } function PeerStatusFromJSONTyped(json, ignoreDiscriminator) { return json; } function PeerTypeFromJSON(json) { return PeerTypeFromJSONTyped(json, false); } function PeerTypeFromJSONTyped(json, ignoreDiscriminator) { return json; } function TrackTypeFromJSON(json) { return TrackTypeFromJSONTyped(json, false); } function TrackTypeFromJSONTyped(json, ignoreDiscriminator) { return json; } function TrackFromJSON(json) { return TrackFromJSONTyped(json, false); } function TrackFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "id": json["id"] == null ? void 0 : json["id"], "metadata": json["metadata"] == null ? void 0 : json["metadata"], "type": json["type"] == null ? void 0 : TrackTypeFromJSON(json["type"]) }; } function PeerFromJSON(json) { return PeerFromJSONTyped(json, false); } function PeerFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "id": json["id"], "metadata": json["metadata"], "status": PeerStatusFromJSON(json["status"]), "subscribeMode": SubscribeModeFromJSON(json["subscribeMode"]), "subscriptions": SubscriptionsFromJSON(json["subscriptions"]), "tracks": json["tracks"].map(TrackFromJSON), "type": PeerTypeFromJSON(json["type"]) }; } function PeerDetailsResponseDataFromJSON(json) { return PeerDetailsResponseDataFromJSONTyped(json, false); } function PeerDetailsResponseDataFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "peer": PeerFromJSON(json["peer"]), "peer_websocket_url": json["peer_websocket_url"] == null ? void 0 : json["peer_websocket_url"], "token": json["token"] }; } function PeerDetailsResponseFromJSON(json) { return PeerDetailsResponseFromJSONTyped(json, false); } function PeerDetailsResponseFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "data": PeerDetailsResponseDataFromJSON(json["data"]) }; } function PeerRefreshTokenResponseDataFromJSON(json) { return PeerRefreshTokenResponseDataFromJSONTyped(json, false); } function PeerRefreshTokenResponseDataFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "token": json["token"] }; } function PeerRefreshTokenResponseFromJSON(json) { return PeerRefreshTokenResponseFromJSONTyped(json, false); } function PeerRefreshTokenResponseFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "data": PeerRefreshTokenResponseDataFromJSON(json["data"]) }; } var RoomType = { FullFeature: "full_feature", AudioOnly: "audio_only", Broadcaster: "broadcaster", Livestream: "livestream", Conference: "conference", AudioOnlyLivestream: "audio_only_livestream" }; function RoomTypeFromJSON(json) { return RoomTypeFromJSONTyped(json, false); } function RoomTypeFromJSONTyped(json, ignoreDiscriminator) { return json; } function RoomTypeToJSON(value) { return value; } var VideoCodec = { H264: "h264", Vp8: "vp8" }; function VideoCodecFromJSON(json) { return VideoCodecFromJSONTyped(json, false); } function VideoCodecFromJSONTyped(json, ignoreDiscriminator) { return json; } function VideoCodecToJSON(value) { return value; } function RoomConfigFromJSON(json) { return RoomConfigFromJSONTyped(json, false); } function RoomConfigFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "batchWebhookNotifications": json["batchWebhookNotifications"] == null ? void 0 : json["batchWebhookNotifications"], "maxPeers": json["maxPeers"] == null ? void 0 : json["maxPeers"], "public": json["public"] == null ? void 0 : json["public"], "roomType": json["roomType"] == null ? void 0 : RoomTypeFromJSON(json["roomType"]), "videoCodec": json["videoCodec"] == null ? void 0 : VideoCodecFromJSON(json["videoCodec"]), "webhookUrl": json["webhookUrl"] == null ? void 0 : json["webhookUrl"] }; } function RoomConfigToJSON(json) { return RoomConfigToJSONTyped(json, false); } function RoomConfigToJSONTyped(value, ignoreDiscriminator = false) { if (value == null) { return value; } return { "batchWebhookNotifications": value["batchWebhookNotifications"], "maxPeers": value["maxPeers"], "public": value["public"], "roomType": RoomTypeToJSON(value["roomType"]), "videoCodec": VideoCodecToJSON(value["videoCodec"]), "webhookUrl": value["webhookUrl"] }; } function TrackForwardingInfoFromJSON(json) { return TrackForwardingInfoFromJSONTyped(json, false); } function TrackForwardingInfoFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "audioTrackId": json["audioTrackId"] == null ? void 0 : json["audioTrackId"], "inputId": json["inputId"], "peerId": json["peerId"], "videoTrackId": json["videoTrackId"] == null ? void 0 : json["videoTrackId"] }; } function CompositionInfoFromJSON(json) { return CompositionInfoFromJSONTyped(json, false); } function CompositionInfoFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "compositionUrl": json["compositionUrl"], "forwardings": json["forwardings"].map(TrackForwardingInfoFromJSON) }; } function RoomFromJSON(json) { return RoomFromJSONTyped(json, false); } function RoomFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "compositionInfo": json["compositionInfo"] == null ? void 0 : CompositionInfoFromJSON(json["compositionInfo"]), "config": RoomConfigFromJSON(json["config"]), "id": json["id"], "peers": json["peers"].map(PeerFromJSON) }; } function RoomCreateDetailsResponseDataFromJSON(json) { return RoomCreateDetailsResponseDataFromJSONTyped(json, false); } function RoomCreateDetailsResponseDataFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "room": RoomFromJSON(json["room"]) }; } function RoomCreateDetailsResponseFromJSON(json) { return RoomCreateDetailsResponseFromJSONTyped(json, false); } function RoomCreateDetailsResponseFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "data": RoomCreateDetailsResponseDataFromJSON(json["data"]) }; } function RoomDetailsResponseFromJSON(json) { return RoomDetailsResponseFromJSONTyped(json, false); } function RoomDetailsResponseFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "data": RoomFromJSON(json["data"]) }; } function RoomsListingResponseFromJSON(json) { return RoomsListingResponseFromJSONTyped(json, false); } function RoomsListingResponseFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "data": json["data"].map(RoomFromJSON) }; } function SubscribeTracksRequestToJSON(json) { return SubscribeTracksRequestToJSONTyped(json, false); } function SubscribeTracksRequestToJSONTyped(value, ignoreDiscriminator = false) { if (value == null) { return value; } return { "track_ids": value["track_ids"] }; } var RoomsApi = class extends BaseAPI { /** * Creates request options for addPeer without sending the request */ async addPeerRequestOpts(requestParameters) { if (requestParameters["roomId"] == null) { throw new RequiredError( "roomId", 'Required parameter "roomId" was null or undefined when calling addPeer().' ); } const queryParameters = {}; const headerParameters = {}; headerParameters["Content-Type"] = "application/json"; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/room/{room_id}/peer`; urlPath = urlPath.replace("{room_id}", encodeURIComponent(String(requestParameters["roomId"]))); return { path: urlPath, method: "POST", headers: headerParameters, query: queryParameters, body: PeerConfigToJSON(requestParameters["peerConfig"]) }; } /** * Add a peer to a room and return its connection token. * Create a peer */ async addPeerRaw(requestParameters, initOverrides) { const requestOptions = await this.addPeerRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new JSONApiResponse(response, (jsonValue) => PeerDetailsResponseFromJSON(jsonValue)); } /** * Add a peer to a room and return its connection token. * Create a peer */ async addPeer(requestParameters, initOverrides) { const response = await this.addPeerRaw(requestParameters, initOverrides); return await response.value(); } /** * Creates request options for createRoom without sending the request */ async createRoomRequestOpts(requestParameters) { const queryParameters = {}; const headerParameters = {}; headerParameters["Content-Type"] = "application/json"; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/room`; return { path: urlPath, method: "POST", headers: headerParameters, query: queryParameters, body: RoomConfigToJSON(requestParameters["roomConfig"]) }; } /** * Create a new room with the given configuration. * Create a room */ async createRoomRaw(requestParameters, initOverrides) { const requestOptions = await this.createRoomRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new JSONApiResponse(response, (jsonValue) => RoomCreateDetailsResponseFromJSON(jsonValue)); } /** * Create a new room with the given configuration. * Create a room */ async createRoom(requestParameters = {}, initOverrides) { const response = await this.createRoomRaw(requestParameters, initOverrides); return await response.value(); } /** * Creates request options for deletePeer without sending the request */ async deletePeerRequestOpts(requestParameters) { if (requestParameters["roomId"] == null) { throw new RequiredError( "roomId", 'Required parameter "roomId" was null or undefined when calling deletePeer().' ); } if (requestParameters["id"] == null) { throw new RequiredError( "id", 'Required parameter "id" was null or undefined when calling deletePeer().' ); } const queryParameters = {}; const headerParameters = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/room/{room_id}/peer/{id}`; urlPath = urlPath.replace("{room_id}", encodeURIComponent(String(requestParameters["roomId"]))); urlPath = urlPath.replace("{id}", encodeURIComponent(String(requestParameters["id"]))); return { path: urlPath, method: "DELETE", headers: headerParameters, query: queryParameters }; } /** * Remove a peer from a room and disconnect it. * Delete a peer */ async deletePeerRaw(requestParameters, initOverrides) { const requestOptions = await this.deletePeerRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new VoidApiResponse(response); } /** * Remove a peer from a room and disconnect it. * Delete a peer */ async deletePeer(requestParameters, initOverrides) { await this.deletePeerRaw(requestParameters, initOverrides); } /** * Creates request options for deleteRoom without sending the request */ async deleteRoomRequestOpts(requestParameters) { if (requestParameters["roomId"] == null) { throw new RequiredError( "roomId", 'Required parameter "roomId" was null or undefined when calling deleteRoom().' ); } const queryParameters = {}; const headerParameters = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/room/{room_id}`; urlPath = urlPath.replace("{room_id}", encodeURIComponent(String(requestParameters["roomId"]))); return { path: urlPath, method: "DELETE", headers: headerParameters, query: queryParameters }; } /** * Delete a room by id and disconnect all of its peers. * Delete a room */ async deleteRoomRaw(requestParameters, initOverrides) { const requestOptions = await this.deleteRoomRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new VoidApiResponse(response); } /** * Delete a room by id and disconnect all of its peers. * Delete a room */ async deleteRoom(requestParameters, initOverrides) { await this.deleteRoomRaw(requestParameters, initOverrides); } /** * Creates request options for getAllRooms without sending the request */ async getAllRoomsRequestOpts() { const queryParameters = {}; const headerParameters = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/room`; return { path: urlPath, method: "GET", headers: headerParameters, query: queryParameters }; } /** * List all rooms and livestreams. * List all rooms */ async getAllRoomsRaw(initOverrides) { const requestOptions = await this.getAllRoomsRequestOpts(); const response = await this.request(requestOptions, initOverrides); return new JSONApiResponse(response, (jsonValue) => RoomsListingResponseFromJSON(jsonValue)); } /** * List all rooms and livestreams. * List all rooms */ async getAllRooms(initOverrides) { const response = await this.getAllRoomsRaw(initOverrides); return await response.value(); } /** * Creates request options for getRoom without sending the request */ async getRoomRequestOpts(requestParameters) { if (requestParameters["roomId"] == null) { throw new RequiredError( "roomId", 'Required parameter "roomId" was null or undefined when calling getRoom().' ); } const queryParameters = {}; const headerParameters = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/room/{room_id}`; urlPath = urlPath.replace("{room_id}", encodeURIComponent(String(requestParameters["roomId"]))); return { path: urlPath, method: "GET", headers: headerParameters, query: queryParameters }; } /** * Get a room by id. * Get a room */ async getRoomRaw(requestParameters, initOverrides) { const requestOptions = await this.getRoomRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new JSONApiResponse(response, (jsonValue) => RoomDetailsResponseFromJSON(jsonValue)); } /** * Get a room by id. * Get a room */ async getRoom(requestParameters, initOverrides) { const response = await this.getRoomRaw(requestParameters, initOverrides); return await response.value(); } /** * Creates request options for refreshToken without sending the request */ async refreshTokenRequestOpts(requestParameters) { if (requestParameters["roomId"] == null) { throw new RequiredError( "roomId", 'Required parameter "roomId" was null or undefined when calling refreshToken().' ); } if (requestParameters["id"] == null) { throw new RequiredError( "id", 'Required parameter "id" was null or undefined when calling refreshToken().' ); } const queryParameters = {}; const headerParameters = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/room/{room_id}/peer/{id}/refresh_token`; urlPath = urlPath.replace("{room_id}", encodeURIComponent(String(requestParameters["roomId"]))); urlPath = urlPath.replace("{id}", encodeURIComponent(String(requestParameters["id"]))); return { path: urlPath, method: "POST", headers: headerParameters, query: queryParameters }; } /** * Issue a fresh connection token for an existing peer. * Refresh a peer token */ async refreshTokenRaw(requestParameters, initOverrides) { const requestOptions = await this.refreshTokenRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new JSONApiResponse(response, (jsonValue) => PeerRefreshTokenResponseFromJSON(jsonValue)); } /** * Issue a fresh connection token for an existing peer. * Refresh a peer token */ async refreshToken(requestParameters, initOverrides) { const response = await this.refreshTokenRaw(requestParameters, initOverrides); return await response.value(); } /** * Creates request options for subscribePeer without sending the request */ async subscribePeerRequestOpts(requestParameters) { if (requestParameters["roomId"] == null) { throw new RequiredError( "roomId", 'Required parameter "roomId" was null or undefined when calling subscribePeer().' ); } if (requestParameters["id"] == null) { throw new RequiredError( "id", 'Required parameter "id" was null or undefined when calling subscribePeer().' ); } const queryParameters = {}; if (requestParameters["peerId"] != null) { queryParameters["peer_id"] = requestParameters["peerId"]; } const headerParameters = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/room/{room_id}/peer/{id}/subscribe_peer`; urlPath = urlPath.replace("{room_id}", encodeURIComponent(String(requestParameters["roomId"]))); urlPath = urlPath.replace("{id}", encodeURIComponent(String(requestParameters["id"]))); return { path: urlPath, method: "POST", headers: headerParameters, query: queryParameters }; } /** * Subscribe a peer to all current and future tracks published by another peer in the same room. * Subscribe a peer to another peer\'s tracks */ async subscribePeerRaw(requestParameters, initOverrides) { const requestOptions = await this.subscribePeerRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new VoidApiResponse(response); } /** * Subscribe a peer to all current and future tracks published by another peer in the same room. * Subscribe a peer to another peer\'s tracks */ async subscribePeer(requestParameters, initOverrides) { await this.subscribePeerRaw(requestParameters, initOverrides); } /** * Creates request options for subscribeTracks without sending the request */ async subscribeTracksRequestOpts(requestParameters) { if (requestParameters["roomId"] == null) { throw new RequiredError( "roomId", 'Required parameter "roomId" was null or undefined when calling subscribeTracks().' ); } if (requestParameters["id"] == null) { throw new RequiredError( "id", 'Required parameter "id" was null or undefined when calling subscribeTracks().' ); } const queryParameters = {}; const headerParameters = {}; headerParameters["Content-Type"] = "application/json"; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/room/{room_id}/peer/{id}/subscribe_tracks`; urlPath = urlPath.replace("{room_id}", encodeURIComponent(String(requestParameters["roomId"]))); urlPath = urlPath.replace("{id}", encodeURIComponent(String(requestParameters["id"]))); return { path: urlPath, method: "POST", headers: headerParameters, query: queryParameters, body: SubscribeTracksRequestToJSON(requestParameters["subscribeTracksRequest"]) }; } /** * Subscribe a peer to a specific list of track IDs in the same room. * Subscribe a peer to specific tracks */ async subscribeTracksRaw(requestParameters, initOverrides) { const requestOptions = await this.subscribeTracksRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new VoidApiResponse(response); } /** * Subscribe a peer to a specific list of track IDs in the same room. * Subscribe a peer to specific tracks */ async subscribeTracks(requestParameters, initOverrides) { await this.subscribeTracksRaw(requestParameters, initOverrides); } }; function StreamerFromJSON(json) { return StreamerFromJSONTyped(json, false); } function StreamerFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "id": json["id"], "status": json["status"], "token": json["token"] }; } function StreamerDetailsResponseFromJSON(json) { return StreamerDetailsResponseFromJSONTyped(json, false); } function StreamerDetailsResponseFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "data": StreamerFromJSON(json["data"]) }; } function StreamerTokenFromJSON(json) { return StreamerTokenFromJSONTyped(json, false); } function StreamerTokenFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "token": json["token"] }; } var StreamersApi = class extends BaseAPI { /** * Creates request options for createStreamer without sending the request */ async createStreamerRequestOpts(requestParameters) { if (requestParameters["streamId"] == null) { throw new RequiredError( "streamId", 'Required parameter "streamId" was null or undefined when calling createStreamer().' ); } const queryParameters = {}; const headerParameters = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/livestream/{stream_id}/streamer`; urlPath = urlPath.replace("{stream_id}", encodeURIComponent(String(requestParameters["streamId"]))); return { path: urlPath, method: "POST", headers: headerParameters, query: queryParameters }; } /** * Create a streamer for a stream and return its credentials. * Create a streamer */ async createStreamerRaw(requestParameters, initOverrides) { const requestOptions = await this.createStreamerRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new JSONApiResponse(response, (jsonValue) => StreamerDetailsResponseFromJSON(jsonValue)); } /** * Create a streamer for a stream and return its credentials. * Create a streamer */ async createStreamer(requestParameters, initOverrides) { const response = await this.createStreamerRaw(requestParameters, initOverrides); return await response.value(); } /** * Creates request options for deleteStreamer without sending the request */ async deleteStreamerRequestOpts(requestParameters) { if (requestParameters["streamId"] == null) { throw new RequiredError( "streamId", 'Required parameter "streamId" was null or undefined when calling deleteStreamer().' ); } if (requestParameters["streamerId"] == null) { throw new RequiredError( "streamerId", 'Required parameter "streamerId" was null or undefined when calling deleteStreamer().' ); } const queryParameters = {}; const headerParameters = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/livestream/{stream_id}/streamer/{streamer_id}`; urlPath = urlPath.replace("{stream_id}", encodeURIComponent(String(requestParameters["streamId"]))); urlPath = urlPath.replace("{streamer_id}", encodeURIComponent(String(requestParameters["streamerId"]))); return { path: urlPath, method: "DELETE", headers: headerParameters, query: queryParameters }; } /** * Delete a streamer from a stream and revoke its token. * Delete a streamer */ async deleteStreamerRaw(requestParameters, initOverrides) { const requestOptions = await this.deleteStreamerRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new VoidApiResponse(response); } /** * Delete a streamer from a stream and revoke its token. * Delete a streamer */ async deleteStreamer(requestParameters, initOverrides) { await this.deleteStreamerRaw(requestParameters, initOverrides); } /** * Creates request options for generateStreamerToken without sending the request */ async generateStreamerTokenRequestOpts(requestParameters) { if (requestParameters["roomId"] == null) { throw new RequiredError( "roomId", 'Required parameter "roomId" was null or undefined when calling generateStreamerToken().' ); } const queryParameters = {}; const headerParameters = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/room/{room_id}/streamer`; urlPath = urlPath.replace("{room_id}", encodeURIComponent(String(requestParameters["roomId"]))); return { path: urlPath, method: "POST", headers: headerParameters, query: queryParameters }; } /** * Issue a fresh streamer token. * Create a streamer token */ async generateStreamerTokenRaw(requestParameters, initOverrides) { const requestOptions = await this.generateStreamerTokenRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new JSONApiResponse(response, (jsonValue) => StreamerTokenFromJSON(jsonValue)); } /** * Issue a fresh streamer token. * Create a streamer token */ async generateStreamerToken(requestParameters, initOverrides) { const response = await this.generateStreamerTokenRaw(requestParameters, initOverrides); return await response.value(); } }; function ViewerFromJSON(json) { return ViewerFromJSONTyped(json, false); } function ViewerFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "id": json["id"], "token": json["token"] }; } function ViewerDetailsResponseFromJSON(json) { return ViewerDetailsResponseFromJSONTyped(json, false); } function ViewerDetailsResponseFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "data": ViewerFromJSON(json["data"]) }; } function ViewerTokenFromJSON(json) { return ViewerTokenFromJSONTyped(json, false); } function ViewerTokenFromJSONTyped(json, ignoreDiscriminator) { if (json == null) { return json; } return { "token": json["token"] }; } var ViewersApi = class extends BaseAPI { /** * Creates request options for createViewer without sending the request */ async createViewerRequestOpts(requestParameters) { if (requestParameters["streamId"] == null) { throw new RequiredError( "streamId", 'Required parameter "streamId" was null or undefined when calling createViewer().' ); } const queryParameters = {}; const headerParameters = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/livestream/{stream_id}/viewer`; urlPath = urlPath.replace("{stream_id}", encodeURIComponent(String(requestParameters["streamId"]))); return { path: urlPath, method: "POST", headers: headerParameters, query: queryParameters }; } /** * Create a viewer for a stream and return its credentials. * Create a viewer */ async createViewerRaw(requestParameters, initOverrides) { const requestOptions = await this.createViewerRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new JSONApiResponse(response, (jsonValue) => ViewerDetailsResponseFromJSON(jsonValue)); } /** * Create a viewer for a stream and return its credentials. * Create a viewer */ async createViewer(requestParameters, initOverrides) { const response = await this.createViewerRaw(requestParameters, initOverrides); return await response.value(); } /** * Creates request options for deleteViewer without sending the request */ async deleteViewerRequestOpts(requestParameters) { if (requestParameters["streamId"] == null) { throw new RequiredError( "streamId", 'Required parameter "streamId" was null or undefined when calling deleteViewer().' ); } if (requestParameters["viewerId"] == null) { throw new RequiredError( "viewerId", 'Required parameter "viewerId" was null or undefined when calling deleteViewer().' ); } const queryParameters = {}; const headerParameters = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/livestream/{stream_id}/viewer/{viewer_id}`; urlPath = urlPath.replace("{stream_id}", encodeURIComponent(String(requestParameters["streamId"]))); urlPath = urlPath.replace("{viewer_id}", encodeURIComponent(String(requestParameters["viewerId"]))); return { path: urlPath, method: "DELETE", headers: headerParameters, query: queryParameters }; } /** * Delete a viewer from a stream and revoke its token. * Delete a viewer */ async deleteViewerRaw(requestParameters, initOverrides) { const requestOptions = await this.deleteViewerRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new VoidApiResponse(response); } /** * Delete a viewer from a stream and revoke its token. * Delete a viewer */ async deleteViewer(requestParameters, initOverrides) { await this.deleteViewerRaw(requestParameters, initOverrides); } /** * Creates request options for generateViewerToken without sending the request */ async generateViewerTokenRequestOpts(requestParameters) { if (requestParameters["roomId"] == null) { throw new RequiredError( "roomId", 'Required parameter "roomId" was null or undefined when calling generateViewerToken().' ); } const queryParameters = {}; const headerParameters = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("management_token", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/room/{room_id}/viewer`; urlPath = urlPath.replace("{room_id}", encodeURIComponent(String(requestParameters["roomId"]))); return { path: urlPath, method: "POST", headers: headerParameters, query: queryParameters }; } /** * Issue a fresh viewer token. * Create a viewer token */ async generateViewerTokenRaw(requestParameters, initOverrides) { const requestOptions = await this.generateViewerTokenRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new JSONApiResponse(response, (jsonValue) => ViewerTokenFromJSON(jsonValue)); } /** * Issue a fresh viewer token. * Create a viewer token */ async generateViewerToken(requestParameters, initOverrides) { const response = await this.generateViewerTokenRaw(requestParameters, initOverrides); return await response.value(); } }; // ../fishjam-proto/dist/index.js function varint64read() {