npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mediaplatform/communications-library

v1.0.4

Published

The `@mediaplatform/communications-library` is intended as a communication middleman between the Sportal365 CMS and custom client applications. The library handles the transfer of messages and data between the two parties.

Downloads

360

Readme

SMP Communications library

The @mediaplatform/communications-library is intended as a communication middleman between the Sportal365 CMS and custom client applications. The library handles the transfer of messages and data between the two parties.

How to run the project

  1. Clone the project.
  2. Install dependencies with yarn install.
  3. Run yarn dev in project root to build the library in dist folder and start the library in the index.html file.

How to install library in client app

  1. Run yarn add @mediaplatform/communications-library

Bundling for production

The project is bundled with ⚡ Vite. To make a build run yarn build in project root to generate the production build in the dist folder. An example output will be:

communications-library
└── dist
    └── constants         <-- All messages 
    └── library           <-- The communications library main class
    └── utils             <-- The communications library utility functions

How to use

  1. Import the communications library in your file and the corresponding message constants and EventModel model:
  import {CommunicationsLibrary, EVENT_MESSAGE, EventModel, PARENT_DATA} from "@mediaplatform/communications-library" for the third party app;
  
  import {CommunicationsLibrary, EVENT_MESSAGE, EventModel} from "@mediaplatform/communications-library" for the Sportal365 CMS;

Note 1: EVENT_MESSAGE - indicates a message from the communications library has been sent

Note 2: CHILD_LOAD_FINISHED - indicates the child has loaded and ready to receive data from the parent

Note 3: PARENT_DATA - indicates the parent data has been sent to the child

Note 4: EventModel - the format of the callback function sent by the event listener: {type: messageType, data: data}

  1. Instantiate the communications library in the client application:
  const communicationsLibray = new CommunicationsLibrary(${targetOrigin});

Note 1: targetOrigin - the url, which points to the parent receiver (Sportal365 CMS)

  1. Instantiate the communications library in the Sportal365 CMS:

  const communicationsLibray = new CommunicationsLibrary(${targetOrigin}, ${contentWindow}); 
  

Note 1: targetOrigin - the url, which points to the child receiver (client application)

Note 2: contentWindow - the window of the parent (Sportal365 CMS), which represents the iframe in which the client application is loaded

  1. How to initiate the communication between Sportal365 CMS and client application:
    communicationsLibray.initiateHandshake();

Note 1: initiateHandshake() determines whether the communications library is called from the Sportal365 CMS or the client application and listens for communication events between the two parties.

Note 2: If the communications library is an instance of the parent (Sportal365 CMS), it listens for CHILD_LOAD_FINISHED event type and sends data of the parent (Sportal365 CMS) to the child (client application) BEFORE initiating the communication, you must set the data of the parent (custom block) in the communications library instance, so it can be sent to the child.

commsLib.setParentData(${blockData});

Note 3: If the communications library is an instance of the child (client application), it sends message of type CHILD_LOAD_FINISHED to the parent

  1. How to send and receive data as a child to and from the parent (Sportal365 CMS):

Note 1: Receiving and handling data from the parent

      communicationsLibray.listenForEvents((evt: EventModel) => {
        if (evt.type === PARENT_DATA) {
	    // Logic in client app that handles the data from the CMS
        }
    })

Note 2: Sending data to the parent

communicationsLibray.sendDataToParent({type: EVENT_MESSAGE, data: ${clientAppData}})
  1. How to send and receive data as a parent to and from the child (Client application):

Note 1: Receiving and handling data from the child

      communicationsLibray.listenForEvents((evt: EventModel) => {
		if (evt.type === EVENT_MESSAGE) {
	            // Logic in cms that handles the data from the custom app
		}
	});
  1. Closing the connection listeners:
   communicationsLibray.closeConnection()