emotiv-ts
Version:
A Typescript library that wraps the Cortex API functionalities to communicate with Emotiv headsets
27 lines (26 loc) • 941 B
JavaScript
import { AuthenticationService } from "./authentication.service";
import "../enums/internal/emotiv.requests";
import { Subscribe } from "../models/requests/datasubscription/subscribe";
import { SessionService } from "./session.service";
export class DataStreamService {
socket;
constructor(socket) {
this.socket = socket;
}
subscribe(streams, action) {
let authToken = AuthenticationService.getAuthToken();
let sessionId = SessionService.getSessionId();
let subRequest = new Subscribe(authToken, sessionId, streams);
this.socket.send(JSON.stringify(subRequest));
this.socket.onmessage = (message) => {
try {
let data = JSON.parse(message.data);
console.debug("SubRequest response:", data);
action(data);
}
catch (error) {
console.error(error);
}
};
}
}