UNPKG

infobip-rtc

Version:

Infobip RTC JavaScript SDK - Infobip WebRTC API Implementation

68 lines 3.17 kB
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()); }); }; import VideoType from "../../util/VideoType"; export class AbstractCapturer { constructor(localCameraStream, localScreenShareStream, remotePeerConnection, mid, currentUserIdentity) { this.localCameraStream = localCameraStream; this.localScreenShareStream = localScreenShareStream; this.remotePeerConnection = remotePeerConnection; this.mid = mid; this.currentUserIdentity = currentUserIdentity; } getCanvas(identity, videoType) { return __awaiter(this, void 0, void 0, function* () { let videoStream = this.getVideoStream(identity, videoType); if (!videoStream) { throw new Error(`Video not found for identity ${identity} and video type ${videoType}`); } return this.drawImage(videoStream); }); } drawImage(videoStream) { return __awaiter(this, void 0, void 0, function* () { const video = yield this.getVideoElement(videoStream); let canvas = document.createElement('canvas'); canvas.width = video.videoWidth; canvas.height = video.videoHeight; canvas.getContext('2d').drawImage(video, 0, 0, video.videoWidth, video.videoHeight); video.srcObject = null; return canvas; }); } getVideoStream(identity, videoType) { var _a; if (identity === this.currentUserIdentity) { return videoType === VideoType.CAMERA ? this.localCameraStream() : this.localScreenShareStream(); } else { const mid = this.mid(identity, videoType); for (const transceiver of (_a = this.remotePeerConnection()) === null || _a === void 0 ? void 0 : _a.getTransceivers()) { if (transceiver.mid === mid) { return new MediaStream([transceiver.receiver.track]); } } } return null; } getVideoElement(stream) { return __awaiter(this, void 0, void 0, function* () { const video = document.createElement('video'); const track = stream.getVideoTracks()[0]; video.width = track.getSettings().width; video.height = track.getSettings().height; video.autoplay = true; video.playsInline = true; video.srcObject = stream; yield video.play(); return video; }); } } //# sourceMappingURL=AbstractCapturer.js.map