After the page loads I need to change the domain liveview mounts to. I can see that this happens, the socket mounts to the expected server. It appears, the problem is the callbacks on Hooks
are not called again so this
just throws:
phx-GBqsyCInsL9T32rB hook: unable to push hook event. LiveView not connected - push_permit
I have tried reassigning the hooks, embedding them in the function… in either case the mounted
JS callback is not called. Any ideas?
...
Hooks.Session = {
mounted() {
document.addEventListener("push_permit", async (event) => {
while (!this.pushEvent("push_permit", event.detail)) {
console.log(this.liveSocket, this)
await sleep(1000);
};
});
}
};
...
export function defineLiveSocket(host = null) {
const hostMeta = document.querySelector("meta[name='host']");
const hostValue = hostMeta ? hostMeta.getAttribute('content') : null;
if ((!host && !hostValue) || (window.liveSocket && window.liveSocket.getHref().includes(hostValue))) return null;
if (window.liveSocket) {
window.liveSocket.disconnect();
window.liveSocket = null;
}
const domain = host ? host : `ws://${hostValue}/live`;
hooks();
window.liveSocket = new LiveSocket(domain, Socket, {
params: { permit: document.querySelector("meta[name='session']").getAttribute("content") },
hooks: Hooks
});
window.liveSocket.connect();
}