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

client originated messages handling is not supported #1

Open
roybirger opened this issue Jan 8, 2016 · 11 comments
Open

client originated messages handling is not supported #1

roybirger opened this issue Jan 8, 2016 · 11 comments

Comments

@roybirger
Copy link

Client originated messages are currenly sent to all other subscribers which is not very helpful if you want to do something else with the message (for example trigger some server action).
It would be great if they could be handled by an external component or plugin.

@juho-jaakkola
Copy link
Owner

I have two approaches in mind:

  1. The push server takes Elgg engine as a parameter, so it can trigger Elgg's internal features
  2. Each client originated message would be passed to Elgg using a separate AJAX call

@roybirger
Copy link
Author

  1. I think that injecting the engine would not help because it will mean that custom logic will have to be introduced to the plugin which will not be communication related.
  2. A seperate call would also be quite problematic if we want actions that are a direct result of a client mesage since it would mean that you would have to store client states or some similar data.

How about:
3. An interface for commands that would be triggered by the plugin on messages' arrival?

@juho-jaakkola
Copy link
Owner

  1. The engine could provide just the events service (and/or plugin hook service). That way the actual logic could be built into custom Elgg plugins instead of the communications plugin.
  2. I'm not sure what problems you mean. I think we could just make an ajax call to an Elgg action and on success:
    • Update the originator's DOM accordingly when the server responds
    • Communicate the action to other connected clients through ZMQ
  3. How would these be communicated to Elgg, if Elgg core is not injected to the push server?

(I numbered the suggestions on the previous messages, so it's easier to follow the discussion.)

@roybirger
Copy link
Author

Which hooks would the plugin trigger in case the elgg engine is passed to it? (Sorry but I'm relatively new to elgg...)
Would these be custom hooks or using one of the built in hooks?

@juho-jaakkola
Copy link
Owner

  1. The pusher plugin could trigger its own custom events.
// Called by the push server when it receives a client-originated message
elgg_trigger_event('receive', 'message', $message);
// Third-party plugins can now register an event handler for the [receive, message]
// event and do what they want with the message.
elgg_register_event_handler('receive', 'message', function($event, $type, $message) {
    // Do something with the message. E.g. save it to database:
    $chat_message = new ChatMessage();
    $chat_message->content = $message->content;
    $chat_message->save();
});

@roybirger
Copy link
Author

Looks good. I'll try to incorporate this into my project and use this plugin for communication,

If you need help with the work let me know.

@juho-jaakkola
Copy link
Owner

  1. One risk in this approach is that the Elgg core isn't really meant to run as an ongoing process (as it would if it were injected to the push server). There may be some memory leaks.
  2. Out of curiosity, could you explain in more detail the problems that this approach would cause? I see that it could work something like this:
    • User makes a call using AJAX
    • Server saves the data to database
    • Server sends the data to ZMQ (example here)
    • ZMQ sends the data to other connected users (example here and here)

@roybirger
Copy link
Author

In my login flow I want to send the user all of his pending notifications once he connects.

I also send a callback ID with each request in order to resolve the correct data in the client and in addition I save the latest callback id in the plugin (by assuming a maximum of one pending request to the server)

If I'll have to break this flow It will mean that I have to save to order of messages or keep several callbacks at any given time which I would like to avoid.

@roybirger
Copy link
Author

Hi,
Are you planning to add the custom hook trigger on message to the pusher plugin?
Also, can the pusher plugin avoid sending every message to all of the online users somehow?

@juho-jaakkola
Copy link
Owner

Are you planning to add the custom hook trigger on message to the pusher plugin?

Yes, it is on my TODO list. There aren't currently any clients paying for developing the plugin, so unfortunately it's a quite low priority. I'll however try to get the change in as soon as possible.

Also, can the pusher plugin avoid sending every message to all of the online users somehow?

You mean the message that tells which other users are online? AFAIK it's not send every message to all users. ...or is it?

@juho-jaakkola
Copy link
Owner

Please try out this branch: https://github.com/juho-jaakkola/elgg-pusher/tree/plugin_hook

When the server receives a message from client, it now triggers the [message, pusher] hook. Plugins can then register callbacks for the hook.

Would this help with your use case?

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