UNPKG

nativescript-opentok

Version:
212 lines 8.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var utils = require("tns-core-modules/utils/utils"); var view_1 = require("tns-core-modules/ui/core/view"); var observable_1 = require("tns-core-modules/data/observable"); var CameraListener = com.opentok.android.Publisher.CameraListener; var PublisherListener = com.opentok.android.PublisherKit.PublisherListener; var Publisher = com.opentok.android.Publisher; var BaseVideoRenderer = com.opentok.android.BaseVideoRenderer; var AbsoluteLayout = android.widget.AbsoluteLayout; var RelativeLayout = android.widget.RelativeLayout; var renderStyle = new view_1.CssProperty({ name: 'renderStyle', cssName: 'render-style', defaultValue: 'fill', valueConverter: function (v) { return String(v); } }); var TNSOTPublisher = (function (_super) { __extends(TNSOTPublisher, _super); function TNSOTPublisher() { var _this = _super.call(this) || this; _this._events = observable_1.fromObject({}); return _this; } Object.defineProperty(TNSOTPublisher.prototype, "android", { get: function () { return this.nativeView; }, enumerable: true, configurable: true }); TNSOTPublisher.prototype.createNativeView = function () { return new android.widget.LinearLayout(this._context); }; TNSOTPublisher.prototype.publish = function (session, name, cameraResolution, cameraFrameRate) { var _this = this; var that = new WeakRef(this); this._publisher = new com.opentok.android.Publisher(utils.ad.getApplicationContext(), name ? name : '', TNSOTPublisher.getCameraResolution(cameraResolution), TNSOTPublisher.getCameraFrameRate(cameraFrameRate)); var pub = this._publisher.getView(); this.nativeView.addView(pub); this.renderStyle = this._renderStyle; this._publisher.setPublisherListener(new PublisherListener({ owner: that.get(), onError: function (publisher, error) { if (this.owner._events) { this.owner._events.notify({ eventName: 'didFailWithError', object: observable_1.fromObject({ publisher: publisher, error: error }) }); } }, onStreamCreated: function (publisher, stream) { if (this.owner._events) { this.owner._events.notify({ eventName: 'streamCreated', object: observable_1.fromObject({ publisher: publisher, stream: stream }) }); } }, onStreamDestroyed: function (publisher, stream) { if (this.owner._events) { this.owner._events.notify({ eventName: 'streamDestroyed', object: observable_1.fromObject({ publisher: publisher, stream: stream }) }); } } })); this._publisher.setCameraListener(new CameraListener({ owner: that.get(), onCameraChanged: function (publisher, newCameraId) { if (this.owner._events) { this.owner._events.notify({ eventName: 'cameraChanged', object: observable_1.fromObject({ publisher: publisher, cameraId: newCameraId }) }); } }, onCameraError: function (publisher, error) { if (this.owner._events) { this.owner._events.notify({ eventName: 'cameraError', object: observable_1.fromObject({ publisher: publisher, error: error }) }); } } })); session.events.on('sessionDidConnect', function (result) { try { var stream = result.object; session.session.publish(_this._publisher); } catch (error) { console.log(error); } }); }; TNSOTPublisher.getCameraResolution = function (cameraResolution) { if (cameraResolution) { switch (cameraResolution.toString().toUpperCase()) { case 'LOW': return com.opentok.android.Publisher.CameraCaptureResolution.LOW; case 'MEDIUM': return com.opentok.android.Publisher.CameraCaptureResolution.MEDIUM; case 'HIGH': return com.opentok.android.Publisher.CameraCaptureResolution.HIGH; } } return com.opentok.android.Publisher.CameraCaptureResolution.MEDIUM; }; TNSOTPublisher.getCameraFrameRate = function (cameraFrameRate) { if (cameraFrameRate) { switch (Number(cameraFrameRate)) { case 30: return com.opentok.android.Publisher.CameraCaptureFrameRate.FPS_30; case 15: return com.opentok.android.Publisher.CameraCaptureFrameRate.FPS_15; case 7: return com.opentok.android.Publisher.CameraCaptureFrameRate.FPS_7; case 1: return com.opentok.android.Publisher.CameraCaptureFrameRate.FPS_1; } } return com.opentok.android.Publisher.CameraCaptureFrameRate.FPS_30; }; TNSOTPublisher.prototype[renderStyle.setNative] = function (value) { this._renderStyle = value; switch (value) { case 'fill': this._publisher.getRenderer().setStyle(com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE, com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_FILL); break; case 'scale': this._publisher.getRenderer().setStyle(com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE, com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE); break; default: this._publisher.getRenderer().setStyle(com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE, com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_FIT); break; } }; Object.defineProperty(TNSOTPublisher.prototype, "publisher", { get: function () { return this._publisher; }, enumerable: true, configurable: true }); Object.defineProperty(TNSOTPublisher.prototype, "events", { get: function () { return this._events; }, enumerable: true, configurable: true }); TNSOTPublisher.prototype.toggleCamera = function () { this.publishVideo = !this.publishVideo; }; TNSOTPublisher.prototype.toggleVideo = function () { this.publishVideo = !this.publishVideo; }; TNSOTPublisher.prototype.toggleMute = function () { this.publishAudio = !this.publishAudio; }; Object.defineProperty(TNSOTPublisher.prototype, "publishVideo", { get: function () { return this._publisher.getPublishVideo(); }, set: function (state) { this._publisher.setPublishVideo(state); }, enumerable: true, configurable: true }); Object.defineProperty(TNSOTPublisher.prototype, "publishAudio", { get: function () { return this._publisher.getPublishAudio(); }, set: function (state) { this._publisher.setPublishAudio(state); }, enumerable: true, configurable: true }); TNSOTPublisher.prototype.cycleCamera = function () { this._publisher.cycleCamera(); }; TNSOTPublisher.prototype.instance = function () { return this._publisher; }; TNSOTPublisher.prototype.unpublish = function (session) { session.session.unpublish(this._publisher); }; return TNSOTPublisher; }(view_1.View)); TNSOTPublisher.toggleVideoEvent = "toggleVideo"; TNSOTPublisher.toggleAudioEvent = "toggleAudio"; exports.TNSOTPublisher = TNSOTPublisher; renderStyle.register(view_1.Style); //# sourceMappingURL=publisher.js.map