-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbridgecalls-example.js
More file actions
17 lines (17 loc) · 988 Bytes
/
Copy pathbridgecalls-example.js
File metadata and controls
17 lines (17 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.connect = exports.emitEvent = exports.spectodaEventSource = void 0;
const functions_1 = require("./lib/spectoda-js/functions");
const BASE_URL = "http://localhost:8888";
// TODO check performance, if slow switch to using subscription per "event" basis or throtthling
const evs = new EventSource(`${BASE_URL}/events`);
exports.spectodaEventSource = (0, functions_1.createNanoEvents)();
evs.onmessage = v => exports.spectodaEventSource.emit("event", JSON.parse(v.data));
function emitEvent(event) {
return fetch(`${BASE_URL}/event`, { method: "POST", body: JSON.stringify(event), headers: { "Content-Type": "application/json" } }).then(v => v.json());
}
exports.emitEvent = emitEvent;
function connect(params) {
return fetch(`${BASE_URL}/connect`, { method: "POST", body: JSON.stringify(params), headers: { "Content-Type": "application/json" } }).then(v => v.json());
}
exports.connect = connect;