@formant/data-sdk 0.0.76 → 0.0.79
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/dist/data-sdk.es.js +218 -1
- package/dist/data-sdk.umd.js +7 -7
- package/dist/types/data-sdk/src/Device.d.ts +9 -1
- package/dist/types/data-sdk/src/Fleet.d.ts +2 -0
- package/dist/types/data-sdk/src/Manipulator.d.ts +2 -2
- package/dist/types/data-sdk/src/PeerDevice.d.ts +36 -0
- package/dist/types/data-sdk/src/RequestDataChannel.d.ts +4 -3
- package/dist/types/data-sdk/src/main.d.ts +2 -0
- package/dist/types/data-sdk/src/model/IStreamCurrentValue.d.ts +13 -0
- package/package.json +1 -1
package/dist/data-sdk.es.js
CHANGED
|
@@ -19217,6 +19217,218 @@ class Device {
|
|
|
19217
19217
|
return interventionResponse;
|
|
19218
19218
|
}
|
|
19219
19219
|
}
|
|
19220
|
+
class PeerDevice {
|
|
19221
|
+
constructor(peer_url) {
|
|
19222
|
+
__publicField(this, "rtcClient");
|
|
19223
|
+
__publicField(this, "remoteDevicePeerId");
|
|
19224
|
+
__publicField(this, "realtimeListeners", []);
|
|
19225
|
+
__publicField(this, "id");
|
|
19226
|
+
__publicField(this, "handleMessage", (peerId, message) => {
|
|
19227
|
+
this.realtimeListeners.forEach((_) => _(peerId, message));
|
|
19228
|
+
});
|
|
19229
|
+
this.peer_url = peer_url;
|
|
19230
|
+
}
|
|
19231
|
+
async getLatestTelemetry() {
|
|
19232
|
+
const data = await fetch(`${this.peer_url}/telemetry`);
|
|
19233
|
+
const telemetry = await data.json();
|
|
19234
|
+
const entries = Object.entries(telemetry);
|
|
19235
|
+
return entries.map(([stream, latestValue]) => {
|
|
19236
|
+
const v = {
|
|
19237
|
+
deviceId: this.id,
|
|
19238
|
+
streamName: stream,
|
|
19239
|
+
streamType: "json",
|
|
19240
|
+
currentValue: latestValue,
|
|
19241
|
+
currentValueTime: latestValue.timestamp,
|
|
19242
|
+
tags: {}
|
|
19243
|
+
};
|
|
19244
|
+
return v;
|
|
19245
|
+
});
|
|
19246
|
+
}
|
|
19247
|
+
async getDeviceId() {
|
|
19248
|
+
let result = await fetch(`${this.peer_url}/configuration`);
|
|
19249
|
+
const cfg = await result.json();
|
|
19250
|
+
return cfg.agent_config.id;
|
|
19251
|
+
}
|
|
19252
|
+
async getConfiguration() {
|
|
19253
|
+
let result = await fetch(`${this.peer_url}/configuration`);
|
|
19254
|
+
const cfg = await result.json();
|
|
19255
|
+
return cfg.agent_config.document;
|
|
19256
|
+
}
|
|
19257
|
+
getRealtimeStatus() {
|
|
19258
|
+
if (this.rtcClient && this.remoteDevicePeerId) {
|
|
19259
|
+
return this.rtcClient.getConnectionStatus(this.remoteDevicePeerId);
|
|
19260
|
+
} else {
|
|
19261
|
+
throw new Error(`Realtime connection hasn't been started`);
|
|
19262
|
+
}
|
|
19263
|
+
}
|
|
19264
|
+
getRealtimePing() {
|
|
19265
|
+
if (this.rtcClient && this.remoteDevicePeerId) {
|
|
19266
|
+
return this.rtcClient.getPing(this.remoteDevicePeerId);
|
|
19267
|
+
} else {
|
|
19268
|
+
throw new Error(`Realtime connection hasn't been started`);
|
|
19269
|
+
}
|
|
19270
|
+
}
|
|
19271
|
+
async startRealtimeConnection(_sessionType) {
|
|
19272
|
+
if (!this.rtcClient) {
|
|
19273
|
+
const rtcClient = new dist.exports.RtcClient({
|
|
19274
|
+
lanOnlyMode: true,
|
|
19275
|
+
receive: this.handleMessage
|
|
19276
|
+
});
|
|
19277
|
+
await rtcClient.connectLan(this.peer_url);
|
|
19278
|
+
while (true) {
|
|
19279
|
+
await delay(100);
|
|
19280
|
+
if (rtcClient.getConnections()[0].isReady()) {
|
|
19281
|
+
break;
|
|
19282
|
+
}
|
|
19283
|
+
}
|
|
19284
|
+
this.rtcClient = rtcClient;
|
|
19285
|
+
} else {
|
|
19286
|
+
throw new Error(`Already created realtime connection to device ${this.id}`);
|
|
19287
|
+
}
|
|
19288
|
+
}
|
|
19289
|
+
addRealtimeListener(listener) {
|
|
19290
|
+
this.realtimeListeners.push(listener);
|
|
19291
|
+
}
|
|
19292
|
+
removeRealtimeListener(listener) {
|
|
19293
|
+
const i = this.realtimeListeners.indexOf(listener);
|
|
19294
|
+
if (i === -1) {
|
|
19295
|
+
throw new Error("Could not find realtime listener to remove");
|
|
19296
|
+
}
|
|
19297
|
+
this.realtimeListeners.splice(i, 1);
|
|
19298
|
+
}
|
|
19299
|
+
async getRealtimeVideoStreams() {
|
|
19300
|
+
var _a, _b, _c;
|
|
19301
|
+
const document2 = await this.getConfiguration();
|
|
19302
|
+
const streams = [];
|
|
19303
|
+
for (const _ of (_a = document2.teleop.hardwareStreams) != null ? _a : []) {
|
|
19304
|
+
if (_.rtcStreamType === "h264-video-frame") {
|
|
19305
|
+
streams.push({
|
|
19306
|
+
name: _.name
|
|
19307
|
+
});
|
|
19308
|
+
}
|
|
19309
|
+
}
|
|
19310
|
+
for (const _ of (_b = document2.teleop.rosStreams) != null ? _b : []) {
|
|
19311
|
+
if (_.topicType == "formant/H264VideoFrame") {
|
|
19312
|
+
streams.push({
|
|
19313
|
+
name: _.topicName
|
|
19314
|
+
});
|
|
19315
|
+
}
|
|
19316
|
+
}
|
|
19317
|
+
for (const _ of (_c = document2.teleop.customStreams) != null ? _c : []) {
|
|
19318
|
+
if (_.rtcStreamType === "h264-video-frame") {
|
|
19319
|
+
streams.push({
|
|
19320
|
+
name: _.name
|
|
19321
|
+
});
|
|
19322
|
+
}
|
|
19323
|
+
}
|
|
19324
|
+
return streams;
|
|
19325
|
+
}
|
|
19326
|
+
async getRealtimeManipulators() {
|
|
19327
|
+
var _a;
|
|
19328
|
+
const document2 = await this.getConfiguration();
|
|
19329
|
+
const manipulators = [];
|
|
19330
|
+
for (const _ of (_a = document2.teleop.rosStreams) != null ? _a : []) {
|
|
19331
|
+
if (_.topicType == "sensor_msgs/JointState") {
|
|
19332
|
+
manipulators.push(new Manipulator(this, {
|
|
19333
|
+
currentJointStateStream: { name: _.topicName },
|
|
19334
|
+
plannedJointStateStream: _.plannedTopic ? { name: _.plannedTopic } : void 0,
|
|
19335
|
+
planValidStream: _.planValidTopic ? { name: _.planValidTopic } : void 0,
|
|
19336
|
+
endEffectorStream: _.endEffectorTopic ? { name: _.endEffectorTopic } : void 0,
|
|
19337
|
+
endEffectorLinkName: _.endEffectorLinkName,
|
|
19338
|
+
baseReferenceFrame: _.baseReferenceFrame,
|
|
19339
|
+
localFrame: _.localFrame
|
|
19340
|
+
}));
|
|
19341
|
+
}
|
|
19342
|
+
}
|
|
19343
|
+
return manipulators;
|
|
19344
|
+
}
|
|
19345
|
+
async startListeningToRealtimeVideo(stream) {
|
|
19346
|
+
const client = defined(this.rtcClient, "Realtime connection has not been started");
|
|
19347
|
+
const devicePeer = await this.getRemotePeer();
|
|
19348
|
+
client.controlRemoteStream(defined(devicePeer).id, {
|
|
19349
|
+
streamName: stream.name,
|
|
19350
|
+
enable: true,
|
|
19351
|
+
pipeline: "rtc"
|
|
19352
|
+
});
|
|
19353
|
+
}
|
|
19354
|
+
async stopListeningToRealtimeVideo(stream) {
|
|
19355
|
+
const client = defined(this.rtcClient, "Realtime connection has not been started");
|
|
19356
|
+
const devicePeer = await this.getRemotePeer();
|
|
19357
|
+
client.controlRemoteStream(defined(devicePeer).id, {
|
|
19358
|
+
streamName: stream.name,
|
|
19359
|
+
enable: false,
|
|
19360
|
+
pipeline: "rtc"
|
|
19361
|
+
});
|
|
19362
|
+
}
|
|
19363
|
+
async startListeningToRealtimeDataStream(stream) {
|
|
19364
|
+
const client = defined(this.rtcClient, "Realtime connection has not been started");
|
|
19365
|
+
const devicePeer = await this.getRemotePeer();
|
|
19366
|
+
client.controlRemoteStream(defined(devicePeer).id, {
|
|
19367
|
+
streamName: stream.name,
|
|
19368
|
+
enable: true,
|
|
19369
|
+
pipeline: "rtc"
|
|
19370
|
+
});
|
|
19371
|
+
}
|
|
19372
|
+
async stopListeningToRealtimeDataStream(stream) {
|
|
19373
|
+
const client = defined(this.rtcClient, "Realtime connection has not been started");
|
|
19374
|
+
const devicePeer = await this.getRemotePeer();
|
|
19375
|
+
client.controlRemoteStream(defined(devicePeer).id, {
|
|
19376
|
+
streamName: stream.name,
|
|
19377
|
+
enable: false,
|
|
19378
|
+
pipeline: "rtc"
|
|
19379
|
+
});
|
|
19380
|
+
}
|
|
19381
|
+
async enableRealtimeTelemetryPriorityIngestion(streamName) {
|
|
19382
|
+
const client = defined(this.rtcClient, "Realtime connection has not been started");
|
|
19383
|
+
const devicePeer = await this.getRemotePeer();
|
|
19384
|
+
client.controlRemoteStream(defined(devicePeer).id, {
|
|
19385
|
+
streamName,
|
|
19386
|
+
enablePriorityUpload: true,
|
|
19387
|
+
pipeline: "telemetry"
|
|
19388
|
+
});
|
|
19389
|
+
}
|
|
19390
|
+
async disableRealtimeTelemetryPriorityIngestion(streamName) {
|
|
19391
|
+
const client = defined(this.rtcClient, "Realtime connection has not been started");
|
|
19392
|
+
const devicePeer = await this.getRemotePeer();
|
|
19393
|
+
client.controlRemoteStream(defined(devicePeer).id, {
|
|
19394
|
+
streamName,
|
|
19395
|
+
enablePriorityUpload: false,
|
|
19396
|
+
pipeline: "telemetry"
|
|
19397
|
+
});
|
|
19398
|
+
}
|
|
19399
|
+
async getRemotePeer() {
|
|
19400
|
+
const peers = await defined(this.rtcClient, "Realtime connection has not been started").getPeers();
|
|
19401
|
+
const devicePeer = peers.find((_) => _.deviceId === this.id);
|
|
19402
|
+
return defined(devicePeer, "Could not find remote peer for device " + this.id);
|
|
19403
|
+
}
|
|
19404
|
+
async stopRealtimeConnection() {
|
|
19405
|
+
if (this.rtcClient) {
|
|
19406
|
+
await this.rtcClient.disconnect(this.id);
|
|
19407
|
+
} else {
|
|
19408
|
+
throw new Error(`Realtime connection hasn't been started for ${this.id}`);
|
|
19409
|
+
}
|
|
19410
|
+
}
|
|
19411
|
+
async createCustomDataChannel(channelName, rtcConfig) {
|
|
19412
|
+
const client = defined(this.rtcClient, "Realtime connection has not been started");
|
|
19413
|
+
const devicePeer = await this.getRemotePeer();
|
|
19414
|
+
const p = await new Promise((resolve) => {
|
|
19415
|
+
client.createCustomDataChannel(defined(devicePeer).id, channelName, __spreadValues({
|
|
19416
|
+
ordered: true
|
|
19417
|
+
}, rtcConfig), false, (_peerId, channel) => {
|
|
19418
|
+
const dataChannel = new DataChannel(channel);
|
|
19419
|
+
resolve(dataChannel);
|
|
19420
|
+
});
|
|
19421
|
+
});
|
|
19422
|
+
await p.waitTilReady();
|
|
19423
|
+
return p;
|
|
19424
|
+
}
|
|
19425
|
+
createCustomRequestDataChannel(channelName, timeout = 3e3) {
|
|
19426
|
+
return new TextRequestDataChannel(this, channelName, timeout);
|
|
19427
|
+
}
|
|
19428
|
+
createCustomBinaryRequestDataChannel(channelName, timeout = 3e3) {
|
|
19429
|
+
return new BinaryRequestDataChannel(this, channelName, timeout);
|
|
19430
|
+
}
|
|
19431
|
+
}
|
|
19220
19432
|
const _Fleet = class {
|
|
19221
19433
|
static async setDefaultDevice(deviceId) {
|
|
19222
19434
|
_Fleet.defaultDeviceId = deviceId;
|
|
@@ -19242,6 +19454,11 @@ const _Fleet = class {
|
|
|
19242
19454
|
_Fleet.knownContext.push(new WeakRef(context));
|
|
19243
19455
|
return context;
|
|
19244
19456
|
}
|
|
19457
|
+
static async getPeerDevice(url) {
|
|
19458
|
+
const peer = new PeerDevice(url);
|
|
19459
|
+
peer.id = await peer.getDeviceId();
|
|
19460
|
+
return peer;
|
|
19461
|
+
}
|
|
19245
19462
|
static async getDevice(deviceId) {
|
|
19246
19463
|
if (!Authentication.token) {
|
|
19247
19464
|
throw new Error("Not authenticated");
|
|
@@ -19537,4 +19754,4 @@ const moduleName = urlParams.get("module");
|
|
|
19537
19754
|
if (moduleName) {
|
|
19538
19755
|
Authentication.listenForRefresh();
|
|
19539
19756
|
}
|
|
19540
|
-
export { App, Authentication, BinaryRequestDataChannel, CaptureStream, DataChannel, Device, Fleet, KeyValue, Manipulator, SessionType, TextRequestDataChannel, accessLevels, administrator, aggregateLevels, annotationTypes, eventTypes, healthStatuses, interventionTypes, operator, severities, videoMimeTypes, viewer };
|
|
19757
|
+
export { App, Authentication, BinaryRequestDataChannel, CaptureStream, DataChannel, Device, Fleet, KeyValue, Manipulator, PeerDevice, SessionType, TextRequestDataChannel, accessLevels, administrator, aggregateLevels, annotationTypes, eventTypes, healthStatuses, interventionTypes, operator, severities, videoMimeTypes, viewer };
|