nativescript-opentok
Version:
Integrates OpenTok for NativeScript.
218 lines • 7.36 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var observable_1 = require("tns-core-modules/data/observable");
var TNSOTSession = (function (_super) {
__extends(TNSOTSession, _super);
function TNSOTSession() {
return _super !== null && _super.apply(this, arguments) || this;
}
TNSOTSession.initWithApiKeySessionId = function (apiKey, sessionId) {
var instance = TNSOTSession.new();
instance._events = observable_1.fromObject({});
instance._ios = OTSession.alloc().initWithApiKeySessionIdDelegate(apiKey.toString(), sessionId.toString(), instance);
return instance;
};
TNSOTSession.requestPermission = function () {
};
TNSOTSession.prototype.connect = function (token) {
var errorRef = new interop.Reference();
this._ios.connectWithTokenError(token, errorRef);
if (errorRef.value) {
console.log(errorRef.value);
}
};
TNSOTSession.prototype.disconnect = function () {
if (this._ios) {
try {
var errorRef = new interop.Reference();
this._ios.disconnect(errorRef);
if (errorRef.value) {
console.log(errorRef.value);
}
}
catch (error) {
console.log(error);
}
}
};
TNSOTSession.prototype.sendSignal = function (type, message) {
if (this._ios) {
try {
var errorRef = new interop.Reference();
this._ios.signalWithTypeStringConnectionError(type, message, null, errorRef);
if (errorRef.value) {
console.log(errorRef.value);
}
}
catch (error) {
console.log(error);
}
}
};
TNSOTSession.prototype.unsubscribe = function (subscriber) {
try {
if (this._ios) {
var errorRef = new interop.Reference();
this._ios.unsubscribe(subscriber, errorRef);
if (errorRef.value) {
console.log(errorRef.value);
}
}
}
catch (error) {
console.log(error);
}
};
Object.defineProperty(TNSOTSession.prototype, "subscriber", {
set: function (subscriber) {
this._subscriber = subscriber;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TNSOTSession.prototype, "events", {
get: function () {
return this._events;
},
enumerable: true,
configurable: true
});
TNSOTSession.prototype.sessionDidConnect = function (session) {
if (this.events) {
this.events.notify({
eventName: 'sessionDidConnect',
object: observable_1.fromObject({
session: session
})
});
}
};
TNSOTSession.prototype.sessionDidDisconnect = function (session) {
if (this.events) {
this.events.notify({
eventName: 'sessionDidDisconnect',
object: observable_1.fromObject({
session: session
})
});
}
};
TNSOTSession.prototype.sessionDidReconnect = function (session) {
if (this.events) {
this.events.notify({
eventName: 'sessionDidReconnect',
object: observable_1.fromObject({
session: session
})
});
}
};
TNSOTSession.prototype.sessionDidBeginReconnecting = function (session) {
if (this.events) {
this.events.notify({
eventName: 'sessionDidBeginReconnecting',
object: observable_1.fromObject({
session: session
})
});
}
};
TNSOTSession.prototype.sessionStreamCreated = function (session, stream) {
if (this.events) {
this.events.notify({
eventName: 'streamCreated',
object: observable_1.fromObject({
session: session,
stream: stream
})
});
}
if (this._subscriber) {
this._subscriber.subscribe(session, stream);
}
};
TNSOTSession.prototype.sessionStreamDestroyed = function (session, stream) {
if (this.events) {
this.events.notify({
eventName: 'streamDestroyed',
object: observable_1.fromObject({
session: session,
stream: stream
})
});
}
};
TNSOTSession.prototype.sessionDidFailWithError = function (session, error) {
if (this.events) {
this.events.notify({
eventName: 'didFailWithError',
object: observable_1.fromObject({
session: session,
error: error
})
});
}
};
TNSOTSession.prototype.sessionConnectionDestroyed = function (session, connection) {
if (this.events) {
this.events.notify({
eventName: 'connectionDestroyed',
object: observable_1.fromObject({
session: session,
connection: connection
})
});
}
};
TNSOTSession.prototype.sessionConnectionCreated = function (session, connection) {
if (this.events) {
this.events.notify({
eventName: 'connectionCreated',
object: observable_1.fromObject({
session: session,
connection: connection
})
});
}
};
TNSOTSession.prototype.sessionArchiveStartedWithId = function (session, archiveId, name) {
if (this.events) {
this.events.notify({
eventName: 'archiveStartedWithId',
object: observable_1.fromObject({
session: session,
archiveId: archiveId,
name: name
})
});
}
};
TNSOTSession.prototype.sessionArchiveStoppedWithId = function (session, archiveId) {
if (this.events) {
this.events.notify({
eventName: 'archiveStoppedWithId',
object: observable_1.fromObject({
session: session,
archiveId: archiveId
})
});
}
};
TNSOTSession.prototype.sessionReceivedSignalTypeFromConnectionWithString = function (session, type, connection, data) {
if (this.events) {
this.events.notify({
eventName: 'signalReceived',
object: observable_1.fromObject({
session: session,
type: type,
data: data,
connection: connection
})
});
}
};
return TNSOTSession;
}(NSObject));
TNSOTSession.ObjCProtocols = [OTSessionDelegate];
exports.TNSOTSession = TNSOTSession;
//# sourceMappingURL=session.js.map