Comments (7)
Custom message passing can be implemented on top of the message 'receive' client event / middleware hook:
Server:
backend.use('receive', function(request, next) {
var data = request.data;
if (data.myApp) {
// Handle app specific messages and don't call next
return;
}
// Call next to pass other messages to ShareDB
next();
});
Client:
connection.on('receive', function(request) {
var data = request.data;
if (data.myApp) {
request.data = null;
// Handle app specific message
}
});
Send a message from client:
connection.send({
myApp: 'messageType',
...
});
Send a message from server:
agent.send({
myApp: 'messageType',
...
});
The agent is available in all middleware, so on the server you could send a message in reply to a message from the client, or send a message to the client from the 'connect' middleware as soon as the client connects, for example.
Let me know if that solves your issue!
from sharedb.
Is there any way to send a message from the server to all connected clients? I think agent.send
will send reply to only 1 client. Am I correct?
from sharedb.
@RisingGeek this doesn't sound related to this issue? What's your use case here?
from sharedb.
I am trying to make a real-time editor using sharedb and want to add video calling feature. Using socket io gives errors and when trying to use middleware provided by sharedb, server sends reply to only 1 client because it's ignoring it. I want a listener on client side for custom events.
from sharedb.
I'm not sure I understand what video calling has to do with ShareDB? Do you mean you're trying to send custom messages down the same socket ShareDB is using? In theory it's possible, although probably not advised. Can't you just open up a separate websocket, and send messages using whatever websocket protocol you want?
from sharedb.
Yes, I was sending custom message in the same socket that sharedb is using. Thanks for the advice. I will use a separate websocket.
from sharedb.
Custom message passing can be implemented on top of the message 'receive' client event / middleware hook:
Server:
backend.use('receive', function(request, next) { var data = request.data; if (data.myApp) { // Handle app specific messages and don't call next return; } // Call next to pass other messages to ShareDB next(); });Client:
connection.on('receive', function(request) { var data = request.data; if (data.myApp) { request.data = null; // Handle app specific message } });Send a message from client:
connection.send({ myApp: 'messageType', ... });Send a message from server:
agent.send({ myApp: 'messageType', ... });The agent is available in all middleware, so on the server you could send a message in reply to a message from the client, or send a message to the client from the 'connect' middleware as soon as the client connects, for example.
Let me know if that solves your issue!
I have applied this for passing custom messages but it gives an error Ignoring unrecognized message {
while sending message from server
from sharedb.
Related Issues (20)
- `TypeError Cannot read properties of null (reading 'callback')` when receiving subscribe response with no inflight subscribe HOT 4
- Feature suggestion: type accessors HOT 3
- Q: How multiple `Doc`s guarantee transactions? HOT 2
- Collaborative text field using react with debounce HOT 3
- How can I synchronize my article titles? HOT 6
- Avoid committing no-ops
- Feature Request: Support for Custom Type Projections in ShareDB HOT 3
- API Support for Presence Notifications HOT 6
- How do I implement custom messages, just like websockets HOT 2
- Consider Partysocket for Examples
- Access Control / Permissions HOT 2
- Example Proposal: Comments
- Messages artificially delayed when running `Backend` in the browser HOT 1
- how to reload/refresh ShareDB document? HOT 6
- Invalid op submitted. Op version newer than current snapshot HOT 4
- failed process file : failed send RangeError: Invalid string length HOT 4
- The doc links are broken
- [Bug Report] Server-Side Data Inconsistencies When Rapidly Creating Nodes in ShareDB HOT 12
- How to implement Presence with 'rich-text' as 'json1' subtype? HOT 2
- How to optimize the performance of large documents? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharedb.