Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message handling #53

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Message handling #53

wants to merge 12 commits into from

Conversation

EvanSchalton
Copy link

@EvanSchalton EvanSchalton commented Feb 9, 2021

I haven't tried my hand at writing JSDoc before so please confirm I didn't do something boneheaded here

My problem statement is that my server (API Gateway) wont allow me to transmit my data in binary, so I had to base64 encode it which means that I need to tell y-quill to convert that data to unit8array/buffer -- I think it'd be helpful to future proof by allowing the user to provide a function that pre-processes their websocket events; with the default/fallback behavior of your typical processing (reading into a unit8array)

Huly®: YJS-730

@EvanSchalton
Copy link
Author

EvanSchalton commented Feb 9, 2021

I don't like maintaining code separately so I instead hacked this by overwriting the onmessage with the following:

    this._provider.ws.onmessage = event => {
      this._provider.wsLastMessageReceived = time.getUnixTime()
      const eventData = new Uint8Array(base64ToArrayBuffer(event.data))
      const encoder = readMessage(this._provider, eventData, true)
      if (encoding.length(encoder) > 1) {
        this._provider.send(encoding.toUint8Array(encoder))
      }
    }

It isn't as clean a solution as it required me to rewrite the non-exported readMessage function also, but I wanted to share this incase it helps illustrate the intent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant