Code Monkey home page Code Monkey logo

next-plugin-websocket's People

Contributors

sam3d avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

next-plugin-websocket's Issues

deploy

can I deploy trpc with this package adding websocket ability to vercel? or I have to deploy to somewhere else?

Build error after uninstalling the package

Hello, I found this package in a GitHub discussion while trying to find a solution to the problem in my Next.js app and I installed it and it worked perfectly but I realized that it does not match my case.

Anyway, when I uninstalled it from my terminal using npm uninstall next-plugin-websocket and pushed my code to GitHub, deployed to Vercel. I faced the following error when building project:

image

This error happened because the library works by injecting a couple of micro-patches into the Next.js core and this causes error when deleting the package so please take a look and think how find a solution for this issue.

Thanks for your time and efforts.

aftre install package next utils.js error

yarn run v1.22.19
$ next
D:\Dev\nextjs_ws_apollo\node_modules\next\dist\build\utils.js:1
"httpServer: server,
^^^^^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1176:20)
at Module._compile (node:internal/modules/cjs/loader:1218:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Module.require (node:internal/modules/cjs/loader:1141:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object. (D:\Dev\nextjs_ws_apollo\node_modules\next\dist\build\worker.js:13:14)
at Module._compile (node:internal/modules/cjs/loader:1254:14)

Node.js v18.16.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Get the WebSocketServer

The example provided in the README works perfectly, but it only illustrates how to respond back to the client when it sends something first.

How do I send something from the server to all connected clients or a particular client? Is there an exposed WebSocketServer that I am missing?

Thanks

Full example

Hello
please could you provide to me a complete example ( client / api) ?
thanks in advance
Joseph

run next dev found some error

hi sam3d,

nice job! the way use websocket is very clean and easy. today i tried this plugin , but found a error in the output log.

this.ensureApiPage is not a function!

can you give a full example ? thank u

env

{
  "name": "ws-demo",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "next": "13.2.4",
    "next-plugin-websocket": "^0.1.2",
    "react": "18.2.0",
    "react-dom": "18.2.0"
  }
}

node = 16.13.2

next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
ready - loaded websocket plugin successfully
event - compiled client and server successfully in 612 ms (168 modules)
wait - compiling /_error (client and server)...
event - compiled client and server successfully in 146 ms (169 modules)
warn - Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/messages/fast-refresh-reload
wait - compiling / (client and server)...
event - compiled client and server successfully in 206 ms (213 modules)
error - unhandledRejection: TypeError: this.ensureApiPage is not a function

Support new the app directory's Route Handlers of Next.js v13.3

Expected working example:

import { NextApiHandler } from "next";
import { NextWebSocketHandler } from "next-plugin-websocket";

export const socket: NextWebSocketHandler = (client, req) => {
  console.log("Client connected");

  client.on("message", (msg) => {
    client.send(msg);
  });

  client.on("close", () => {
    console.log("Client disconnected");
  });
};

export async function GET(request: Request) {
  return new Response("Upgrade Required", {
    status: 426,
  });
}

After PR #6 has been merged it will give an error if you try and use the above example.

error - unhandledRejection: PageNotFoundError: Cannot find module for page: /api/ws
    at findPagePathData (.../node_modules/next/dist/server/dev/on-demand-entry-handler.js:272:15)
    at async Object.ensurePage (.../node_modules/next/dist/server/dev/on-demand-entry-handler.js:444:38)
    at async Server.<anonymous> (.../node_modules/next-plugin-websocket/dist/index.js:88:13) {
  code: 'ENOENT'
}

It only works with the old pages directory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.