voryx / Thruway

PHP Client and Router Library for Autobahn and WAMP (Web Application Messaging Protocol) for Real-Time Application Messaging
MIT License
676 stars 117 forks source link

RPC Hooks #332

Open mbonneau opened 4 years ago

mbonneau commented 4 years ago

This change creates a Thruway-specific feature that allows for the hooking of RPCs.

A client can register an RPC that will receive calls for an already existing RPC. The client can then choose to service the call itself or it can call the original hooked RPC (either using it's own session context or the original session's context).

The use case for this feature are similar to hooking in any other environment. (debugging, extending functionality without changing the original RPC, etc.)

Usage:

Hook an existing RPC by registering a new RPC with the same name and the option: 'x_thruway_hook' => true. This registration will then receive all calls to that RPC.

These INVOCATIONs can be handled as a normal RPC if desired. The existing registration will not receive the INVOCATIONs.

The hooked registration can also call the underlying RPC by making a call with the option: ['x_thruway_call_hooked' => (object)[ 'registration_id' => $hookRegistrationId ]] and can call the underlying RPC with the session context of the caller using:

(object)[
                'x_thruway_call_hooked' => (object)[
                    'registration_id' => $hookRegistrationId,
                    'with_caller_from' => $origInvocationMessage->getRequestId()
                ]
            ]