Socket
Socket
Sign inDemoInstall

talkman

Package Overview
Dependencies
0
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    talkman

A simple, lightweight and flexible communication API. Define your own mechanism to send/receive your messages and leave the rest to us


Version published
Weekly downloads
27
increased by107.69%
Maintainers
2
Install size
6.58 kB
Created
Weekly downloads
 

Readme

Source

talkman

A simple, lightweight and flexible communication API. Define your own mechanism to send/receive your messages and leave the rest to us (to be continued...)

sample code

import CommAPI, {TransportBrowserWindow} from 'talkman';

let source = window;         // iframe window
let target = window.parent   // parent of iframe window

const transport = new TransportBrowserWindow ({
  sourceWindow : source,
  targetWindow : target
});

const incomingInfo = (payload) => {

  console.log (payload);
  //further process "INFO" payload here
};

const incomingRequest = (payload) => {

  let res = {};
  
  try {
    // process "REQUEST" payload here
    res = {/* prepare "RESPONSE" here */};
    return res;  // resolves the awaiting request promise on the other end
  }
  catch (err) {
    throw err;  
    // rejects the awaiting request promise on the other end
  }
};

const messenger = new CommAPI ({
  transportInstance: transport,
  onReq: incomingRequest,
  onInfo: incomingInfo
});



const info = {/* INFO payload message */};
messenger.sendInfo (info);

const req = {/* REQUEST payload message */};
messenger.sendReq (req).then (
  (response) => {
    // REQUEST resolved with RESPONSE
  },
  (err) => {
    //REQUEST rejected with an error
  }
)

Keywords

FAQs

Last updated on 08 Mar 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc