/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { LivepeerCore } from "../core.js"; import { encodeJSON } from "../lib/encodings.js"; import * as M from "../lib/matchers.js"; import { safeParse } from "../lib/schemas.js"; import { RequestOptions } from "../lib/sdks.js"; import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; import { pathToFunc } from "../lib/url.js"; import * as components from "../models/components/index.js"; import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError, } from "../models/errors/httpclienterrors.js"; import { SDKError } from "../models/errors/sdkerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import * as operations from "../models/operations/index.js"; import { Result } from "../types/fp.js"; /** * Create a stream * * @remarks * The only parameter you are required to set is the name of your stream, * but we also highly recommend that you define transcoding profiles * parameter that suits your specific broadcasting configuration. * \ * \ * If you do not define transcoding rendition profiles when creating the * stream, a default set of profiles will be used. These profiles include * 240p, 360p, 480p and 720p. * \ * \ * The playback policy is set to public by default for new streams. It can * also be added upon the creation of a new stream by adding * `"playbackPolicy": {"type": "jwt"}` */ export async function streamCreate( client: LivepeerCore, request: components.NewStreamPayload, options?: RequestOptions, ): Promise< Result< operations.CreateStreamResponse, | SDKError | SDKValidationError | UnexpectedClientError | InvalidRequestError | RequestAbortedError | RequestTimeoutError | ConnectionError > > { const parsed = safeParse( request, (value) => components.NewStreamPayload$outboundSchema.parse(value), "Input validation failed", ); if (!parsed.ok) { return parsed; } const payload = parsed.value; const body = encodeJSON("body", payload, { explode: true }); const path = pathToFunc("/stream")(); const headers = new Headers({ "Content-Type": "application/json", Accept: "application/json", }); const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; const requestSecurity = resolveGlobalSecurity(securityInput); const context = { operationID: "createStream", oAuth2Scopes: [], resolvedSecurity: requestSecurity, securitySource: client._options.apiKey, retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; const requestRes = client._createRequest(context, { security: requestSecurity, method: "POST", path: path, headers: headers, body: body, timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return requestRes; } const req = requestRes.value; const doResult = await client._do(req, { context, errorCodes: ["4XX", "5XX"], retryConfig: context.retryConfig, retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; } const response = doResult.value; const responseFields = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, RawResponse: response, Headers: {}, }; const [result] = await M.match< operations.CreateStreamResponse, | SDKError | SDKValidationError | UnexpectedClientError | InvalidRequestError | RequestAbortedError | RequestTimeoutError | ConnectionError >( M.json(201, operations.CreateStreamResponse$inboundSchema, { key: "stream", }), M.fail(["4XX", "5XX"]), M.json("default", operations.CreateStreamResponse$inboundSchema, { key: "error", }), )(response, { extraFields: responseFields }); if (!result.ok) { return result; } return result; }