nativescript-opentok-arth
Version:
Integrates OpenTok for NativeScript.
183 lines • 6.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var observable_1 = require("data/observable");
var content_view_1 = require("ui/content-view");
var TNSOTPublisher = (function (_super) {
__extends(TNSOTPublisher, _super);
function TNSOTPublisher() {
var _this = _super.call(this) || this;
_this._ios = {};
_this._view = UIView.alloc().init();
_this._publisherKitDelegate = TNSPublisherKitDelegateImpl.initWithOwner(new WeakRef(_this));
return _this;
}
TNSOTPublisher.prototype.publish = function (session, name, cameraResolution, cameraFrameRate) {
var _this = this;
this._ios = OTPublisher.alloc().initWithDelegateNameCameraResolutionCameraFrameRate(this._publisherKitDelegate, name ? name : '', this.getCameraResolution(cameraResolution), this.getCameraFrameRate(cameraFrameRate));
this._ios.view.frame = CGRectMake(0, 0, this.width, this.height);
this._view.addSubview(this._ios.view);
session.events.on('sessionDidConnect', function (result) {
_this._ios.publishAudio = true;
var stream = result.object;
_this.setIdleTimer(true);
try {
stream.session.publish(_this._ios);
}
catch (error) {
console.log(error);
}
});
};
TNSOTPublisher.prototype.unpublish = function (session) {
try {
if (session) {
var errorRef = new interop.Reference();
this.setIdleTimer(false);
session._ios.unpublishError(this._ios, errorRef);
if (errorRef.value) {
console.log(errorRef.value);
}
}
}
catch (error) {
console.log(error);
}
};
Object.defineProperty(TNSOTPublisher.prototype, "ios", {
get: function () {
return this._ios;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TNSOTPublisher.prototype, "_nativeView", {
get: function () {
return this._view;
},
enumerable: true,
configurable: true
});
TNSOTPublisher.prototype.setIdleTimer = function (idleTimerDisabled) {
var app;
if (UIApplication.sharedApplication) {
app = UIApplication.sharedApplication;
}
else {
app = UIApplication.sharedApplication();
}
app.idleTimerDisabled = idleTimerDisabled;
};
TNSOTPublisher.prototype.getCameraResolution = function (cameraResolution) {
if (cameraResolution) {
switch (cameraResolution) {
case 'LOW':
return OTCameraCaptureResolution.OTCameraCaptureResolutionLow;
case 'MEDIUM':
return OTCameraCaptureResolution.OTCameraCaptureResolutionMedium;
case 'HIGH':
return OTCameraCaptureResolution.OTCameraCaptureResolutionHigh;
}
}
return OTCameraCaptureResolution.OTCameraCaptureResolutionMedium;
};
TNSOTPublisher.prototype.getCameraFrameRate = function (cameraFrameRate) {
if (cameraFrameRate) {
switch (Number(cameraFrameRate)) {
case 30:
return OTCameraCaptureFrameRate.OTCameraCaptureFrameRate30FPS;
case 15:
return OTCameraCaptureFrameRate.OTCameraCaptureFrameRate15FPS;
case 7:
return OTCameraCaptureFrameRate.OTCameraCaptureFrameRate7FPS;
case 1:
return OTCameraCaptureFrameRate.OTCameraCaptureFrameRate1FPS;
}
}
return OTCameraCaptureFrameRate.OTCameraCaptureFrameRate30FPS;
};
TNSOTPublisher.prototype.cycleCamera = function () {
if (this._ios) {
if (this._ios.cameraPosition === AVCaptureDevicePositionBack) {
this._ios.cameraPosition = AVCaptureDevicePositionFront;
}
else {
this._ios.cameraPosition = AVCaptureDevicePositionBack;
}
}
};
TNSOTPublisher.prototype.toggleCamera = function () {
if (this._ios) {
this._ios.publishVideo = !this._ios.publishVideo;
}
};
TNSOTPublisher.prototype.toggleMute = function () {
if (this._ios) {
this._ios.publishAudio = !this._ios.publishAudio;
}
};
Object.defineProperty(TNSOTPublisher.prototype, "events", {
get: function () {
return this._publisherKitDelegate.events;
},
enumerable: true,
configurable: true
});
return TNSOTPublisher;
}(content_view_1.ContentView));
exports.TNSOTPublisher = TNSOTPublisher;
var TNSPublisherKitDelegateImpl = (function (_super) {
__extends(TNSPublisherKitDelegateImpl, _super);
function TNSPublisherKitDelegateImpl() {
return _super !== null && _super.apply(this, arguments) || this;
}
TNSPublisherKitDelegateImpl.initWithOwner = function (owner) {
var publisherKitDelegate = new TNSPublisherKitDelegateImpl();
publisherKitDelegate._events = new observable_1.Observable();
publisherKitDelegate._owner = owner;
return publisherKitDelegate;
};
TNSPublisherKitDelegateImpl.prototype.publisherStreamCreated = function (publisher, stream) {
if (this._events) {
this._events.notify({
eventName: 'streamCreated',
object: new observable_1.Observable({
publisher: publisher,
stream: stream
})
});
}
};
TNSPublisherKitDelegateImpl.prototype.publisherStreamDestroyed = function (publisher, stream) {
if (this._events) {
this._events.notify({
eventName: 'streamDestroyed',
object: new observable_1.Observable({
publisher: publisher,
stream: stream
})
});
}
};
TNSPublisherKitDelegateImpl.prototype.publisherDidFailWithError = function (publisher, error) {
if (this._events) {
this._events.notify({
eventName: 'didFailWithError',
object: new observable_1.Observable({
publisher: publisher,
error: error
})
});
}
console.log(error);
};
Object.defineProperty(TNSPublisherKitDelegateImpl.prototype, "events", {
get: function () {
return this._events;
},
enumerable: true,
configurable: true
});
return TNSPublisherKitDelegateImpl;
}(NSObject));
TNSPublisherKitDelegateImpl.ObjCProtocols = [OTPublisherKitDelegate];
//# sourceMappingURL=publisher.js.map