Skip to content

pifabs/fsocket

Repository files navigation

Fsocket

Extend frappe's websocket server using socket.io and redis

Installation

Use frappe bench to add fsocket in your project

$ bench get-app https://github.com/pifabs/fsocket.git

Usage

Add "fsocketio_port" key in your common_site_config.json file and set the value to an unused port number

{
  ...,
  "fsocketio_port": 9002
}

Add the ff. line in your Procfile

...

fsocket_server: /usr/bin/node apps/fsocket/socketio.js

...

This will automatically launch a socket io server when you run "bench start"

...
22:27:01 system           | socketio.1 started (pid=28536)
22:27:02 fsocket_server.1 | listening on *: 9002
22:27:03 socketio.1       | listening on *: 9001
...

Now we listen to events emitted by frappe.publish_realtime()

...

subscriber.on("message", function (channel, message, room) {
	message = JSON.parse(message);
	if (message.room) {
		io.to(message.room).emit(message.event, message.message);
	} else {
		io.emit(message.event, message.message);
	}
});

...

Demo

We can also listen to events emitted by the client

...

io.on('connection', function (socket) {
	socket.on("msgprint", function(message) {
		console.log("message from client", message);
	});
});
...

Client to Server

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

About

Get realtime updates in your mobile/web app from frappe and erpnext

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published