UNPKG

sinch-rtc

Version:

RTC JavaScript/Web SDK

99 lines 4.66 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.DefaultSinchClientBuilder = void 0; const DefaultSinchClient_1 = require("./DefaultSinchClient"); const DefaultMediaStreamFactory_1 = require("./rtc/DefaultMediaStreamFactory"); const MediaManager_1 = require("./rtc/MediaManager"); const utils_1 = require("./utils"); const Errors_1 = require("./utils/Errors"); class DefaultSinchClientBuilder { userId(userId) { if (!userId) throw new Errors_1.ArgumentError("userId must not be null or empty", (0, utils_1.nameof)(userId)); this.clientUserId = userId; return this; } applicationKey(applicationKey) { if (!applicationKey) throw new Errors_1.ArgumentError("applicastionKey must not be null or empty", (0, utils_1.nameof)(applicationKey)); this.clientApplicationKey = applicationKey; return this; } environmentHost(environmentHost) { if (!environmentHost) throw new Errors_1.ArgumentError("environmentHost must not be null or empty", (0, utils_1.nameof)(environmentHost)); this.clientEnvironmentHost = environmentHost; return this; } callerIdentifier(callerIdentifier) { if (!callerIdentifier) throw new Errors_1.ArgumentError("callerIdentifier must not be null or empty", (0, utils_1.nameof)(callerIdentifier)); this.clientCallerIdentifier = callerIdentifier; return this; } fetchApi(fetchApi) { if (!fetchApi) throw new Errors_1.ArgumentError("fetchApi must not be null", (0, utils_1.nameof)(fetchApi)); this.clientFetchApi = fetchApi; return this; } mediaStreamFactory(mediaStreamFactory) { this.clientMediaStreamFactory = mediaStreamFactory; return this; } videoConfiguration(videoConstraints) { this.clientVideoConstraints = videoConstraints; return this; } // add silent stream factory for testing, not in public api silentMediaStream() { const ctx = new AudioContext(); const oscillator = ctx.createOscillator(); const dst = oscillator.connect(ctx.createMediaStreamDestination()); this.mediaStreamFactory({ getMediaStream: (_) => __awaiter(this, void 0, void 0, function* () { return new MediaStream([ Object.assign(dst.stream.getAudioTracks()[0], { enabled: false, }), ]); }), }); return this; } getDefaultMediaStreamFactory() { var _a; return new DefaultMediaStreamFactory_1.DefaultMediaStreamFactory((_a = this.clientVideoConstraints) !== null && _a !== void 0 ? _a : { width: { ideal: 640 }, height: { ideal: 480 }, }); } build() { var _a; if (!this.clientApplicationKey) throw new Errors_1.ArgumentError("applicationKey must be set", (0, utils_1.nameof)(this.clientApplicationKey)); if (!this.clientUserId) throw new Errors_1.ArgumentError("userId must be set", (0, utils_1.nameof)(this.clientUserId)); if (!this.clientEnvironmentHost) throw new Errors_1.ArgumentError("environmentHost must be set", (0, utils_1.nameof)(this.clientEnvironmentHost)); return new DefaultSinchClient_1.DefaultSinchClient({ applicationKey: this.clientApplicationKey, userId: this.clientUserId, baseUrl: this.clientEnvironmentHost, callerIdentifier: this.clientCallerIdentifier, fetchApi: this.clientFetchApi, mediaManager: new MediaManager_1.MediaManager((_a = this.clientMediaStreamFactory) !== null && _a !== void 0 ? _a : this.getDefaultMediaStreamFactory()), }); } } exports.DefaultSinchClientBuilder = DefaultSinchClientBuilder; //# sourceMappingURL=DefaultSinchClientBuilder.js.map