Giter Site home page Giter Site logo

lore-server's Introduction

lore-server

A small server that runs inside of Adobe CEP extensions to listen for fetch() messages from other extensions, plugins or local browsers.

Installation

$ npm install lore-server

Usage

// Via import:
import Lore from "lore-server";

// Via require:
const Lore = require("lore-server").default;

Quickstart

Create a new Lore instance:

// Import name becomes class object
import Lore from "lore-server";

// Server can then be created via new [class name]
const lore = new Lore(3200); // 3200 is the port we listen to

// Each class is a separate instance, independent of each other
const server = new Lore(3030, "127.0.0.1"); // Second param is address

console.log(lore);
console.log(server);

Broadcasting a message from an Adobe extension, web app or plugin:

// If neither port nor address are defined, they default to:
// http://127.0.0.1:3200
const lore = new Lore();

let msgObj = {
  appName: "Figma",
  version: "1.0.3"
};

lore.message(msgObj);

A Lore Message must contain a message that will be stringified.

Listening for messages within an Adobe extension:

function logMsg(msg) {
  console.log(msg);
}

lore.listener(logMsg);

A Lore Listener must contain a function that will do something with the received message.

Note: This is creating a localhost server and must be run within a node app. It cannot be run within the browser.

Examples

// message to be sent to an Adobe extension
let msgObj = {
  actionName: "popup",
  data: "This is a message from an alternate dimension"
};

// message data
lore.message(msgObj);
const lore = new Lore(9320);

// message listener inside of Adobe extension
function loreFilter(msg) {
  if (msg.actionName == "popup") {
    alert(JSON.stringify(msg.data, false, 2));
  } else if (msg.actionName == "newLayer") {
    /// code to create a new layer ///
  }
}

// message data
lore.listener(loreFilter);

The function loreFilter() is passed into the lore.listener() and parses the data that accompanies any messages received on port 9320. The data contained within this message is arbitrary and must be handled by the function passed into the listener.

About

This project is based on how heavily I personally rely on Adobe's Vulcan library for communication between Adobe extension panels. An attempt to extend this concept outside of Adobe apps led me to this article on the use of fetch() and the creation of localhost servers. Lore wraps up a lot of this to simplify server setup and fetch commands.

Thanks to Tom Scharstein for ongoing brain power and clarifying the process of creating a module.

lore-server's People

Contributors

adamplouff avatar inventsable avatar

Stargazers

Pedro Labonia avatar chvndler avatar Terkel avatar Tim Haywood avatar  avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

Forkers

inventsable

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.