Giter Club home page Giter Club logo

rmi.js's Introduction

rmi.js

通用的远程方法调库,支持 Node 及 Browser。

Dependence

  • promise
    rmi.js 依赖 promise 实现,请确保使用环境已支持 promise。

Quick Start

  1. index.html

在主页面里添加一个 <iframe>,设置其 id(用作通信ID)

<iframe id="iframe-page" src="iframe.html">
<script src="rmi.js/rmi.js"></script>
<script src="rmi.js/MainframeBridge.js"></script>
<script>
var server = rmi.create('mainframe', {
  // 添加 api
  'message': function (msg) {
    console.log('Receive message: ', msg);
    return 'response';
  }
});
server.pipe(new MainframeBridge());
</script>
  1. iframe.html
<script src="rmi.js/rmi.js"></script>
<script src="rmi.js/IframeBridge.js"></script>
<script>
var client = rmi.create('iframe-page');
client.pipe(new IframeBridge());

// 调用 index.html 的 api
client.invoke('mainframe', 'message', 'hello').then(function (res) {
  console.log('Receive from mainframe: ', res);
});
</script>

Demo

rmi.js's People

Contributors

duoani avatar

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.