How to use the post-robot.on function in post-robot

To help you get started, we’ve selected a few post-robot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Bearer / bearer-js / packages / js / src / lib / bearer.ts View on Github external
static get authorizedListener() {
    if (!window[LISTENER_KEY]) {
      // TODO: get rid of post robot, too heavy for our needs
      window[LISTENER_KEY] = new EventEmitter()
      postRobot.on('BEARER_AUTHORIZED', ({ data }) => {
        window[LISTENER_KEY].emit(authorizeEvent(data.scenarioId || data.integrationId), data)
      })
      postRobot.on('BEARER_REJECTED', ({ data }) => {
        window[LISTENER_KEY].emit(rejectEvent(data.scenarioId || data.integrationId), data)
      })
    }
    return window[LISTENER_KEY]
  }
github buttercup / buttercup-browser-extension / source / tab / messaging.js View on Github external
function startPostMessageListener() {
    postRobot.CONFIG.LOG_LEVEL = "error";
    postRobot.on("bcup-close-dialog", () => {
        hideInputDialog();
        hideSaveDialog();
    });
    postRobot.on("bcup-get-url", () => window.location.href);
    postRobot.on("bcup-open-url", event => {
        const { url } = event.data;
        chrome.runtime.sendMessage({ type: "open-tab", url });
    });
}
github TheIdentitySelector / thiss-js / src / ps / index.js View on Github external
if (storage.isSet(id)) {
        return storage.get(id);
    } else {
        return undefined;
    }
}

function check_access(event) {
    if (whitelist) {
        if (!whitelist.some(o => { return event.origin.endsWith(o) })) {
            throw `Access denied from ${event.origin}`
        }
    }
}

postRobot.on('update', {window: window.parent}, function(event) {
    check_access(event);
    let entity = event.data.entity;
    let storage = _ctx(event.data.context);
    let now = _timestamp();
    if (entity.entityID && !entity.entity_id) {
        entity.entity_id = entity.entityID;
    }
    let id = entity.entity_id.hexEncode();
    let item = get_entity(storage, id);
    if (!is_valid(item, now)) {
        item = { "last_refresh": now, "last_use": now, "entity": entity };
    } else {
        item.last_refresh = now;
        item.last_use = now;
        item.entity = entity;
    }
github buttercup / buttercup-browser-extension / source / tab / messaging.js View on Github external
function startPostMessageListener() {
    postRobot.CONFIG.LOG_LEVEL = "error";
    postRobot.on("bcup-close-dialog", () => {
        hideInputDialog();
        hideSaveDialog();
    });
    postRobot.on("bcup-get-url", () => window.location.href);
    postRobot.on("bcup-open-url", event => {
        const { url } = event.data;
        chrome.runtime.sendMessage({ type: "open-tab", url });
    });
}
github buttercup / buttercup-browser-extension / source / tab / messaging.js View on Github external
function startPostMessageListener() {
    postRobot.CONFIG.LOG_LEVEL = "error";
    postRobot.on("bcup-close-dialog", () => {
        hideInputDialog();
        hideSaveDialog();
    });
    postRobot.on("bcup-get-url", () => window.location.href);
    postRobot.on("bcup-open-url", event => {
        const { url } = event.data;
        chrome.runtime.sendMessage({ type: "open-tab", url });
    });
}
github Bearer / bearer-js / packages / core / src / bearer.ts View on Github external
initSession() {
    if (this.window !== undefined && !document.querySelector(`#${IFRAME_NAME}`)) {
      postRobot.on(Events.SESSION_INITIALIZED, event => {
        this.sessionInitialized(event)
      })
      postRobot.on(Events.AUTHORIZED, this.authorized)
      postRobot.on(Events.REVOKED, this.revoked)

      this.iframe = document.createElement('iframe')
      this.iframe.src = `${this.bearerConfig.authorizationHost}v1/user/initialize`
      this.iframe.id = IFRAME_NAME
      this.iframe.width = '0'
      this.iframe.height = '0'
      this.iframe.frameBorder = '0'
      this.iframe.style.display = 'none'
      document.body.appendChild(this.iframe)
    }
  }
github Bearer / bearer-js / packages / core / src / bearer.ts View on Github external
initSession() {
    if (this.window !== undefined && !document.querySelector(`#${IFRAME_NAME}`)) {
      postRobot.on(Events.SESSION_INITIALIZED, event => {
        this.sessionInitialized(event)
      })
      postRobot.on(Events.AUTHORIZED, this.authorized)
      postRobot.on(Events.REVOKED, this.revoked)

      this.iframe = document.createElement('iframe')
      this.iframe.src = `${this.bearerConfig.authorizationHost}v1/user/initialize`
      this.iframe.id = IFRAME_NAME
      this.iframe.width = '0'
      this.iframe.height = '0'
      this.iframe.frameBorder = '0'
      this.iframe.style.display = 'none'
      document.body.appendChild(this.iframe)
    }
  }
github Bearer / bearer-js / packages / core / src / bearer.ts View on Github external
initSession() {
    if (this.window !== undefined && !document.querySelector(`#${IFRAME_NAME}`)) {
      postRobot.on(Events.SESSION_INITIALIZED, event => {
        this.sessionInitialized(event)
      })
      postRobot.on(Events.AUTHORIZED, this.authorized)
      postRobot.on(Events.REVOKED, this.revoked)

      this.iframe = document.createElement('iframe')
      this.iframe.src = `${this.bearerConfig.authorizationHost}v1/user/initialize`
      this.iframe.id = IFRAME_NAME
      this.iframe.width = '0'
      this.iframe.height = '0'
      this.iframe.frameBorder = '0'
      this.iframe.style.display = 'none'
      document.body.appendChild(this.iframe)
    }
  }
github TheIdentitySelector / thiss-js / src / ps / index.js View on Github external
let storage = _ctx(event.data.context);
    let entity_id = event.data.entity_id;
    if (!entity_id) {
        throw new Error("Unable to find entity_id in request")
    }
    let id = entity_id.hexEncode();
    let item = get_entity(storage, id);
    if (item) {
        let now = _timestamp();
        item.last_use = now;
        storage.set(id, clean_item(item));
    }
    return item;
});

postRobot.on('remove', {window: window.parent}, function(event) {
    check_access(event);
    let storage = _ctx(event.data.context);
    let entity_id = event.data.entity_id;
    if (entity_id === undefined) {
    } else {
        storage.remove(entity_id.hexEncode());
    }
});