etsdk-js
Version:
Client-side to Tobii Pro SDK
106 lines (102 loc) • 3.69 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
TobiiClient: () => TobiiClient
});
module.exports = __toCommonJS(src_exports);
// src/TobiiClient.ts
var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
var import_js_logger = __toESM(require("js-logger"));
// src/utils.ts
function waitForSocketState(socket, state) {
return new Promise(function(resolve) {
setTimeout(function() {
if (socket.readyState === state) {
resolve(true);
} else if (socket.readyState === socket.CLOSED && state === socket.OPEN) {
resolve(false);
} else {
waitForSocketState(socket, state).then(resolve);
}
});
});
}
// src/TobiiClient.ts
import_js_logger.default.useDefaults();
var tobiiLogger = import_js_logger.default.get("tobiiprosdk");
var TobiiClient = class {
port;
host = "http://localhost";
wsHost = "ws://localhost";
_activeWSConnections = {};
constructor(port = 9999, host = "http://localhost", wsHost = "ws://localhost") {
this.port = port;
this.host = host;
this.wsHost = wsHost;
}
async ping() {
const response = await fetch(`${this.host}:${this.port}/api/ping`);
const data = await response.json();
return data;
}
async getEyeTrackers() {
const response = await fetch(`${this.host}:${this.port}/api/find`);
const data = await response.json();
return data;
}
async connectToEyeTracker(serial_number) {
const ws = await this._createWebSocketConnection(serial_number);
this._activeWSConnections[serial_number] = ws;
return ws;
}
async disconnectFromEyeTracker(serial_number) {
const ws = this._activeWSConnections[serial_number];
if (ws) {
ws.close();
delete this._activeWSConnections[serial_number];
}
}
async clearAllActiveConnections() {
for (const serial_number in this._activeWSConnections) {
this.disconnectFromEyeTracker(serial_number);
}
}
async _createWebSocketConnection(url_params) {
const ws = new import_isomorphic_ws.default(`${this.wsHost}:${this.port}/ws/${url_params}`);
await waitForSocketState(ws, ws.OPEN);
return ws;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TobiiClient
});
//# sourceMappingURL=index.js.map