Skip to content

Commit

Permalink
lsp: Fix handling of binary websocket messages
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Dec 15, 2024
1 parent 36f1773 commit c47f837
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/esbonio/changes/665.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix handling of binary websocket messages in documentation previews
14 changes: 13 additions & 1 deletion lib/esbonio/esbonio/sphinx_agent/static/webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,10 @@ const showMarkers = queryParams.has("show-markers")
const wsUrl = queryParams.get("ws");

console.debug(`Connecting to '${wsUrl}'...`)
const textDecoder = new TextDecoder()
const socket = new WebSocket(wsUrl);
socket.binaryType = 'arraybuffer'

let connected = false

function sendMessage(data) {
Expand Down Expand Up @@ -279,7 +282,16 @@ socket.addEventListener("open", (event) => {

// Listen for messages
socket.addEventListener("message", (event) => {
handle(JSON.parse(event.data))
let message

if (event.data instanceof ArrayBuffer) {
let buf = new Uint8Array(event.data)
message = JSON.parse(textDecoder.decode(buf))
} else {
message = JSON.parse(event.data)
}

handle(message)
});

function main() {
Expand Down

0 comments on commit c47f837

Please sign in to comment.