You are here

function hook_nodejs_message_callback in Node.js integration 8

Same name and namespace in other branches
  1. 7 nodejs.api.php \hook_nodejs_message_callback()

Define handlers for custom messages received from the Node JS Server.

Parameters

String $type: The type of message received from the Node JS Server. Serves to identify the specific extension of the server that sent the message to the drupal site. This is set by developers when writing their server extensions.

As an example, a module implementing this hook, and returning a function called "mymodule_message_handler", will have to implement that function as follows:

function mymodule_message_handler($message, &$response) { // Do whatever is needed with the message received. tell_mom_about_the_message($message);

// Tell something back to the Node JS server. $response = array( 'message' => 'Thanks, I just told my mom about this!'; ); }

Return value

array An array of function names. These functions will be executed sequentially, and will receive the original $message from the server, and a $response variable passed by reference, which they should use as per they needs. This variable is what will be sent back automatically by the nodejs module to the Node JS server.

1 invocation of hook_nodejs_message_callback()
NodejsPages::messageHandler in src/Controller/NodejsPages.php
@todo .

File

./nodejs.api.php, line 37
API documentation for the Nodejs integration module.

Code

function hook_nodejs_message_callback($type) {
  switch ($type) {

    // Not necessarily camelCase, but since the type is set on javascript, it'll
    // be usually camelCased.
    case 'myMessageType':
      return array(
        'my_message_handler',
      );
  }
}