🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

@finwave/liveness

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@finwave/liveness - npm Package Compare versions

Comparing version

to
1.2.4

@@ -11,73 +11,35 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VideoFace = exports.ResultHelper = exports.Event = void 0;
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
var socket_io_client_1 = require("socket.io-client");
var types_1 = require("./types");
var Event = /** @class */ (function () {
function Event(type, value) {
if (value === void 0) { value = null; }
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
const socket_io_client_1 = require("socket.io-client");
const types_1 = require("./types");
class Event {
constructor(type, value = null) {
this.type = type;
this.value = value;
}
return Event;
}());
}
exports.Event = Event;
var ResultHelper = /** @class */ (function () {
function ResultHelper() {
class ResultHelper {
static get(id_1) {
return __awaiter(this, arguments, void 0, function* (id, env = types_1.Envs.DEV) {
const endpoint = types_1.Endpoints[env] || types_1.Endpoints.DEV;
const url = endpoint + "result/" + id;
if (typeof window !== "undefined") {
//Browser
return fetch(url, {
method: "GET",
}).then((r) => r.json().then((j) => j));
}
else {
throw new Error("Unsuported platform");
}
});
}
ResultHelper.get = function (id_1) {
return __awaiter(this, arguments, void 0, function (id, env) {
var endpoint, url;
if (env === void 0) { env = types_1.Envs.DEV; }
return __generator(this, function (_a) {
endpoint = types_1.Endpoints[env] || types_1.Endpoints.DEV;
url = endpoint + "result/" + id;
if (typeof window !== "undefined") {
//Browser
return [2 /*return*/, fetch(url, {
method: "GET",
}).then(function (r) { return r.json().then(function (j) { return j; }); })];
}
else {
throw new Error("Unsuported platform");
}
return [2 /*return*/];
});
});
};
return ResultHelper;
}());
}
exports.ResultHelper = ResultHelper;
var VideoFace = /** @class */ (function () {
function VideoFace(token, env, config) {
if (env === void 0) { env = types_1.Envs.DEV; }
class VideoFace {
constructor(token, env = types_1.Envs.DEV, config) {
this.events$ = new rxjs_1.Subject();

@@ -93,187 +55,144 @@ console.log("Liveness constructor");

}
VideoFace.prototype.startStream = function (gatheringTimeout) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
this.gatheringTimeout = gatheringTimeout;
return [2 /*return*/, this.connect().then(function () { return _this.id; })];
});
startStream(gatheringTimeout) {
return __awaiter(this, void 0, void 0, function* () {
this.gatheringTimeout = gatheringTimeout;
return this.connect().then(() => this.id);
});
};
VideoFace.prototype.openCamera = function () {
return __awaiter(this, arguments, void 0, function (facingMode, deviceId) {
var remoteConfig, _a;
var _this = this;
var _b, _c, _d;
if (facingMode === void 0) { facingMode = undefined; }
if (deviceId === void 0) { deviceId = undefined; }
return __generator(this, function (_e) {
switch (_e.label) {
case 0: return [4 /*yield*/, this.getRemoteConfig()];
case 1:
remoteConfig = _e.sent();
if (facingMode && ((_b = remoteConfig.media_stream_constraints) === null || _b === void 0 ? void 0 : _b.video)) {
remoteConfig.media_stream_constraints.video.facingMode = facingMode;
}
if (deviceId && ((_c = remoteConfig.media_stream_constraints) === null || _c === void 0 ? void 0 : _c.video)) {
remoteConfig.media_stream_constraints.video.deviceId = deviceId;
}
_a = this;
return [4 /*yield*/, navigator.mediaDevices
.getUserMedia((_d = remoteConfig === null || remoteConfig === void 0 ? void 0 : remoteConfig.media_stream_constraints) !== null && _d !== void 0 ? _d : {
video: {
deviceId: deviceId,
facingMode: facingMode,
frameRate: 20,
height: { ideal: 720 },
width: { ideal: 720 },
},
})
.catch(function (s) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
video: {
deviceId: deviceId,
facingMode: facingMode,
},
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); })];
case 2:
_a.stream = _e.sent();
return [2 /*return*/, this.stream];
}
});
}
openCamera() {
return __awaiter(this, arguments, void 0, function* (facingMode = undefined, deviceId = undefined) {
var _a, _b, _c;
const remoteConfig = yield this.getRemoteConfig();
if (facingMode && ((_a = remoteConfig.media_stream_constraints) === null || _a === void 0 ? void 0 : _a.video)) {
remoteConfig.media_stream_constraints.video.facingMode = facingMode;
}
if (deviceId && ((_b = remoteConfig.media_stream_constraints) === null || _b === void 0 ? void 0 : _b.video)) {
remoteConfig.media_stream_constraints.video.deviceId = deviceId;
}
this.stream = yield navigator.mediaDevices
.getUserMedia((_c = remoteConfig === null || remoteConfig === void 0 ? void 0 : remoteConfig.media_stream_constraints) !== null && _c !== void 0 ? _c : {
video: {
deviceId,
facingMode,
frameRate: 20,
height: { ideal: 720 },
width: { ideal: 720 },
},
})
.catch((s) => __awaiter(this, void 0, void 0, function* () {
return yield navigator.mediaDevices.getUserMedia({
video: {
deviceId,
facingMode,
},
});
}));
return this.stream;
});
};
VideoFace.prototype.closeCamera = function () {
}
closeCamera() {
var _a;
(_a = this.stream) === null || _a === void 0 ? void 0 : _a.getTracks().forEach(function (t) { return t.stop(); });
(_a = this.stream) === null || _a === void 0 ? void 0 : _a.getTracks().forEach((t) => t.stop());
this.stream = undefined;
};
VideoFace.prototype.events = function (type) {
return this.events$.pipe((0, operators_1.filter)(function (e) { return e.type == type; }), (0, operators_1.map)(function (e) { return e.value; }));
};
VideoFace.prototype.setMediaStream = function (stream) {
}
events(type) {
return this.events$.pipe((0, operators_1.filter)((e) => e.type == type), (0, operators_1.map)((e) => e.value));
}
setMediaStream(stream) {
this.stream = stream;
};
VideoFace.prototype.getMediaStream = function () {
}
getMediaStream() {
return this.stream;
};
VideoFace.prototype.connect = function () {
return __awaiter(this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this;
return [4 /*yield*/, this.createPeerConnection()];
case 1:
_a.pc = _b.sent();
return [4 /*yield*/, this.openWithStream()];
case 2: return [2 /*return*/, _b.sent()];
}
});
}
connect() {
return __awaiter(this, void 0, void 0, function* () {
this.pc = yield this.createPeerConnection();
return yield this.openWithStream();
});
};
VideoFace.prototype.reconnect = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.closePeerConnection()];
case 1:
_a.sent();
return [4 /*yield*/, this.connect()];
case 2: return [2 /*return*/, _a.sent()];
}
reconnect() {
return __awaiter(this, void 0, void 0, function* () {
yield this.closePeerConnection();
return yield this.connect();
});
}
openWithStream() {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g;
(_a = this.stream) === null || _a === void 0 ? void 0 : _a.getTracks().forEach((track) => {
if (track.kind === "video") {
// track.applyConstraints({ });
}
this.pc.addTrack(track, this.stream);
});
});
};
VideoFace.prototype.openWithStream = function () {
return __awaiter(this, void 0, void 0, function () {
var tcvr, codecs, filtered_codecs, i;
var _this = this;
var _a, _b, _c, _d, _e, _f, _g;
return __generator(this, function (_h) {
(_a = this.stream) === null || _a === void 0 ? void 0 : _a.getTracks().forEach(function (track) {
if (track.kind === "video") {
// track.applyConstraints({ });
let tcvr = this.pc.getTransceivers()[0];
console.log(tcvr);
let codecs = (_c = (_b = RTCRtpReceiver === null || RTCRtpReceiver === void 0 ? void 0 : RTCRtpReceiver.getCapabilities("video")) === null || _b === void 0 ? void 0 : _b.codecs) !== null && _c !== void 0 ? _c : [];
console.log(codecs);
let filtered_codecs = [];
if ((_d = this.remoteConfig) === null || _d === void 0 ? void 0 : _d.codecs) {
for (let i = 0; i < codecs.length; i++) {
if ((_e = this.remoteConfig) === null || _e === void 0 ? void 0 : _e.codecs.includes(codecs[i].mimeType)) {
filtered_codecs.push(codecs[i]);
}
_this.pc.addTrack(track, _this.stream);
});
tcvr = this.pc.getTransceivers()[0];
console.log(tcvr);
codecs = (_c = (_b = RTCRtpReceiver === null || RTCRtpReceiver === void 0 ? void 0 : RTCRtpReceiver.getCapabilities("video")) === null || _b === void 0 ? void 0 : _b.codecs) !== null && _c !== void 0 ? _c : [];
console.log(codecs);
filtered_codecs = [];
if ((_d = this.remoteConfig) === null || _d === void 0 ? void 0 : _d.codecs) {
for (i = 0; i < codecs.length; i++) {
if ((_e = this.remoteConfig) === null || _e === void 0 ? void 0 : _e.codecs.includes(codecs[i].mimeType)) {
filtered_codecs.push(codecs[i]);
}
}
}
if (((_f = this.remoteConfig) === null || _f === void 0 ? void 0 : _f.codecs) &&
filtered_codecs.length == ((_g = this.remoteConfig) === null || _g === void 0 ? void 0 : _g.codecs.length) &&
(tcvr === null || tcvr === void 0 ? void 0 : tcvr.setCodecPreferences) != undefined) {
console.log(filtered_codecs);
tcvr === null || tcvr === void 0 ? void 0 : tcvr.setCodecPreferences(filtered_codecs);
}
return [2 /*return*/, this.negotiate()];
});
}
if (((_f = this.remoteConfig) === null || _f === void 0 ? void 0 : _f.codecs) &&
filtered_codecs.length == ((_g = this.remoteConfig) === null || _g === void 0 ? void 0 : _g.codecs.length) &&
(tcvr === null || tcvr === void 0 ? void 0 : tcvr.setCodecPreferences) != undefined) {
console.log(filtered_codecs);
tcvr === null || tcvr === void 0 ? void 0 : tcvr.setCodecPreferences(filtered_codecs);
}
return this.negotiate();
});
};
VideoFace.prototype.negotiate = function () {
var _this = this;
}
negotiate() {
return this.pc
.createOffer()
.then(function (offer) {
return _this.pc.setLocalDescription(offer);
.then((offer) => {
return this.pc.setLocalDescription(offer);
})
.then(function () {
.then(() => {
var _a, _b, _c, _d;
var sdp = (_c = (_b = (_a = _this.pc) === null || _a === void 0 ? void 0 : _a.localDescription) === null || _b === void 0 ? void 0 : _b.sdp) !== null && _c !== void 0 ? _c : "";
sdp = _this.updateSDPForMinBitrate(sdp, 1000);
(_d = _this.pc) === null || _d === void 0 ? void 0 : _d.setLocalDescription({ type: "offer", sdp: sdp });
let sdp = (_c = (_b = (_a = this.pc) === null || _a === void 0 ? void 0 : _a.localDescription) === null || _b === void 0 ? void 0 : _b.sdp) !== null && _c !== void 0 ? _c : "";
sdp = this.updateSDPForMinBitrate(sdp, 1000);
(_d = this.pc) === null || _d === void 0 ? void 0 : _d.setLocalDescription({ type: "offer", sdp: sdp });
})
.then(function () {
.then(() => {
// wait for ICE gathering to complete
return new Promise(function (resolve) {
if (_this.pc.iceGatheringState === "complete") {
return new Promise((resolve) => {
if (this.pc.iceGatheringState === "complete") {
resolve(null);
}
else {
var checkState_1 = function () {
console.log("gatheringstate -> " + _this.pc.iceGatheringState);
if (_this.pc.iceGatheringState === "complete") {
_this.pc.removeEventListener("icegatheringstatechange", checkState_1);
const checkState = () => {
console.log("gatheringstate -> " + this.pc.iceGatheringState);
if (this.pc.iceGatheringState === "complete") {
this.pc.removeEventListener("icegatheringstatechange", checkState);
resolve(null);
}
};
_this.pc.addEventListener("icegatheringstatechange", checkState_1);
this.pc.addEventListener("icegatheringstatechange", checkState);
}
console.log("gathering timeout: " + _this.gatheringTimeout);
if (_this.gatheringTimeout && _this.gatheringTimeout >= 0) {
setTimeout(function () {
console.log("gathering timeout: " + this.gatheringTimeout);
if (this.gatheringTimeout && this.gatheringTimeout >= 0) {
setTimeout(() => {
resolve(null);
}, _this.gatheringTimeout);
}, this.gatheringTimeout);
}
});
})
.then(function () {
var offer = _this.pc.localDescription;
return _this.dc
.then(() => {
const offer = this.pc.localDescription;
return this.dc
.emitWithAck("offer", {
sdp: offer === null || offer === void 0 ? void 0 : offer.sdp,
type: offer === null || offer === void 0 ? void 0 : offer.type,
config: _this.localConfig,
id: _this.id,
token: _this.token,
config: this.localConfig,
id: this.id,
token: this.token,
})
.then(function (r) {
.then((r) => {
if (!r) {
_this.events$.next(new Event(types_1.EventType.ERROR, "INVALID_TOKEN"));
this.events$.next(new Event(types_1.EventType.ERROR, "INVALID_TOKEN"));
throw new Error("INVALID_TOKEN");

@@ -284,22 +203,18 @@ }

})
.then(function (answer) {
_this.id = answer.id;
.then((answer) => {
this.id = answer.id;
console.log("REMOTE_SDP", answer.sdp);
return _this.pc.setRemoteDescription(answer);
return this.pc.setRemoteDescription(answer);
});
};
Object.defineProperty(VideoFace.prototype, "endpoint", {
get: function () {
return types_1.Endpoints[this.env] || types_1.Endpoints.DEV;
},
enumerable: false,
configurable: true
});
VideoFace.prototype.updateSDPForMinBitrate = function (sdp, minBitrate) {
}
get endpoint() {
return types_1.Endpoints[this.env] || types_1.Endpoints.DEV;
}
updateSDPForMinBitrate(sdp, minBitrate) {
// Dividir el SDP en líneas para su manipulación
var lines = sdp.split("\r\n");
var newSdp = [];
var inVideoMediaSection = false;
var bitrateInserted = false;
lines.forEach(function (line) {
let lines = sdp.split("\r\n");
let newSdp = [];
let inVideoMediaSection = false;
let bitrateInserted = false;
lines.forEach((line) => {
// Agregar la línea tal cual al nuevo SDP

@@ -313,3 +228,3 @@ newSdp.push(line);

if (inVideoMediaSection && line.startsWith("c=") && !bitrateInserted) {
var bLine = "b=AS:" + minBitrate;
let bLine = "b=AS:" + minBitrate;
newSdp.push(bLine);

@@ -326,122 +241,100 @@ bitrateInserted = true;

return newSdp.join("\r\n");
};
VideoFace.prototype.getRemoteConfig = function () {
return __awaiter(this, void 0, void 0, function () {
var devices_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!!this.remoteConfig) return [3 /*break*/, 2];
devices_1 = [];
// enumerate devices and select the first camera (mostly the back one)
return [4 /*yield*/, navigator.mediaDevices.enumerateDevices().then(function (d) {
for (var _i = 0, d_1 = d; _i < d_1.length; _i++) {
var x = d_1[_i];
if (x.kind === "videoinput") {
devices_1.push({
label: x.label,
deviceId: x.deviceId,
kind: x.kind,
groupId: x.groupId,
});
console.log("Camera found: ", x.label || "label not found", x.deviceId || "id no found");
}
}
})];
case 1:
// enumerate devices and select the first camera (mostly the back one)
_a.sent();
this.remoteConfig = this.dc.emitWithAck("config", {
token: this.token,
userAgent: window.navigator.userAgent,
screen: { width: window.screen.width, height: window.screen.height },
devices: devices_1,
});
_a.label = 2;
case 2: return [2 /*return*/, this.remoteConfig];
}
});
}
getRemoteConfig() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.remoteConfig) {
let devices = [];
// enumerate devices and select the first camera (mostly the back one)
yield navigator.mediaDevices.enumerateDevices().then((d) => {
for (var x of d) {
if (x.kind === "videoinput") {
devices.push({
label: x.label,
deviceId: x.deviceId,
kind: x.kind,
groupId: x.groupId,
});
console.log("Camera found: ", x.label || "label not found", x.deviceId || "id no found");
}
}
});
this.remoteConfig = this.dc.emitWithAck("config", {
token: this.token,
userAgent: window.navigator.userAgent,
screen: { width: window.screen.width, height: window.screen.height },
devices,
});
}
return this.remoteConfig;
});
};
VideoFace.prototype.createPeerConnection = function () {
return __awaiter(this, void 0, void 0, function () {
var remoteConfig, config, pc;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getRemoteConfig()];
case 1:
remoteConfig = _a.sent();
config = {
iceServers: remoteConfig.iceServers,
};
pc = new RTCPeerConnection(config);
pc.onicegatheringstatechange = function () {
console.log("icegatheringstatechange -> " + pc.iceConnectionState);
};
pc.oniceconnectionstatechange = function () {
console.log("iceconnectionstatechange -> " + pc.iceConnectionState);
// "checking" | "closed" | "completed" | "connected" | "disconnected" | "failed" | "new"
if (pc.iceConnectionState === "connected") {
_this.events$.next(new Event(types_1.EventType.CONNECTED));
}
else if (pc.iceConnectionState === "disconnected" ||
pc.iceConnectionState === "closed" ||
pc.iceConnectionState === "failed") {
_this.events$.next(new Event(types_1.EventType.MOVE, "RECONNECT"));
_this.reconnect();
}
};
pc.onsignalingstatechange = function () {
console.log("signalingstatechange -> " + pc.iceConnectionState);
};
pc.onicecandidate = function (e) {
var _a, _b;
if (!e.candidate)
return;
// Mostrar cadena candidata, p. Ej.
// candidate:842163049 1 udp 1677729535 XXX.XXX.XX.XXXX 58481 typ srflx raddr 0.0.0.0 rport 0 generation 0 ufrag sXP5 network-cost 999
// Si se encontró un candidato srflx, notifique que el servidor STUN funciona.
if (e.candidate.type == "srflx") {
console.log("The STUN server ".concat((_a = e.candidate) === null || _a === void 0 ? void 0 : _a.url, " is working."));
console.log(e.candidate);
//console.log(` Your Public IP Address is: ${e?.candidate?.address}`);
}
// Si se encontró un candidato de retransmisión, notifique que el servidor TURN funciona.
if (e.candidate.type == "relay") {
console.log("The TURN server ".concat((_b = e.candidate) === null || _b === void 0 ? void 0 : _b.url, " is working."));
console.log(e.candidate);
}
};
return [2 /*return*/, pc];
}
createPeerConnection() {
return __awaiter(this, void 0, void 0, function* () {
const remoteConfig = yield this.getRemoteConfig();
const config = {
iceServers: remoteConfig.iceServers,
};
let pc = new RTCPeerConnection(config);
pc.onicegatheringstatechange = () => {
console.log("icegatheringstatechange -> " + pc.iceConnectionState);
};
pc.oniceconnectionstatechange = () => {
console.log("iceconnectionstatechange -> " + pc.iceConnectionState);
// "checking" | "closed" | "completed" | "connected" | "disconnected" | "failed" | "new"
if (pc.iceConnectionState === "connected") {
this.events$.next(new Event(types_1.EventType.CONNECTED));
}
});
else if (pc.iceConnectionState === "disconnected" ||
pc.iceConnectionState === "closed" ||
pc.iceConnectionState === "failed") {
this.events$.next(new Event(types_1.EventType.MOVE, "RECONNECT"));
this.reconnect();
}
};
pc.onsignalingstatechange = () => {
console.log("signalingstatechange -> " + pc.iceConnectionState);
};
pc.onicecandidate = (e) => {
var _a, _b;
if (!e.candidate)
return;
// Mostrar cadena candidata, p. Ej.
// candidate:842163049 1 udp 1677729535 XXX.XXX.XX.XXXX 58481 typ srflx raddr 0.0.0.0 rport 0 generation 0 ufrag sXP5 network-cost 999
// Si se encontró un candidato srflx, notifique que el servidor STUN funciona.
if (e.candidate.type == "srflx") {
console.log(`The STUN server ${(_a = e.candidate) === null || _a === void 0 ? void 0 : _a.url} is working.`);
console.log(e.candidate);
//console.log(` Your Public IP Address is: ${e?.candidate?.address}`);
}
// Si se encontró un candidato de retransmisión, notifique que el servidor TURN funciona.
if (e.candidate.type == "relay") {
console.log(`The TURN server ${(_b = e.candidate) === null || _b === void 0 ? void 0 : _b.url} is working.`);
console.log(e.candidate);
}
};
return pc;
});
};
VideoFace.prototype.closeCameraStream = function () {
this.pc.getSenders().forEach(function (sender) {
}
closeCameraStream() {
this.pc.getSenders().forEach((sender) => {
var _a;
(_a = sender === null || sender === void 0 ? void 0 : sender.track) === null || _a === void 0 ? void 0 : _a.stop();
});
};
VideoFace.prototype.closePeerConnection = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (this.dc) {
this.dc.close();
}
if (this.pc.getTransceivers) {
this.pc.getTransceivers().forEach(function (transceiver) {
if (transceiver.stop) {
transceiver.stop();
}
});
}
this.pc.close();
return [2 /*return*/];
});
}
closePeerConnection() {
return __awaiter(this, void 0, void 0, function* () {
if (this.dc) {
this.dc.close();
}
if (this.pc.getTransceivers) {
this.pc.getTransceivers().forEach((transceiver) => {
if (transceiver.stop) {
transceiver.stop();
}
});
}
this.pc.close();
});
};
VideoFace.prototype.close = function (sendEvent) {
if (sendEvent === void 0) { sendEvent = true; }
}
close(sendEvent = true) {
console.log("Force close!");

@@ -453,46 +346,41 @@ this.closeCamera();

this.events$.next(new Event(types_1.EventType.CLOSED));
};
VideoFace.prototype.pause = function () {
}
pause() {
this.sendEvent("PAUSE");
};
VideoFace.prototype.resume = function () {
}
resume() {
this.sendEvent("RESUME");
};
VideoFace.prototype.sendEvent = function (event, data) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.dc.send(JSON.stringify({ event: event, data: data }) + "$$$");
return [2 /*return*/];
});
}
sendEvent(event, data) {
return __awaiter(this, void 0, void 0, function* () {
this.dc.send(JSON.stringify({ event: event, data }) + "$$$");
});
};
VideoFace.prototype.createDataChannel = function () {
var _this = this;
var socket = (0, socket_io_client_1.io)(this.endpoint, {
}
createDataChannel() {
const socket = (0, socket_io_client_1.io)(this.endpoint, {
transports: ["websocket"],
});
socket.on("connect", function () {
socket.on("connect", () => {
console.log("Socket connected");
});
socket.on("disconnect", function () {
socket.on("disconnect", () => {
console.log("Socket disconnected");
});
socket.on("error", function (error) {
socket.on("error", (error) => {
console.log("Socket error", error);
});
socket.on("message", function (data) {
socket.on("message", (data) => {
if (data.event == "RESULT") {
_this.events$.next(new Event(types_1.EventType.RESULT, data.data));
this.events$.next(new Event(types_1.EventType.RESULT, data.data));
}
else if (data.event == "MOVE") {
_this.events$.next(new Event(types_1.EventType.MOVE, data.value));
this.events$.next(new Event(types_1.EventType.MOVE, data.value));
}
else if (data.event == "ERROR") {
_this.events$.next(new Event(types_1.EventType.ERROR, data.data));
this.events$.next(new Event(types_1.EventType.ERROR, data.data));
}
});
return socket;
};
return VideoFace;
}());
}
}
exports.VideoFace = VideoFace;
{
"name": "@finwave/liveness",
"version": "1.2.3",
"version": "1.2.4",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",