publish video on same event loop as websocket
This commit is contained in:
@@ -85,7 +85,7 @@ var connect_to_api = function () {
|
|||||||
console.log("got image");
|
console.log("got image");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("could not parse as json, must be bytes");
|
// console.log("could not parse as json, must be bytes");
|
||||||
send_image_data_to_clients(message);
|
send_image_data_to_clients(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
img.onload = function () {
|
img.onload = function () {
|
||||||
// Once the image has loaded, set it as the source of the <img> element
|
// Once the image has loaded, set it as the source of the <img> element
|
||||||
imgElement.src = this.src;
|
imgElement.src = this.src;
|
||||||
console.log("set image data src")
|
// console.log("set image data src")
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set the base64-encoded image data as the source of the image
|
// Set the base64-encoded image data as the source of the image
|
||||||
@@ -84,7 +84,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
events.onmessage = (event) => {
|
events.onmessage = (event) => {
|
||||||
console.log("MESSAGE RECEIVED");
|
// console.log("MESSAGE RECEIVED");
|
||||||
const eventData = JSON.parse(event.data);
|
const eventData = JSON.parse(event.data);
|
||||||
|
|
||||||
// Check if the event contains image data
|
// Check if the event contains image data
|
||||||
|
|||||||
@@ -109,11 +109,11 @@ class ApiListener(Node):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.get_logger().error('Something went wrong while reading video: ' + str(e))
|
self.get_logger().error('Something went wrong while reading video: ' + str(e))
|
||||||
|
|
||||||
def publish_message(self, message):
|
async def publish_message(self, message):
|
||||||
# self.get_logger().info(f'Publishing message: {message}')
|
# self.get_logger().info(f'Publishing message: {message}')
|
||||||
if self.websocket is not None:
|
if self.websocket is not None:
|
||||||
try:
|
try:
|
||||||
asyncio.run(self.websocket.send(message))
|
await self.websocket.send(message)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.get_logger().error(
|
self.get_logger().error(
|
||||||
'Something went wrong while sending a message to the websocket: ' + str(e))
|
'Something went wrong while sending a message to the websocket: ' + str(e))
|
||||||
@@ -131,7 +131,8 @@ class ApiListener(Node):
|
|||||||
while True:
|
while True:
|
||||||
if len(self.message_queue) > 0 and self.websocket is not None:
|
if len(self.message_queue) > 0 and self.websocket is not None:
|
||||||
# self.get_logger().info("sending message")
|
# self.get_logger().info("sending message")
|
||||||
self.publish_message(self.message_queue.pop(0))
|
loop = asyncio.get_event_loop()
|
||||||
|
asyncio.ensure_future(self.publish_message(self.message_queue.pop(0)), loop=loop)
|
||||||
|
|
||||||
def start_api_thread(self):
|
def start_api_thread(self):
|
||||||
asyncio.run(self.handle_api())
|
asyncio.run(self.handle_api())
|
||||||
|
|||||||
Reference in New Issue
Block a user