@actyx/sdk
Version:
Actyx SDK
49 lines • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mkV1eventStore = void 0;
/*
* Actyx SDK: Functions for writing distributed apps
* deployed on peer-to-peer networks, without any servers.
*
* Copyright (C) 2021 Actyx AG
*/
const rxjs_1 = require("../../node_modules/rxjs");
const log_1 = require("../internal_common/log");
const multiplexedWebsocket_1 = require("./multiplexedWebsocket");
const websocketEventStore_1 = require("./websocketEventStore");
const websocketSnapshotStore_1 = require("./websocketSnapshotStore");
const mkV1eventStore = async (axOpts) => {
const host = axOpts.actyxHost || 'localhost';
const port = axOpts.actyxPort || 4243;
/** url of the destination */
const url = 'ws://' + host + ':' + port + '/store_api';
log_1.log.actyx.debug('Trying V1 connection to', url);
const wsConfig = (0, multiplexedWebsocket_1.mkConfig)(url);
const closeSubject = new rxjs_1.Subject();
wsConfig.closeObserver = closeSubject;
const openSubject = new rxjs_1.Subject();
wsConfig.openObserver = openSubject;
const ws = new multiplexedWebsocket_1.MultiplexedWebsocket(wsConfig);
closeSubject.subscribe({
next: () => {
log_1.log.ws.warn('connection to Actyx lost');
axOpts.onConnectionLost && axOpts.onConnectionLost();
},
});
openSubject.subscribe({
next: () => {
log_1.log.ws.info('connection to Actyx established');
axOpts.onConnectionEstablished && axOpts.onConnectionEstablished();
},
});
const src = await (0, websocketEventStore_1.getSourceId)(ws);
console.warn('Note that the Actyx SDK and Pond 3.0 are optimized for Actyx V2, but you are running Actyx V1. Please upgrade as soon as possible.');
return {
eventStore: new websocketEventStore_1.WebsocketEventStore(ws, src),
sourceId: src,
close: () => ws.close(),
snapshotStore: new websocketSnapshotStore_1.WebsocketSnapshotStore(ws),
};
};
exports.mkV1eventStore = mkV1eventStore;
//# sourceMappingURL=index.js.map