0.1.7 • Published 4 years ago

strapi-plugin-socket.io v0.1.7

Weekly downloads
-
License
GPLv3
Repository
github
Last release
4 years ago

Strapi Socket.io Plugin - ALPHA

Description

this plugin will enhance strapi with an easy to use StrapIO. It will trigger on entity changes and you don't need to write custome Controller like with StrapIO alone.

If you want to discuss more, then post on the forum thread

Or join the Discord.

The plugin was first created by derrickmehaffy - The Strapi Guru

Install in Strapi

Installing is simple and the plugin is enabled by default just a simple:

  • npm i -s strapi-plugin-socket
  • yarn add strapi-plugin-socket

In a Strapi project, tested on v3.6.2

Configuration

you can enable endpoints by creating an extension for strapi-plugin-socket. If there is no configuration file then ALL changes on entities are emit.

extensions/socket/services/config.json

{
	"routes": [
		{ "apiName": "user" }
	]
}

Client Sample

If you want a sample client to test with this:

NOTE as the original package author of StrapIO didn't specify you need the following package version of "socket.io-client": "2.3.0"

Init a new node project in a clean folder:

  • npm init
  • yarn init

Install the proper socket.io client:

  • npm i -s socket.io-client:2.3.0
  • yarn add socket.io-client:2.3.0

Create an index.js:

const io = require("socket.io-client");
const API_URL = "http://localhost:1337/";
const token = "replace with your end-user JWT";

// Handshake required, token will be verified against strapi
const socket = io.connect(API_URL, {
  query: { token },
});

socket.on("create", async (data) => {
  //do something
  console.log("CREATE");
  console.log(data);
});
socket.on("update", (data) => {
  // do something
  console.log("UPDATE");
  console.log(data);
});
socket.on("delete", (data) => {
  // do something
  console.log("DELETE");
  console.log(data);
});

Run it with node index.js you can also enable the socket.io debugger with DEBUG=socket* node index.js This will respond on all normal content-types (no plugins) with the exception of the content-manager plugin for normal content types.

TLDR: This works for updates made both in REST and the Strapi admin panel. I didn't test GraphQL because I'm lazy.

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.4-alpha.0

4 years ago

0.1.3-alpha.0

4 years ago