Skip to content

afeiship/message-bridge

Repository files navigation

message-bridge

Web/h5/mp bridge for web/mp.

version license size download

installation

yarn add @jswork/message-bridge

usage

import messageBridge from '@jswork/message-bridge';

// Register a handler for incoming messages
messageBridge.registerHandler('message:in', (data, responseCallback) => {
  console.log('Received data:', data);
  // Send response back
  responseCallback({ status: 'success' });
});

// Send a message and handle the response
messageBridge.callHandler('message:out', { type: 'request', payload: 'Hello!' }, (response) => {
  console.log('Got response:', response);
});

license

Code released under the MIT license.