Skip to content

nccasia/mezon-web-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mezon Web SDK

Table of Contents

Features

  • Handles events from the web view, such as clicks and form submissions
  • Allows you to attach custom event handlers to specific events
  • Supports reloading the iframe on demand
  • Stores initialization parameters in session storage for easy retrieval

Install

<!DOCTYPE html>
<html>
<title>Mezon Web SDK</title>
<body>
  <!-- ... -->
  <script src="mezon-web-sdk.js"></script>
  <!-- ... -->
</body>
</html>

Now you can use the MezonWebView via window object:

window.Mezon.Webview

API

initParams: Record<string, string | null>

An object containing the initialization parameters for the web view

postEvent<T>(eventType: string, eventData: T, callback: Function): void

window.Mezon.Webview.postEvent('iframe_ready', () => {})
  • Posts an event from web view to Mezon, along with any associated data which will be sent as a JSON message to the parent window.

  • Handles an incoming event from Mezon. See MezonWebViewEvent for more information on available events.

  • eventType: The event will be posted to Mezon with this name.

  • eventData: The data associated with the event.

  • callback: An optional callback function that will be executed when the postEvent method completes.

receiveEvent<T>(eventType: MezonAppEvent, eventData: T): void

window.Mezon.Webview.postEvent('theme_changed', () => {})

Handles an incoming event from Mezon. See MezonAppEvent for more information on available events.

  • eventType: The type of event being received.
  • eventData: The data associated with the event.

onEvent<T>(eventType: MezonAppEvent, callback: MezonEventHandler<T>): void

window.Mezon.Webview.onEvent('theme_changed', () => {})

Registers a new handler for a specific event type. If an event of that type is received, it will be called with the associated data.

  • eventType: The type of event being registered.
  • callback: The function to call when the event occurs.

offEvent<T>(eventType: MezonAppEvent, callback: MezonEventHandler<T>): void

window.Mezon.Webview.offEvent('theme_changed', handler)

Unregisters a previously registered handler for a specific event type.

  • eventType: The type of event being unregistered.
  • callback: The function being removed from the handlers list.

Enums

MezonAppEvent

Events from Mezon to web view

export enum MezonAppEvent {
  ThemeChanged = 'theme_changed',
  ViewPortChanged = 'viewport_changed',
  SetCustomStyle = 'set_custom_style',
  ReloadIframe = 'reload_iframe',
}

MezonWebViewEvent

Events from web view to Mezon

export enum MezonWebViewEvent {
  IframeReady = 'iframe_ready',
  IframeWillReloaded = 'iframe_will_reload',
}

Build instruction

npm run build

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •