UNPKG

exthos

Version:

stream processing in nodejs using the power of golang

115 lines 3.85 kB
import EventEmitter2 from "eventemitter2"; import { standardizeAxiosErrors } from "../utils/utils.js"; import { Mutex } from "async-mutex"; class EngineProcessAPI extends EventEmitter2 { constructor() { super({ wildcard: true }); this._engineProcessMutex = new Mutex(); } async _apiGetStreams(axiosReqConfig = {}) { let self = this; try { let resp = await self._axiosInstance.get("/streams", axiosReqConfig); return resp; } catch (e) { throw standardizeAxiosErrors(e); } } async _apiGetPing(axiosReqConfig = {}) { let self = this; try { let resp = await self._axiosInstance.get("/ping", axiosReqConfig); return resp; } catch (e) { throw standardizeAxiosErrors(e); } } async _apiGetReady(axiosReqConfig = {}) { let self = this; try { let resp = await self._axiosInstance.get("/ready", axiosReqConfig); return resp; } catch (e) { throw standardizeAxiosErrors(e); } } async _apiGetStreamReady(stream, axiosReqConfig = {}) { let self = this; try { let resp = await self._axiosInstance.get(`/${stream.streamID}/ready`, axiosReqConfig); return resp; } catch (e) { throw standardizeAxiosErrors(e); } } async _apiPostStreams(streamsMap, axiosReqConfig = {}) { let self = this; return await self._engineProcessMutex.runExclusive(async () => { try { let streamsConfig = {}; for (let k in streamsMap) { streamsConfig[k] = streamsMap[k].streamConfig; } let resp = await self._axiosInstance.post("/streams", streamsConfig, axiosReqConfig); return resp; } catch (e) { throw standardizeAxiosErrors(e); } }); } async _apiGetStream(stream, axiosReqConfig = {}) { let self = this; try { let resp = await self._axiosInstance.get(`/streams/${stream.streamID}`, axiosReqConfig); return resp; } catch (e) { throw standardizeAxiosErrors(e); } } async _apiPostStream(stream, axiosReqConfig = {}) { let self = this; return await self._engineProcessMutex.runExclusive(async () => { try { await stream.beforeAdd(); let resp = await self._axiosInstance.post(`/streams/${stream.streamID}`, stream.streamConfig, axiosReqConfig); return resp; } catch (e) { throw standardizeAxiosErrors(e); } }); } async _apiDeleteStream(stream, axiosReqConfig = {}) { let self = this; return await self._engineProcessMutex.runExclusive(async () => { try { await stream.afterRemove(); let resp = await self._axiosInstance.delete(`/streams/${stream.streamID}`, axiosReqConfig); return resp; } catch (e) { throw standardizeAxiosErrors(e); } }); } async _apiPutStream(stream, axiosReqConfig = {}) { let self = this; return await self._engineProcessMutex.runExclusive(async () => { try { let resp = await self._axiosInstance.put(`/streams/${stream.streamID}`, stream.streamConfig, axiosReqConfig); return resp; } catch (e) { throw standardizeAxiosErrors(e); } }); } } export { EngineProcessAPI }; //# sourceMappingURL=engineProcessAPI.js.map