@science-corporation/synapse 2.0.0 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/api/api.d.ts +5047 -2381
- package/dist/api/api.js +12917 -6374
- package/dist/api/api.js.map +1 -1
- package/dist/api/proto.json +969 -451
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -5
- package/dist/config.js.map +1 -1
- package/dist/device.d.ts +0 -1
- package/dist/device.d.ts.map +1 -1
- package/dist/device.js +1 -5
- package/dist/device.js.map +1 -1
- package/dist/nodes/index.d.ts +0 -2
- package/dist/nodes/index.d.ts.map +1 -1
- package/dist/nodes/index.js +1 -5
- package/dist/nodes/index.js.map +1 -1
- package/package.json +3 -2
- package/src/api/api.d.ts +5047 -2381
- package/src/api/api.js +13466 -6537
- package/src/api/proto.json +969 -451
- package/src/config.ts +1 -5
- package/src/device.ts +1 -5
- package/src/nodes/index.ts +0 -2
- package/synapse-api/README.md +1 -1
- package/synapse-api/api/app.proto +55 -0
- package/synapse-api/api/channel.proto +15 -1
- package/synapse-api/api/datatype.proto +97 -1
- package/synapse-api/api/device.proto +65 -0
- package/synapse-api/api/node.proto +19 -18
- package/synapse-api/api/nodes/application.proto +24 -0
- package/synapse-api/api/nodes/broadband_source.proto +1 -0
- package/synapse-api/api/nodes/disk_writer.proto +17 -0
- package/synapse-api/api/nodes/optical_stimulation.proto +29 -0
- package/synapse-api/api/nodes/signal_config.proto +2 -0
- package/synapse-api/api/performance.proto +29 -0
- package/synapse-api/api/query.proto +8 -0
- package/synapse-api/api/status.proto +6 -1
- package/synapse-api/api/synapse.proto +8 -31
- package/synapse-api/api/tap.proto +35 -0
- package/synapse-api/api/time.proto +53 -0
- package/dist/demo.d.ts +0 -2
- package/dist/demo.d.ts.map +0 -1
- package/dist/demo.js +0 -285
- package/dist/demo.js.map +0 -1
- package/dist/nodes/stream_in.d.ts +0 -15
- package/dist/nodes/stream_in.d.ts.map +0 -1
- package/dist/nodes/stream_in.js +0 -66
- package/dist/nodes/stream_in.js.map +0 -1
- package/dist/nodes/stream_out.d.ts +0 -23
- package/dist/nodes/stream_out.d.ts.map +0 -1
- package/dist/nodes/stream_out.js +0 -105
- package/dist/nodes/stream_out.js.map +0 -1
- package/src/demo.ts +0 -325
- package/src/nodes/stream_in.ts +0 -78
- package/src/nodes/stream_out.ts +0 -109
- package/synapse-api/api/nodes/stream_in.proto +0 -14
- package/synapse-api/api/nodes/stream_out.proto +0 -42
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package synapse;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Used for precise time synchronization over UDP between clients and a server
|
|
7
|
+
* In most cases, the server is the Synapse device.enum
|
|
8
|
+
*
|
|
9
|
+
* How it works:
|
|
10
|
+
* 1. Client generates a random client_id on first connection
|
|
11
|
+
* 2. Client increments the sequence number on each packet (to detect drops)
|
|
12
|
+
* 3. Client records the send time and sends the packet to the server over udp.
|
|
13
|
+
* - The server port will be available through the Status message
|
|
14
|
+
* - Try to timestamp the packet as close as possible to the send to minimize
|
|
15
|
+
* the calculated offset error. Future improvements could support hardware timestamps
|
|
16
|
+
* 4. Server records the receive time
|
|
17
|
+
* 5. Server immediately echos it back to the client, recording the send time
|
|
18
|
+
* 6. Client records the receive time when the packet returns
|
|
19
|
+
*
|
|
20
|
+
* With these times, the client can calculate
|
|
21
|
+
* - Round Trip Time: (client_receive_time_ns - client_send_time_ns)
|
|
22
|
+
* - Network Latency (assumes symmetric paths): rtt / 2
|
|
23
|
+
* - Clock offset: https://en.wikipedia.org/wiki/Network_Time_Protocol#Clock_synchronization_algorithm
|
|
24
|
+
*
|
|
25
|
+
* Implementation notes:
|
|
26
|
+
* - All timestamps are monotonic nanoseconds since Unix epoch
|
|
27
|
+
* - The server acts as a passive reflector
|
|
28
|
+
* - Multiple sync packets (8 or so) should be sent with a short period (200 ms) between
|
|
29
|
+
*/
|
|
30
|
+
message TimeSyncPacket {
|
|
31
|
+
fixed32 client_id = 1;
|
|
32
|
+
fixed32 sequence = 2;
|
|
33
|
+
|
|
34
|
+
fixed64 client_send_time_ns = 3;
|
|
35
|
+
fixed64 server_receive_time_ns = 4;
|
|
36
|
+
fixed64 server_send_time_ns = 5;
|
|
37
|
+
fixed64 client_receive_time_ns = 6;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Defines the time synchronization method for device timestamps
|
|
41
|
+
enum TimeSource {
|
|
42
|
+
TIME_SOURCE_UNKNOWN = 0;
|
|
43
|
+
|
|
44
|
+
// Use std::chrono::steady_clock (monotonic, immune to system time changes)
|
|
45
|
+
// Note: The epoch is implementation-defined (often system boot time)
|
|
46
|
+
TIME_SOURCE_STEADY_CLOCK = 1;
|
|
47
|
+
|
|
48
|
+
// Calculate timestamps based on sample counter and sampling rate
|
|
49
|
+
// counter_diff = (counter - first_counter)
|
|
50
|
+
// timestamp_ns = (counter_diff * 1e9 / sample_rate) + initial_steady_clock_value
|
|
51
|
+
// Where initial_steady_clock_value = get_steady_clock_now() at start
|
|
52
|
+
TIME_SOURCE_SAMPLE_COUNTER = 2;
|
|
53
|
+
}
|
package/dist/demo.d.ts
DELETED
package/dist/demo.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"demo.d.ts","sourceRoot":"","sources":["../src/demo.ts"],"names":[],"mappings":""}
|
package/dist/demo.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const fs_1 = __importDefault(require("fs"));
|
|
16
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
17
|
-
const helpers_1 = require("yargs/helpers");
|
|
18
|
-
const api_1 = require("./api/api");
|
|
19
|
-
const config_1 = __importDefault(require("./config"));
|
|
20
|
-
const device_1 = __importDefault(require("./device"));
|
|
21
|
-
const broadband_source_1 = __importDefault(require("./nodes/broadband_source"));
|
|
22
|
-
const optical_stimulation_1 = __importDefault(require("./nodes/optical_stimulation"));
|
|
23
|
-
const stream_in_1 = __importDefault(require("./nodes/stream_in"));
|
|
24
|
-
const stream_out_1 = __importDefault(require("./nodes/stream_out"));
|
|
25
|
-
const discover_1 = require("./utils/discover");
|
|
26
|
-
const enum_1 = require("./utils/enum");
|
|
27
|
-
const ip_1 = require("./utils/ip");
|
|
28
|
-
const cli = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
29
|
-
.help()
|
|
30
|
-
.command("discover", "Discover synapse devices")
|
|
31
|
-
.command("read", "Read from StreamOut node", {
|
|
32
|
-
"udp-port": {
|
|
33
|
-
alias: "p",
|
|
34
|
-
type: "string",
|
|
35
|
-
description: "UDP port",
|
|
36
|
-
default: "50038",
|
|
37
|
-
},
|
|
38
|
-
output: {
|
|
39
|
-
alias: "o",
|
|
40
|
-
type: "string",
|
|
41
|
-
description: "Output file",
|
|
42
|
-
},
|
|
43
|
-
uri: {
|
|
44
|
-
alias: "u",
|
|
45
|
-
type: "string",
|
|
46
|
-
demandOption: true,
|
|
47
|
-
},
|
|
48
|
-
})
|
|
49
|
-
.command("write", "Write to StreamIn node", {
|
|
50
|
-
input: {
|
|
51
|
-
alias: "i",
|
|
52
|
-
type: "string",
|
|
53
|
-
description: "Input file",
|
|
54
|
-
},
|
|
55
|
-
uri: {
|
|
56
|
-
alias: "u",
|
|
57
|
-
type: "string",
|
|
58
|
-
demandOption: true,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
const info = (device) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
-
var _a, _b;
|
|
63
|
-
console.log("Info()");
|
|
64
|
-
const { status: s, response } = yield device.info();
|
|
65
|
-
if (!s.ok()) {
|
|
66
|
-
console.error(s.message);
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
const { serial, name, status, synapseVersion, firmwareVersion, peripherals, configuration } = response;
|
|
70
|
-
console.log(` - serial: ${serial}`);
|
|
71
|
-
console.log(` - name: ${name}`);
|
|
72
|
-
console.log(` - synapse version: ${synapseVersion || "<unknown>"}`);
|
|
73
|
-
console.log(` - firmware version: ${firmwareVersion || "<unknown>"}`);
|
|
74
|
-
console.log(` - status: ${status.code} (${(0, enum_1.getName)(api_1.synapse.StatusCode, status.code)})${status.message ? `: "${status.message}"` : ""}`);
|
|
75
|
-
console.log(` - state: ${(0, enum_1.getName)(api_1.synapse.DeviceState, status.state)}`);
|
|
76
|
-
console.log(` - sockets: ${((_a = status.sockets) === null || _a === void 0 ? void 0 : _a.length) || 0}`);
|
|
77
|
-
(_b = status.sockets) === null || _b === void 0 ? void 0 : _b.forEach(({ nodeId, bind }) => {
|
|
78
|
-
console.log(` - node [${nodeId}] ${bind}`);
|
|
79
|
-
});
|
|
80
|
-
console.log(` - peripherals: ${(peripherals === null || peripherals === void 0 ? void 0 : peripherals.length) || 0}`);
|
|
81
|
-
peripherals === null || peripherals === void 0 ? void 0 : peripherals.forEach(({ name, peripheralId: id, vendor }) => {
|
|
82
|
-
console.log(` - [${id}] ${name} (${vendor})`);
|
|
83
|
-
});
|
|
84
|
-
if (configuration) {
|
|
85
|
-
const { nodes } = configuration;
|
|
86
|
-
console.log(` - configuration:`);
|
|
87
|
-
console.log(` - nodes: ${(nodes === null || nodes === void 0 ? void 0 : nodes.length) || 0}`);
|
|
88
|
-
nodes === null || nodes === void 0 ? void 0 : nodes.forEach(({ id, type }) => {
|
|
89
|
-
console.log(` - [${id}] (${(0, enum_1.getName)(api_1.synapse.NodeType, type)})`);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
return true;
|
|
93
|
-
});
|
|
94
|
-
const read = (device, argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
-
console.log("Reading from device's StreamOut node...");
|
|
96
|
-
const { udpPort, output } = argv;
|
|
97
|
-
let status = null;
|
|
98
|
-
let stream = null;
|
|
99
|
-
if (output) {
|
|
100
|
-
console.log(`Writing to file: ${output}`);
|
|
101
|
-
stream = fs_1.default.createWriteStream(output);
|
|
102
|
-
}
|
|
103
|
-
const onMessage = (msg) => {
|
|
104
|
-
const value = msg.readUInt32BE();
|
|
105
|
-
console.log(`StreamOut | recv: ${value}`);
|
|
106
|
-
if (stream) {
|
|
107
|
-
stream.write(msg);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
const config = new config_1.default();
|
|
111
|
-
const nodeEphys = new broadband_source_1.default({
|
|
112
|
-
peripheralId: 100,
|
|
113
|
-
signal: {
|
|
114
|
-
electrode: {
|
|
115
|
-
channels: [{ id: 0, referenceId: 0, electrodeId: 1 }],
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
bitWidth: 12,
|
|
119
|
-
sampleRateHz: 16000,
|
|
120
|
-
});
|
|
121
|
-
const nodeStreamOut = new stream_out_1.default({
|
|
122
|
-
udpUnicast: {
|
|
123
|
-
destinationPort: udpPort,
|
|
124
|
-
destinationAddress: yield (0, ip_1.getClientIp)(),
|
|
125
|
-
},
|
|
126
|
-
}, { onMessage });
|
|
127
|
-
status = config.add([nodeEphys, nodeStreamOut]);
|
|
128
|
-
status = config.connect(nodeEphys, nodeStreamOut);
|
|
129
|
-
if (!status.ok()) {
|
|
130
|
-
console.error("failed to connect nodes: ", status.message);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
console.log("Configuring device...");
|
|
134
|
-
status = yield device.configure(config);
|
|
135
|
-
if (!status.ok()) {
|
|
136
|
-
console.error("failed to configure device: ", status.message);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
console.log("Starting device...");
|
|
140
|
-
status = yield device.start();
|
|
141
|
-
if (!status.ok()) {
|
|
142
|
-
console.error("failed to start device: ", status.message);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
status = yield nodeStreamOut.start();
|
|
146
|
-
if (!status.ok()) {
|
|
147
|
-
console.error("failed to start stream out node: ", status.message);
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
let running = true;
|
|
151
|
-
process.on("SIGINT", function () {
|
|
152
|
-
if (!running) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
running = false;
|
|
156
|
-
nodeStreamOut.stop();
|
|
157
|
-
device.stop();
|
|
158
|
-
process.exit();
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
const write = (device, argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
162
|
-
const { input } = argv;
|
|
163
|
-
if (input && !fs_1.default.existsSync(input)) {
|
|
164
|
-
console.error(`File not found: ${input}`);
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
console.log("Writing to device's StreamOut node...");
|
|
168
|
-
let status = null;
|
|
169
|
-
const config = new config_1.default();
|
|
170
|
-
const nodeStreamIn = new stream_in_1.default({
|
|
171
|
-
dataType: api_1.synapse.DataType.kBroadband,
|
|
172
|
-
});
|
|
173
|
-
const nodeOptical = new optical_stimulation_1.default();
|
|
174
|
-
status = config.add([nodeStreamIn, nodeOptical]);
|
|
175
|
-
if (!status.ok()) {
|
|
176
|
-
console.error("Failed to add nodes: ", status.message);
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
status = config.connect(nodeStreamIn, nodeOptical);
|
|
180
|
-
if (!status.ok()) {
|
|
181
|
-
console.error("Failed to connect nodes: ", status.message);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
console.log("Configuring device...");
|
|
185
|
-
status = yield device.configure(config);
|
|
186
|
-
if (!status.ok()) {
|
|
187
|
-
console.error("Failed to configure device: ", status.message);
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
console.log("Starting device...");
|
|
191
|
-
status = yield device.start();
|
|
192
|
-
if (!status.ok()) {
|
|
193
|
-
console.error("Failed to start device: ", status.message);
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
let running = true;
|
|
197
|
-
process.on("SIGINT", function () {
|
|
198
|
-
console.log("SIGINT", running);
|
|
199
|
-
if (!running)
|
|
200
|
-
return;
|
|
201
|
-
console.log("stopping...");
|
|
202
|
-
running = false;
|
|
203
|
-
device.stop();
|
|
204
|
-
process.exit();
|
|
205
|
-
});
|
|
206
|
-
if (input) {
|
|
207
|
-
console.log(`Reading from file: ${input}`);
|
|
208
|
-
fs_1.default.open(input, "r", (err, fd) => {
|
|
209
|
-
console.log("Opened file");
|
|
210
|
-
const kBufSize = 4;
|
|
211
|
-
const buffer = Buffer.alloc(kBufSize);
|
|
212
|
-
if (err) {
|
|
213
|
-
console.error(err);
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
const read = () => {
|
|
217
|
-
if (!running) {
|
|
218
|
-
fs_1.default.close(fd, () => { });
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
fs_1.default.read(fd, buffer, 0, kBufSize, null, (err, n) => {
|
|
222
|
-
if (err) {
|
|
223
|
-
console.error(err);
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
if (n === 0) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
console.log(`StreamIn | send: ${buffer.readUInt32BE()}`);
|
|
230
|
-
nodeStreamIn.write(buffer.slice(0, n));
|
|
231
|
-
read();
|
|
232
|
-
});
|
|
233
|
-
};
|
|
234
|
-
read();
|
|
235
|
-
});
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
let i = 0;
|
|
239
|
-
const kInterval = 1;
|
|
240
|
-
const buffer = Buffer.alloc(4);
|
|
241
|
-
const write = () => {
|
|
242
|
-
if (!running) {
|
|
243
|
-
device.stop();
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
buffer.writeUInt32BE(i++);
|
|
247
|
-
nodeStreamIn.write(buffer);
|
|
248
|
-
setTimeout(write, kInterval);
|
|
249
|
-
};
|
|
250
|
-
setTimeout(write, kInterval);
|
|
251
|
-
});
|
|
252
|
-
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
253
|
-
const argv = cli.parseSync();
|
|
254
|
-
if (argv._.includes("discover")) {
|
|
255
|
-
const devices = yield (0, discover_1.discover)();
|
|
256
|
-
for (const device of devices) {
|
|
257
|
-
const addr = `${device.host}:${device.port}`;
|
|
258
|
-
const serial = `[${device.serial}]`;
|
|
259
|
-
console.log(`${addr.padEnd(21)} ${device.capability.padStart(16)} ${serial.padStart(34)} "${device.name}"`);
|
|
260
|
-
}
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
const { uri } = argv;
|
|
264
|
-
if (!uri) {
|
|
265
|
-
console.error("Missing URI");
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
console.log(`Connecting to device @ ${uri}`);
|
|
269
|
-
const device = new device_1.default(uri);
|
|
270
|
-
try {
|
|
271
|
-
yield info(device);
|
|
272
|
-
}
|
|
273
|
-
catch (err) {
|
|
274
|
-
console.error(`Failed to get device info (${err.code}): ${err.message}`);
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
if (argv._.includes("read")) {
|
|
278
|
-
return read(device, argv);
|
|
279
|
-
}
|
|
280
|
-
if (argv._.includes("write")) {
|
|
281
|
-
return write(device, argv);
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
main();
|
|
285
|
-
//# sourceMappingURL=demo.js.map
|
package/dist/demo.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"demo.js","sourceRoot":"","sources":["../src/demo.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,kDAA0B;AAC1B,2CAAwC;AAExC,mCAAoC;AACpC,sDAA8B;AAC9B,sDAA8B;AAC9B,gFAA2D;AAC3D,sFAA6D;AAC7D,kEAAyC;AACzC,oEAA2C;AAC3C,+CAA4C;AAC5C,uCAAuC;AACvC,mCAAyC;AAEzC,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACrC,IAAI,EAAE;KACN,OAAO,CAAC,UAAU,EAAE,0BAA0B,CAAC;KAC/C,OAAO,CAAC,MAAM,EAAE,0BAA0B,EAAE;IAC3C,UAAU,EAAE;QACV,KAAK,EAAE,GAAG;QACV,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,UAAU;QACvB,OAAO,EAAE,OAAO;KACjB;IACD,MAAM,EAAE;QACN,KAAK,EAAE,GAAG;QACV,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,aAAa;KAC3B;IACD,GAAG,EAAE;QACH,KAAK,EAAE,GAAG;QACV,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;KACnB;CACF,CAAC;KACD,OAAO,CAAC,OAAO,EAAE,wBAAwB,EAAE;IAC1C,KAAK,EAAE;QACL,KAAK,EAAE,GAAG;QACV,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,YAAY;KAC1B;IACD,GAAG,EAAE;QACH,KAAK,EAAE,GAAG;QACV,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;KACnB;CACF,CAAC,CAAC;AAEL,MAAM,IAAI,GAAG,CAAO,MAAc,EAAE,EAAE;;IACpC,OAAO,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O,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC,CAAA,CAAC;AAEF,IAAI,EAAE,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import dgram from "dgram";
|
|
2
|
-
import { synapse } from "../api/api";
|
|
3
|
-
import Node from "../node";
|
|
4
|
-
declare class StreamIn extends Node {
|
|
5
|
-
type: synapse.NodeType;
|
|
6
|
-
config: synapse.IStreamInConfig;
|
|
7
|
-
_socket: dgram.Socket;
|
|
8
|
-
constructor(config?: synapse.IStreamInConfig);
|
|
9
|
-
write(data: string | Buffer): boolean;
|
|
10
|
-
toProto(): synapse.NodeConfig;
|
|
11
|
-
_getAddr: () => string | null;
|
|
12
|
-
static fromProto(proto: synapse.INodeConfig): StreamIn;
|
|
13
|
-
}
|
|
14
|
-
export default StreamIn;
|
|
15
|
-
//# sourceMappingURL=stream_in.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream_in.d.ts","sourceRoot":"","sources":["../../src/nodes/stream_in.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,cAAM,QAAS,SAAQ,IAAI;IACzB,IAAI,mBAA8B;IAClC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC;IAChC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC;gBAEV,MAAM,GAAE,OAAO,CAAC,eAAoB;IAKhD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO;IAsCrC,OAAO,IAAI,OAAO,CAAC,UAAU;IAM7B,QAAQ,QAAO,MAAM,GAAG,IAAI,CAM1B;IAEF,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,GAAG,QAAQ;CAQvD;AAED,eAAe,QAAQ,CAAC"}
|
package/dist/nodes/stream_in.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const dgram_1 = __importDefault(require("dgram"));
|
|
7
|
-
const api_1 = require("../api/api");
|
|
8
|
-
const node_1 = __importDefault(require("../node"));
|
|
9
|
-
class StreamIn extends node_1.default {
|
|
10
|
-
constructor(config = {}) {
|
|
11
|
-
super();
|
|
12
|
-
this.type = api_1.synapse.NodeType.kStreamIn;
|
|
13
|
-
this._getAddr = () => {
|
|
14
|
-
if (this.device === null) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
return this.device.uri.split(":")[0];
|
|
18
|
-
};
|
|
19
|
-
this.config = config;
|
|
20
|
-
}
|
|
21
|
-
write(data) {
|
|
22
|
-
if (this.device === null) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
const socket = this.device.sockets.find((s) => s.nodeId === this.id);
|
|
26
|
-
if (!socket) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
const split = socket.bind.split(":");
|
|
30
|
-
if (split.length !== 2) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
const port = parseInt(split[1]);
|
|
34
|
-
if (isNaN(port)) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
const host = split[0];
|
|
38
|
-
if (!host || !port) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
if (!this._socket) {
|
|
42
|
-
this._socket = dgram_1.default.createSocket("udp4");
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
this._socket.send(data, port, host);
|
|
46
|
-
}
|
|
47
|
-
catch (_a) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
toProto() {
|
|
53
|
-
return super.toProto({
|
|
54
|
-
streamIn: this.config,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
static fromProto(proto) {
|
|
58
|
-
const { streamIn } = proto;
|
|
59
|
-
if (!streamIn) {
|
|
60
|
-
throw new Error("Invalid config, missing streamIn");
|
|
61
|
-
}
|
|
62
|
-
return new StreamIn(streamIn);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.default = StreamIn;
|
|
66
|
-
//# sourceMappingURL=stream_in.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream_in.js","sourceRoot":"","sources":["../../src/nodes/stream_in.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAE1B,oCAAqC;AACrC,mDAA2B;AAE3B,MAAM,QAAS,SAAQ,cAAI;IAKzB,YAAY,SAAkC,EAAE;QAC9C,KAAK,EAAE,CAAC;QALV,SAAI,GAAG,aAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;QAqDlC,aAAQ,GAAG,GAAkB,EAAE;YAC7B,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC,CAAC;QArDA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,IAAqB;QACzB,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC;QACrE,IAAI,CAAC,MAAM,EAAE,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@ -1,23 +0,0 @@
|
|
|
1
|
-
import dgram from "dgram";
|
|
2
|
-
import { synapse } from "../api/api";
|
|
3
|
-
import Node from "../node";
|
|
4
|
-
import { Status } from "../utils/status";
|
|
5
|
-
declare class StreamOut extends Node {
|
|
6
|
-
type: synapse.NodeType;
|
|
7
|
-
_destinationAddress: string;
|
|
8
|
-
_destinationPort: number;
|
|
9
|
-
_label: string;
|
|
10
|
-
_socket: dgram.Socket | null;
|
|
11
|
-
_onMessage: ((msg: Buffer) => void) | null;
|
|
12
|
-
_onError: ((error: Error) => void) | null;
|
|
13
|
-
constructor(config: synapse.IStreamOutConfig, callbacks?: {
|
|
14
|
-
onMessage?: (msg: Buffer) => void;
|
|
15
|
-
onError?: (error: Error) => void;
|
|
16
|
-
});
|
|
17
|
-
start(): Promise<Status>;
|
|
18
|
-
stop(): Promise<Status>;
|
|
19
|
-
toProto(): synapse.NodeConfig;
|
|
20
|
-
static fromProto(proto: synapse.INodeConfig): StreamOut;
|
|
21
|
-
}
|
|
22
|
-
export default StreamOut;
|
|
23
|
-
//# sourceMappingURL=stream_out.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream_out.d.ts","sourceRoot":"","sources":["../../src/nodes/stream_out.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAc,MAAM,iBAAiB,CAAC;AAMrD,cAAM,SAAU,SAAQ,IAAI;IAC1B,IAAI,mBAA+B;IACnC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;IAC7B,UAAU,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IAC3C,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;gBAGxC,MAAM,EAAE,OAAO,CAAC,gBAAgB,EAChC,SAAS,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;KAAE;IAY/E,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IA2CxB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAQ7B,OAAO,IAAI,OAAO,CAAC,UAAU;IAc7B,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,GAAG,SAAS;CAQxD;AAED,eAAe,SAAS,CAAC"}
|
package/dist/nodes/stream_out.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const dgram_1 = __importDefault(require("dgram"));
|
|
16
|
-
const api_1 = require("../api/api");
|
|
17
|
-
const node_1 = __importDefault(require("../node"));
|
|
18
|
-
const status_1 = require("../utils/status");
|
|
19
|
-
const ip_1 = require("../utils/ip");
|
|
20
|
-
const kDefaultStreamOutPort = 50038;
|
|
21
|
-
const kSocketBufferSize = 5 * 1024 * 1024; // 5MB
|
|
22
|
-
class StreamOut extends node_1.default {
|
|
23
|
-
constructor(config, callbacks) {
|
|
24
|
-
super();
|
|
25
|
-
this.type = api_1.synapse.NodeType.kStreamOut;
|
|
26
|
-
const { udpUnicast } = config || {};
|
|
27
|
-
this._destinationAddress = udpUnicast === null || udpUnicast === void 0 ? void 0 : udpUnicast.destinationAddress;
|
|
28
|
-
this._destinationPort = (udpUnicast === null || udpUnicast === void 0 ? void 0 : udpUnicast.destinationPort) || kDefaultStreamOutPort;
|
|
29
|
-
this._label = config.label;
|
|
30
|
-
this._onMessage = callbacks === null || callbacks === void 0 ? void 0 : callbacks.onMessage;
|
|
31
|
-
this._onError = callbacks === null || callbacks === void 0 ? void 0 : callbacks.onError;
|
|
32
|
-
}
|
|
33
|
-
start() {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
try {
|
|
36
|
-
this._socket = dgram_1.default.createSocket("udp4");
|
|
37
|
-
if (!this._destinationAddress) {
|
|
38
|
-
try {
|
|
39
|
-
const ip = yield (0, ip_1.getClientIp)();
|
|
40
|
-
if (!ip) {
|
|
41
|
-
return new status_1.Status(status_1.StatusCode.INTERNAL, "failed to get client ip");
|
|
42
|
-
}
|
|
43
|
-
this._destinationAddress = ip;
|
|
44
|
-
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
console.error(e);
|
|
47
|
-
return new status_1.Status(status_1.StatusCode.INTERNAL, `failed to get client ip: ${e}`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (!this._destinationPort) {
|
|
51
|
-
this._destinationPort = kDefaultStreamOutPort;
|
|
52
|
-
}
|
|
53
|
-
this._socket.on("message", (msg) => {
|
|
54
|
-
var _a;
|
|
55
|
-
(_a = this._onMessage) === null || _a === void 0 ? void 0 : _a.call(this, msg);
|
|
56
|
-
});
|
|
57
|
-
this._socket.on("error", (error) => {
|
|
58
|
-
var _a;
|
|
59
|
-
(_a = this._onError) === null || _a === void 0 ? void 0 : _a.call(this, error);
|
|
60
|
-
});
|
|
61
|
-
yield new Promise((resolve, reject) => {
|
|
62
|
-
if (!this._socket)
|
|
63
|
-
return reject(new Error("Socket is null"));
|
|
64
|
-
this._socket.bind(this._destinationPort, this._destinationAddress, () => {
|
|
65
|
-
this._socket.setRecvBufferSize(kSocketBufferSize);
|
|
66
|
-
resolve();
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
return new status_1.Status();
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
return new status_1.Status(status_1.StatusCode.INTERNAL, `failed to start stream out node: ${e}`);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
stop() {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
if (this._socket) {
|
|
79
|
-
this._socket.close();
|
|
80
|
-
}
|
|
81
|
-
return new status_1.Status();
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
toProto() {
|
|
85
|
-
const config = {
|
|
86
|
-
label: this._label,
|
|
87
|
-
udpUnicast: {
|
|
88
|
-
destinationAddress: this._destinationAddress,
|
|
89
|
-
destinationPort: this._destinationPort,
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
return super.toProto({
|
|
93
|
-
streamOut: config,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
static fromProto(proto) {
|
|
97
|
-
const { streamOut } = proto;
|
|
98
|
-
if (!streamOut) {
|
|
99
|
-
throw new Error("Invalid config, missing streamOut");
|
|
100
|
-
}
|
|
101
|
-
return new StreamOut(streamOut, undefined);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
exports.default = StreamOut;
|
|
105
|
-
//# sourceM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