Skip to content

Commit

Permalink
upgrade to liveviewjs 0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
floodfx committed Jan 12, 2023
1 parent ac87cc1 commit 6e87fcb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
46 changes: 28 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
}
},
"dependencies": {
"@liveviewjs/express": "0.7.0",
"@liveviewjs/express": "^0.8.1",
"express": "^4.18.1",
"express-session": "^1.17.2",
"liveviewjs": "0.7.0",
"liveviewjs": "^0.8.1",
"nprogress": "^0.2.0",
"phoenix": "^1.6.9",
"phoenix_html": "^3.2.0",
Expand Down
23 changes: 6 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// create new LiveViewServer
import { NodeExpressLiveViewServer, NodeWsAdaptor } from "@liveviewjs/express";
import { NodeExpressLiveViewServer } from "@liveviewjs/express";
import express from "express";
import session, { MemoryStore } from "express-session";
import { Server } from "http";
import { LiveViewRouter } from "liveviewjs";
import { nanoid } from "nanoid";
import path from "path";
import WebSocket from "ws";
import { todosLiveView } from "./todos/todos_component";
Expand Down Expand Up @@ -45,7 +44,9 @@ const liveView = new NodeExpressLiveViewServer(
router,
liveHtmlTemplate,
{ title: "TodoMVC", suffix: " · LiveViewJS" },
{ serDeSigningSecret: signingSecret }
{
serDeSigningSecret: signingSecret,
}
);

// setup the LiveViewJS middleware
Expand All @@ -64,20 +65,8 @@ const wsServer = new WebSocket.Server({
httpServer.on("request", app);

// initialize the LiveViewJS websocket message router
const liveViewRouter = liveView.wsRouter();

// send websocket requests to the LiveViewJS message router
wsServer.on("connection", (ws) => {
const connectionId = nanoid();
ws.on("message", async (message) => {
// pass websocket messages to LiveViewJS
await liveViewRouter.onMessage(connectionId, message.toString(), new NodeWsAdaptor(ws));
});
ws.on("close", async () => {
// pass websocket close events to LiveViewJS
await liveViewRouter.onClose(connectionId);
});
});
const liveViewWsMiddleware = liveView.wsMiddleware();
liveViewWsMiddleware(wsServer);

// listen for requests
const port = process.env.PORT || 3001;
Expand Down

0 comments on commit 6e87fcb

Please sign in to comment.