chat application example.
Mr A (07-Aug-2017 15:01) : hello all
Mr B (07-Aug-2017 15:20) : hello Mr A
The Server Date Time (dd-mmm-yyyy hh:mm) is inserted by Server. Which I can easy done in Ratchet.
Ratchet.Wamp.WampServerInterface api document
Inside the OnPublish, Where I can amend the message before really publish out.
Can Thruway do the same ? I cannot find any Thruway doc, and I see the examples but not found what I want.Thruway Examples
I think if I needed to accomplish this, I would use a slightly different architecture. I believe the idea of WAMP is to keep the router very generic. That is why we don't have any examples of this.
“All application specific code should reside in WAMP application components, not in the router itself.” —tobias
That being said, it still would not be too difficult to do what you want to do - but would require intercepting the messages. Ideally, it would be nice to override the Broker - but we don't have a generic way to switch that out right now. So we can override the Router and inspect every message:
class MyRouter extends Router {
public function onMessage(TransportInterface $transport, Message $msg) {
if ($msg instanceof PublishMessage) {
if ($msg->getTopicName() == "mytopic") {
// mangle the message in here
}
}
parent::onMessage($transport, $msg);
}
}
Then just use this class instead of the default Router when you are starting up.
I have not tried this code, if I get a chance I will. The idea should work though.