Skip to content

Doesn't support binary messages #5

@gaberogan

Description

@gaberogan

Hi, I'm using this lib with yjs and ran into an error when I saw it was trying to parse the binary message to JSON in local.js. It also tries to parse it again in handler.js. Also it tries to stringify any binary messages sent back to the client.

https://github.com/JamesKyburz/aws-lambda-ws-server/blob/master/packages/aws-lambda-ws-server/src/local.js#L126

https://github.com/JamesKyburz/aws-lambda-ws-server/blob/master/packages/aws-lambda-ws-server/src/handler.js#L17

https://github.com/JamesKyburz/aws-lambda-ws-server/blob/master/packages/aws-lambda-ws-server/src/local.js#L94

Also should note that the postconnection lib also seems not to support binary messages. Note I haven't tested if this is even possible in the cloud yet and it's unfortunately not documented if it is.

https://github.com/JamesKyburz/aws-lambda-ws-server/blob/master/packages/aws-post-to-connection/src/index.js#L15

Normally this seems to conform to the Websocket API specification, but I imagine many libraries are used to communicating binary messages over websockets (see https://tools.ietf.org/html/rfc6455 and search 'binary frame'). There is even a CFN option to enable this:

contentHandlingStrategy: 'CONVERT_TO_BINARY', // see http://amzn.to/39DkYP4

My suggestion would be when parsing JSON fails, fall back to simply not parsing it, or at least check if it's a Buffer which would indicate it's a binary message. Locally on the ws server we also need to specify connection.binaryType = 'arraybuffer', so maybe this is better as a configuration variable.

Edit: feel free to close, I found out AWS doesn't support returning binary messages anyway. i'm going to work with base64 encoded text instead, which is still incompatible with JSON.stringify so something to consider perhaps for the next version (removing json stringify and parse)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions