UNPKG

sinch-rtc

Version:

RTC JavaScript/Web SDK

44 lines 2.15 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.GzipEncodingMiddleware = void 0; const pako = require("pako"); class GzipEncodingMiddleware { constructor() { this.pre = (context) => __awaiter(this, void 0, void 0, function* () { if (!context.init.body) { return; } let bodyString; if (typeof context.init.body === GzipEncodingMiddleware.TYPE_OBJECT) { bodyString = JSON.stringify(context.init.body); } else if (typeof context.init.body === GzipEncodingMiddleware.TYPE_STRING) { bodyString = context.init.body; } else { console.warn("Unsupported request body type for Gzip compression"); return; } const compressedBody = pako.gzip(bodyString); if (context.init.headers) { context.init.headers[GzipEncodingMiddleware.CONTENT_ENCODING_HEADER] = GzipEncodingMiddleware.CONTENT_ENCODING_GZIP; } context.init.body = compressedBody; }); } } exports.GzipEncodingMiddleware = GzipEncodingMiddleware; GzipEncodingMiddleware.CONTENT_ENCODING_HEADER = "Content-Encoding"; GzipEncodingMiddleware.CONTENT_ENCODING_GZIP = "gzip"; GzipEncodingMiddleware.TYPE_OBJECT = "object"; GzipEncodingMiddleware.TYPE_STRING = "string"; //# sourceMappingURL=GzipEncodingMiddleware.js.map