Comments (7)
I might be correct about the race condition issue. If I change it to:
setInterval(async () => {
await server.publish('/item/5', { id: 5, status: 'complete' });
}, 1000);
Then messages go through, the filter
callback fires, the client's handler fires, etc.
Can the example be updated to something that works properly?
from nes.
@rgov in my own development, I was stumped for 15 minutes simply because I was using nodemon for both server and client and thus the client was trying to connect when the connection has not been established yet. restarting the client after the server is up works. this point should be mentioned in the example.
from nes.
Unfortunately, no community resources were available to help resolve this issue after two weeks, and it is being closed. We close unresolved community issues to keep the issue tracker organized and effective. Please check https://hapi.dev/support for other support options.
from nes.
the issue can be fixed by clarifying in the docs that the server and client shouldn't be in the same file or started at the same time, which is a 'no brainer' when you think about it, but is very easily overlooked when you're following docs and trying to get something to work the first time.
from nes.
I don't think they were in the same file, but it's been a while. That said I'm not sure why it should matter if they're in separate files, it's supposed to support concurrency, right?
Re-reading my bug report, I think there are at least 3 things wrong with the example (and/or the module) from my post.
It makes sense that the client can only connect after the server is listening, of course, but the fact that publishing a message didn't work in onSubscribe
but did after a 5 second timer suggests something weird about what's going on behind the scenes.
from nes.
yes it's not the fact that it's in the same file that's the issue, just that starting up the client in the line right after starting the server will most likely result in this issue since not enough time has passed since the server was started.
was it 5 seconds? your comment above has 1000 miliseconds, which was what I was able to replicate too.
from nes.
Here is a working example that doesn't rely on a race. In short, you should start the server before connecting the client, and let the subscription complete before having the server publish.
const Hapi = require('@hapi/hapi');
const Nes = require('@hapi/nes');
(async () => {
const server = new Hapi.Server();
const client = new Nes.Client('ws://localhost');
await server.register(Nes);
server.subscription('/item/{id}');
await server.start();
await client.connect();
const handler = (update, flags) => {
// update -> { id: 5, status: 'complete' }
// Second publish is not received (doesn't match)
};
await client.subscribe('/item/5', handler);
server.publish('/item/5', { id: 5, status: 'complete' });
server.publish('/item/6', { id: 6, status: 'initial' });
})();
from nes.
Related Issues (20)
- Action required: Greenkeeper could not be activated 🚨 HOT 1
- Update deps HOT 1
- Get auth result on connect HOT 2
- nes fails to verify credentials with hapi-auth-jwt2 customVerify function HOT 2
- Client is not working in browser. HOT 5
- Fails to load in IE11 due to ES6 syntax HOT 5
- Error: Connection requires authentication HOT 1
- Only node 12
- Require hapi 19
- Change plugin name to @hapi/nes
- WSS integration HOT 1
- request.info.remoteAddress is always 127.0.0.1 in request handler
- Access server.publish from another file HOT 1
- Non standard browser cookie in Nes authentication HOT 1
- Polling option fallback HOT 1
- Socket closing without prompt
- Error is thrown, if client.connect({auth: 'somestring'})
- Can't received publish messages from browser HOT 2
- Using nextjs with it conflicts with the HRM Websocket HOT 1
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 nes.