Coder Social home page Coder Social logo

directus-websocket-subscribe's Introduction

Brainslug's GitHub stats

directus-websocket-subscribe's People

Contributors

br41nslug avatar piotr-cz 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  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  avatar  avatar  avatar  avatar  avatar

directus-websocket-subscribe's Issues

Cannot run directus-websocket-subscribe with the latest npm version

Hi, I've tried "directus-extension-websocket-subscribe": "^3.1.11" with "directus": "10.2.1"/"10.0.0", and the directus shows the error message. The repo said has already tested with directus 10. So is the npm version the latest build? How can I use the package along with directus v10.

BTW, I was able to run along with "directus": "9.24.0".

SyntaxError: Cannot use import statement outside a module
              at Object.compileFunction (node:vm:360:18)
              at wrapSafe (node:internal/modules/cjs/loader:1119:15)
              at Module._compile (node:internal/modules/cjs/loader:1155:27)
              at Object.Module._extensions..js (node:internal/modules/cjs/loader:1245:10)
              at Module.load (node:internal/modules/cjs/loader:1069:32)
              at Function.Module._load (node:internal/modules/cjs/loader:904:12)
              at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
              at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
              at async Promise.all (index 0)
              at async ESMLoader.import (node:internal/modules/esm/loader:530:24)

Add authorization

A connected websocket client is stateful right? Maybe we could add an "authorize" type that will set the access token of the current session. That way, we could rely on the access token of the session to check against the permissions w/ the regular permissions/authorization middleware before responding over the socket with the requested data 🤔

Permissions are not checked

i am sending the authorization token via query param
The read permission on my notifications collection is set to $CURRENT_USER

image

so only notifications sent to the user can read it.

But currently the websocket is receiving events for all the notifications after subscribing.

Invalid message type! Either get, post, patch, delete or subscribe expected

Hi, there, I'm new to this extension, looks great and I can connect to my server.
ws://127.0.0.1:8082/websocket

- Connection open
- Connecting to: ws://127.0.0.1:8082/websocket

But when I send a message, it shows the following error, I've tried GET/get

- Received: {
  "type": "ERROR",
  "data": "Invalid message type! Either get, post, patch, delete or subscribe expected"
}
- Sending message: {
  "type": "get",
  "collection": "myoffer",
  "query": {
    "fields": [
      "*"
    ],
    "limit": 5
  },
  "uid": "9a58ccda-3578-478b-b7be-52ed647ff9f1"
}

image

My Deps

  "dependencies": {
    "@elecerp/directus-extension-vgrid-echart": "^0.1.1",
    "directus": "9.23.4",
    "directus-extension-websocket-subscribe": "^3.0.10",
    "pg": "^8.7.3"
  }

My .env file

# Websocket
WEBSOCKET_PUBLIC='true'
WEBSOCKET_PATH="/websocket"
WEBSOCKET_SYSTEM=false
WEBSOCKET_CORE='true'
WEBSOCKET_CORE_GET='true'
WEBSOCKET_CORE_POST='true'
WEBSOCKET_CORE_PATCH='true'
WEBSOCKET_CORE_DELETE='true'

How would this work over a horizontally scaled Directus app?

Awesome library! i’m just wondering how this could effectively be implemented over a horizontally scaled Directus setup? If you have 2 servers running docker swarm with Directus replicated over the two, if an update is made to a collection item through instance A, how would clients connected to instance B receive the update messages?

9.9.1 env is not loaded to setup config

Hello, i set on directus 9.9.1 .env properties as your documentation, but they are not loaded. only setting it in config.ts works.
Second try was to create a hook

export default ({ filter, action }) => {
	filter('websocket.config', () => {
            cfg.path = '/test'; // Change the websocket path
            cfg.public = true; // Enable public connections to the websocket
            cfg.system.delete = false; // Disable the delete handler
            return cfg;
	});
};

or this does not work.. loading the hook before or after, does not matter.

export default (_, { logger, emitter }) => {
  emitter.onFilter('websocket.config', (cfg) => {
    cfg.path = '/test'; // Change the websocket path
    cfg.public = true; // Enable public connections to the websocket
    cfg.system.delete = false; // Disable the delete handler
    return cfg;
  });
};

module.exports = function registerHook(_, { logger, emitter }) {
  emitter.onFilter('websocket.config', (cfg) => {
    cfg.path = '/test'; // Change the websocket path
    cfg.system = true; // Enable system collection events
    cfg.core.delete = false; // Disable the delete handler
    return cfg;
  });
};

how to unsubscribe

Is there any unsubscribe handler , using a subscription uid or unsubscribe all from current channel
thanks

How can i custom payload answer

Default i receive this

{ "type": "SUBSCRIPTION", "action": "create", "payload": { "id": 1, "test": "test123", }, "key": 1, "collection": "test" }

but i want to show this
I want to for example populate some field manually

{ "type": "SUBSCRIPTION", "action": "create", "payload": { "id": { "name":"dqsqs", "email":"[email protected]" }, "test": "test123", }, "key": 1, "collection": "test" }

Directus 9.22.4 breaks /websocket route

Directus 9.22.4 breaks /websocket route

