#new WebSocket, possible?
1 messages · Page 1 of 1 (latest)
I see in the LiveReload component
dangerouslySetInnerHTML: {
__html: js`
function remixLiveReloadConnect(config) {
let protocol = location.protocol === "https:" ? "wss:" : "ws:";
let host = location.hostname;
let socketPath = protocol + "//" + host + ":" + ${String(port)} + "/socket";
let ws = new WebSocket(socketPath);
ws.onmessage = (message) => {
let event = JSON.parse(message.data);
if (event.type === "LOG") {
console.log(event.message);
}
if (event.type === "RELOAD") {
console.log("💿 Reloading window ...");
window.location.reload();
}
};
ws.onopen = () => {
if (config && typeof config.onOpen === "function") {
config.onOpen();
}
};
ws.onclose = (error) => {
console.log("Remix dev asset server web socket closed. Reconnecting...");
setTimeout(
() =>
remixLiveReloadConnect({
onOpen: () => window.location.reload(),
}),
1000
);
};
ws.onerror = (error) => {
console.log("Remix dev asset server web socket error:");
console.error(error);
};
}
remixLiveReloadConnect();
`
}
But, when I drop in our otherwise working websocket url, it fails to connect
any ideas?
My issue may be a typo somewhere, troubleshooting a bit because swapping in wss://socketsbay.com/wss/v2/2/demo/ for my web socket domain worked
yeah, I'm using the Websocket library to connect to appsync just fine
import { useContext, useEffect, useState } from "react";
import * as websocket from "websocket";
import { websocketService } from "./Websocket.service";
import { v4 as uuidv4 } from "uuid";
import { RootContext } from "~/routes/auction";
const payload = encodeURIComponent("e30=");
let indyClient: any;
export const useIndySubscription = (query: string, variables: any) => {
const [message, setMessage] = useState<any>(undefined);
const [messageId, setMessageId] = useState(uuidv4());
const rootContext = useContext(RootContext);
if (!indyClient) {
indyClient = websocket.w3cwebsocket(
`wss://${getRealtimeHost()}/graphql?header=${encodeTokens()}&payload=${payload}`,
"graphql-ws"
);
}
well, not using new Websocket here so maybe not quite the same? But still a wss so shouldn't matter?
I've used this to implement socket.io https://github.com/remix-run/remix/tree/main/examples/socket.io
Did you find any solution for this using “new Websocket”?