Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message not received on client #11

Open
little-brain opened this issue May 10, 2020 · 1 comment
Open

Message not received on client #11

little-brain opened this issue May 10, 2020 · 1 comment

Comments

@little-brain
Copy link

Hi, I can't get the client to receive a message from the server. Here's my code:

Meteor.startup(() => {
if (Meteor.isServer) {
		let protocol = JsonProtocol.getInstance();

		protocol.on('myMessage', (data, sessionId) => {
			console.log('server received message', data, sessionId);
			protocol.send('myMessage', { 'myData': `to send from server to ${sessionId}`, sessionId });
		});
	}
});

On the client:

Template.myTemplate.onRendered(function () {
let protocol = JsonProtocol.getInstance();

	console.log('about to send message');
	protocol.send('myMessage', { 'myData': 'to send from client' });

	protocol.on('myMessage', (data) => {
		console.log('client received message', data);
	});
});

The console logs show that the server receives the message from the client, but the client does not receive the message from the server. This looks like a great package if I could only figure out how to get this working? Thanks!

@wojtkowiak
Copy link
Owner

wojtkowiak commented May 11, 2020

You have a mistake in the syntax. Sorry, the server part should be throwing in this case.

You have:
protocol.send('myMessage', { 'myData': 'to send from server to ${sessionId}', sessionId });
You should have:
protocol.send('myMessage', { 'myData': 'to send from server to ${sessionId}' }, sessionId);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants