nativescript-opentok-arth
Version:
Integrates OpenTok for NativeScript.
221 lines • 8.79 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils = require("utils/utils");
var content_view_1 = require("ui/content-view");
var observable_1 = require("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 TNSOTPublisher = (function (_super) {
__extends(TNSOTPublisher, _super);
function TNSOTPublisher() {
var _this = _super.call(this) || this;
_this._events = new observable_1.Observable();
return _this;
}
Object.defineProperty(TNSOTPublisher.prototype, "android", {
get: function () {
return this._android;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TNSOTPublisher.prototype, "_nativeView", {
get: function () {
return this._android;
},
enumerable: true,
configurable: true
});
TNSOTPublisher.prototype._createUI = function () {
this._android = 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._android.addView(pub);
this._publisher.getRenderer().setStyle(com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE, this.render_style);
this._publisher.setPublisherListener(new PublisherListener({
owner: that.get(),
onError: function (publisher, error) {
if (this.owner._events) {
this.owner._events.notify({
eventName: 'didFailWithError',
object: new observable_1.Observable({
publisher: publisher,
error: error
})
});
}
},
onStreamCreated: function (publisher, stream) {
if (this.owner._events) {
this.owner._events.notify({
eventName: 'streamCreated',
object: new observable_1.Observable({
publisher: publisher,
stream: stream
})
});
}
},
onStreamDestroyed: function (publisher, stream) {
if (this.owner._events) {
this.owner._events.notify({
eventName: 'streamDestroyed',
object: new observable_1.Observable({
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: new observable_1.Observable({
publisher: publisher,
cameraId: newCameraId
})
});
}
}, onCameraError: function (publisher, error) {
if (this.owner._events) {
this.owner._events.notify({
eventName: 'cameraError',
object: new observable_1.Observable({
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;
};
Object.defineProperty(TNSOTPublisher.prototype, "render_style", {
get: function () {
return this._render_style;
},
set: function (value) {
switch (value) {
case 'fit':
this._render_style = com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_FIT;
break;
case 'fill':
this._render_style = com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_FILL;
break;
case 'scale':
this._render_style = com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE;
break;
default:
this._render_style = com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_FIT;
break;
}
},
enumerable: true,
configurable: true
});
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;
}(content_view_1.ContentView));
TNSOTPublisher.toggleVideoEvent = "toggleVideo";
TNSOTPublisher.toggleAudioEvent = "toggleAudio";
exports.TNSOTPublisher = TNSOTPublisher;
//# sourceMappingURL=publisher.js.map