1.0.0 • Published 5 years ago
local-intercom v1.0.0
Local Intercom
A package that allows browser tabs and windows to communicate. This was built to help me syncronize multiple browser tabs on the same machine.
Usage
- Install the package from npm.
npm i local-intercom - Include the package in your code.
include intercom from 'local-intercom' - Listen for a type of message and describe what to do.
intercom.listen('chat', (msg) => console.log(msg)) - Send messages.
intercom.send('notify')intercom.send('chat', 'Hello')intercom.send('update', { hello: 'world' })
Demo
Start a local demo with your favorite local web server. I use python in the following example.
git clone https://https://github.com/brettk-dev/local-intercom.git
cd local-intercom
python -m http.serverThen open http://localhost:8000/demo in your browser.
Details
- You must listen to the same type of message that is being sent. All other types will be ignored.
- The message being sent can be anything
JSON.stringifywill handle, orundefined. - This uses localStorage under the hood to pass data.
1.0.0
5 years ago