#Float32 Array as mutation / action argument

3 messages · Page 1 of 1 (latest)

candid pendant
#

I'm working with audio files / streaming where I have to process audio chunks of Float32 array types. I have not tried but I was wondering if this was possible or supported in Convex or if there is a work around.

I have a separate server (Hono) that can process the audio chunk array and return data. I intend to keep this server "private" / "hidden", that is I do not want to interact with the server directly from the client so I can take advantage of authentication that is already set in convex. I want to use a server-server communication.

The GOAL: I call an action from convex, convex calls this server. I already use this server with my convex setup for HTTP calls where the arguments are strings. Within the convex action I make a POST request to this server to get data. Works fine.

The external server has 2 open endpoints...

  • One is a HTTP endpoint that I can call POST, GET etc on
  • The other is a Websocket connection that accepts a Float32 array

Since convex has an open Websocket connection (I stand to be corrected), I thought I could do the same thing I did with the HTTP endpoint, have a convex action that can call this Websocket connection, most importantly, I need a bi-directional connection between client -> convex -> custom server over websockets.

First concern, convex arguments. I can use v.any() but would a Float32 array work?

P.S: I have not implemented any of this yet, I'm evaluating possibilities to see the best approach. Most importantly I do not want to expose this custom server to the client, if I do, I have to implement authentication on it, this is why I'm looking for a solution that would allow me pass this request via Convex.

Open to ideas and suggestions.

mossy rover
#

for Float32Array you can use v.bytes() and call float32Array.buffer, because Convex supports ArrayBuffer https://docs.convex.dev/database/types

Making a websocket connection out from a Convex action to an external server sounds more difficult. Convex actions don't currently support outgoing websockets

All Convex documents are defined as Javascript objects. These objects can have

candid pendant
#

Thank you @mossy rover

That means I have to use the Websocket connection directly from the client. Next challenge is figuring out how to consume my existing auth (I use Convex auth) with this server in a less complicated manner.

I would like to authenticate the Websocket connection on this server with my pre-existing Convex auth. Any ideas?