update
This commit is contained in:
@@ -216,15 +216,15 @@ class ChatHandler {
|
||||
}
|
||||
|
||||
async handleMessage(msg) {
|
||||
const envelope = await smartreceive(msg, {
|
||||
const env = await smartreceive(msg, {
|
||||
fileserverDownloadHandler: this.downloadFile.bind(this)
|
||||
});
|
||||
|
||||
// Extract sender info from envelope
|
||||
const sender = envelope.senderName || 'Anonymous';
|
||||
const sender = env.senderName || 'Anonymous';
|
||||
|
||||
// Process each payload
|
||||
for (const payload of envelope.payloads) {
|
||||
for (const payload of env.payloads) {
|
||||
if (payload.type === 'text') {
|
||||
this.ui.addMessage(sender, payload.data);
|
||||
} else if (payload.type === 'image') {
|
||||
@@ -356,12 +356,12 @@ class FileDownloadService {
|
||||
|
||||
async downloadFile(sender, downloadId) {
|
||||
// Subscribe to sender's file channel
|
||||
const envelope = await smartreceive(msg, {
|
||||
const env = await smartreceive(msg, {
|
||||
fileserverDownloadHandler: this.fetchFromUrl.bind(this)
|
||||
});
|
||||
|
||||
// Process each payload
|
||||
for (const payload of envelope.payloads) {
|
||||
for (const payload of env.payloads) {
|
||||
if (payload.type === 'binary') {
|
||||
const filePath = `/downloads/${payload.dataname}`;
|
||||
fs.writeFileSync(filePath, payload.data);
|
||||
@@ -422,9 +422,9 @@ async function uploadFile(config) {
|
||||
const fileService = new FileUploadService(config.nats_url, config.fileserver_url);
|
||||
|
||||
try {
|
||||
const envelope = await fileService.uploadFile(filePath, recipient);
|
||||
const env = await fileService.uploadFile(filePath, recipient);
|
||||
console.log('Upload successful!');
|
||||
console.log(`File ID: ${envelope.payloads[0].id}`);
|
||||
console.log(`File ID: ${env.payloads[0].id}`);
|
||||
} catch (error) {
|
||||
console.error('Upload failed:', error.message);
|
||||
}
|
||||
@@ -533,7 +533,7 @@ class SensorSender:
|
||||
|
||||
data = [("reading", reading.to_dict(), "dictionary")]
|
||||
|
||||
# With is_publish=False, returns (envelope, json_str) without publishing
|
||||
# With is_publish=False, returns (env, env_json_str) without publishing
|
||||
env, env_json_str = smartsend(
|
||||
f"/sensors/{sensor_id}/prepare",
|
||||
data,
|
||||
@@ -597,9 +597,9 @@ class SensorReceiver:
|
||||
self.fileserver_download_handler = fileserver_download_handler
|
||||
|
||||
def process_reading(self, msg):
|
||||
envelope = smartreceive(msg, self.fileserver_download_handler)
|
||||
env = smartreceive(msg, self.fileserver_download_handler)
|
||||
|
||||
for dataname, data, data_type in envelope["payloads"]:
|
||||
for dataname, data, data_type in env["payloads"]:
|
||||
if data_type == "dictionary":
|
||||
reading = SensorReading(
|
||||
sensor_id=data["sensor_id"],
|
||||
@@ -699,10 +699,10 @@ class DeviceBridge:
|
||||
# Poll for messages
|
||||
msg = self._poll_for_message()
|
||||
if msg:
|
||||
envelope = smartreceive(msg)
|
||||
env = smartreceive(msg)
|
||||
|
||||
# Process payloads
|
||||
for dataname, data, data_type in envelope["payloads"]:
|
||||
for dataname, data, data_type in env["payloads"]:
|
||||
if dataname == "command":
|
||||
callback(data)
|
||||
|
||||
@@ -798,9 +798,9 @@ class DashboardServer:
|
||||
|
||||
def receive_selection(self, callback):
|
||||
def handler(msg):
|
||||
envelope = smartreceive(msg)
|
||||
env = smartreceive(msg)
|
||||
|
||||
for dataname, data, data_type in envelope["payloads"]:
|
||||
for dataname, data, data_type in env["payloads"]:
|
||||
if data_type == "dictionary":
|
||||
callback(data)
|
||||
|
||||
@@ -842,12 +842,12 @@ class DashboardUI {
|
||||
|
||||
async fetchData() {
|
||||
// Subscribe to data updates
|
||||
const envelope = await smartreceive(msg, {
|
||||
const env = await smartreceive(msg, {
|
||||
fileserverDownloadHandler: this.fetchFromUrl.bind(this)
|
||||
});
|
||||
|
||||
// Process table data
|
||||
for (const payload of envelope.payloads) {
|
||||
for (const payload of env.payloads) {
|
||||
if (payload.type === 'table') {
|
||||
// Deserialize Arrow IPC
|
||||
this.data = this.deserializeArrow(payload.data);
|
||||
|
||||
Reference in New Issue
Block a user