1|api  | 2023-01-12T13:50:34: [13:50:33.871] DEBUG: Route /websocket doesn't exist.
1|api  | 2023-01-12T13:50:34:     err: {
1|api  | 2023-01-12T13:50:34:       "type": "RouteNotFoundException",
1|api  | 2023-01-12T13:50:34:       "message": "Route /websocket doesn't exist.",
1|api  | 2023-01-12T13:50:34:       "stack":
1|api  | 2023-01-12T13:50:34:           Error: Route /websocket doesn't exist.
1|api  | 2023-01-12T13:50:34:               at notFound (/var/www/api/node_modules/directus/dist/controllers/not-found.js:31:14)
1|api  | 2023-01-12T13:50:34:       "status": 404,
1|api  | 2023-01-12T13:50:34:       "code": "ROUTE_NOT_FOUND",
1|api  | 2023-01-12T13:50:34:       "extensions": {}
1|api  | 2023-01-12T13:50:34:     }

Extension not working in AWS ECS environment

Hi, @br41nslug !

Your extension is awesome and it's working perfectly fine for me locally (before and after dockerization). However, right after I deploy it to an AWS fargate-managed ECS cluster, the task is launched but after some minutes, the container goes to a CPU max usage and it basically gets stuck:

Here's the environment configuration:

ACCESS_TOKEN_TTL=60m
[email protected]
ADMIN_PASSWORD=password123
ASSETS_CACHE_TTL=30m
CACHE_ENABLED=false
CACHE_STORE=memory
CORS_ALLOWED_HEADERS=Content-Type,Authorization
CORS_CREDENTIALS=true
CORS_ENABLED=true
CORS_EXPOSED_HEADERS=Content-Range
CORS_MAX_AGE=18000
CORS_METHODS=GET,POST,PATCH,DELETE
CORS_ORIGIN=true
DB_CLIENT=pg
DB_DATABASE=MY-DB
DB_HOST=MY-DB-HOST
DB_PASSWORD=MY-PASSWORD!
DB_PORT=5432
DB_USER=MY=DB=USER
[email protected]
EMAIL_SENDMAIL_NEW_LINE=unix
EMAIL_SENDMAIL_PATH=/usr/sbin/sendmail
EMAIL_TRANSPORT=sendmail
EXTENSIONS_AUTO_RELOAD=false
EXTENSIONS_PATH=./extensions
HOST=0.0.0.0
KEY=SOME-RANDOM-KEY
PORT=8056
PUBLIC_URL=MY-URL
REFRESH_TOKEN_COOKIE_DOMAIN=MY-URL
REFRESH_TOKEN_COOKIE_NAME=directus_refresh_token
REFRESH_TOKEN_COOKIE_SAME_SITE=none
REFRESH_TOKEN_COOKIE_SECURE=true
REFRESH_TOKEN_TTL=7d
SECRET=SOME-SECRET
STORAGE_AMAZON_BUCKET=MY-BUCKET
STORAGE_AMAZON_DRIVER=s3
STORAGE_AMAZON_KEY=SOME-KEY
STORAGE_AMAZON_REGION=eu-west-2
STORAGE_AMAZON_ROOT=
STORAGE_AMAZON_SECRET=SOME-SECRET
STORAGE_LOCATIONS=amazon

And here's the Dockerfile

# NOTE: Testing Only. DO NOT use this in production

ARG NODE_VERSION=16-alpine

FROM node:${NODE_VERSION}

WORKDIR /directus

COPY . .

RUN rm -rf node_modules

RUN apk add --update python3 make g++\
   && rm -rf /var/cache/apk/*

RUN npm install

WORKDIR /directus/api

CMD ["sh", "-c", "npm run start"]
EXPOSE 8055/tcp
EXPOSE 8056/tcp

I tried increasing the task memory to 2 vCPU and 8 GBs of memory. Still unresponsive.

Removing the package with the same configuration previously shown worked, even reducing memory and vCPUs to its minimal.

Do you have any idea why is it failing? Is there any specific configuration that's necessary in order to run this extension inside a serverless environment like AWS ECS Fargate? Thanks in advance, pal

Collection does not exist in schema

Hi
I am trying to use this extension to get updates of items created in a collection over a web socket.

I used npm to install this extension..

I can connect to the websocket successfully but even with admin permissions I get "Collection does not exist in schema"
image
image

I tried different collections but I get the same result. Any idea what could be causing this?

When set WEBSOCKET_CORE_SUBSCRIBE='true', cannot start directus

Hi, when I add WEBSOCKET_CORE_SUBSCRIBE='true' in my env,

[16:43:42.717] INFO: Websocket listening on ws://localhost:8082/websocket
/Users/dragonszy/Github/elecsim/elecsim-pg-dapi/node_modules/.store/[email protected]/node_modules/directus-extension-websocket-subscribe/dist/index.js:1

TypeError: Cannot read properties of undefined (reading 'buildDispatcher')

The following .env can start directus

WEBSOCKET_PUBLIC='true'
WEBSOCKET_PATH="/websocket"
WEBSOCKET_SYSTEM='true'
WEBSOCKET_CORE='true'
WEBSOCKET_CORE_GET='true'
WEBSOCKET_CORE_POST='true'
WEBSOCKET_CORE_PATCH='true'
WEBSOCKET_CORE_DELETE='true'

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.