StrapIO the ez to use socket.io configurator

Hey,

I wrote a little module to use socket.io without pain. It verifies the token and used role permissions to decide when to emit events to user. You can install it via npm.

npm i strapio

7 Likes

Hi @larsonnn, pardon my noob question, but is this module for creating notifications within Strapi?

Hello i install this module but i donā€™t find the file on api, maybe strapi developments delete?? greetings

strapio will emit some socketio messages. So when you mean by notifications that its sending socketio messages, yes.

Which file? StrapIO will be in your node_modules. You need to write some code yourself.

@larsonnn Iā€™m wondering if building a middleware to emit the socket.io events might be better (maybe with a whitelist, could be cool to create a plugin or something for this :thinking:)

the problem with middleware is the lack of information. AFAIK, you have not all information in middleware for validating if someone has the permission to receive the message etc. Its missing for example the controller information.

middleware has only context information. So far you would need to inject the needed information in custom controllers.

But maybe someone knows more.

I was playing around and just built a plugin for it lol: strapi-plugin-socket - npm

This is just a sample and I wonā€™t likely maintain it.

1 Like

It would be nice if someone could maintain it.

Thanks for this great source.

1 Like

Happy to hand the package and repo over to anyone who wants to maintain it, I only did it as a test honestly and there is a lot of extra features that could be added.

1 Like

The only question i have here is that can you provide the server side example for emitting the message,
in STRAPIO we had to update bootstrapi.js and also add those emitting events in controllers where needed.
what do we do here ?
I hope this is not open and emits data on all CRUDS on all content types.

1 Like

My example package does, but some feature could be added in a fork much like the strapi-middleware-cache package does. My plugin was only a POC and isnā€™t intended for actual usage.

Maybe we need a ā€œlooking for maintainerā€ section in forum and discord.

@Saad_Mujeeb there is an upcoming PR in the project where you can configure endpoints.

But you should not use it in production yet, it has no maintainer and the code is not well tested.

I guess I will try to maintainā€¦ Hope I get help soon. :slight_smile:

I have renamed my fork to strapi-plugin-socket.io ā† because its no websocket. And the name shouldnt confuse developers.

I will publish to npm soon

1 Like

NPM: https://www.npmjs.com/package/strapi-plugin-socket.io

EDIT:

had to rename to: strapi-plugin-socket-io - npm

strapi cant import plugins with socket.<-dot

I have a question related to this: Will Strapi 4 support Graphql subscriptions?

No, not initially

It is one of the most strong features from GraphQL and one of the feature we most miss from Amplify.

There are various reasons why it hasnā€™t been implemented yet, one big one is scaling and the fact we donā€™t have a valid/native way to connect up a memory database like Redis yet.

Itā€™s coming, we just donā€™t have a date and the initial v4 is about massive refactoring to our backend (plus the new design system) and we are at our capacity for modifications that fit within our deadline.

Point is: We want to do a lot of stuff, but we are lacking in Devs and time that fit within our long term plan. Speaking of, if you know anyone we have lots of positions open and a lot more being opened soon:

2 Likes

STRAPIO v2 is out. Its subscribe only. You need to socket.emit(ā€˜subscribeā€™, ā€˜articleā€™) in your client to get the data.

2 Likes