RubaXa / Wormhole
Wormhole — it's better EventEmitter for communication between tabs with supporting Master/Slave.
Stars: ✭ 393
Programming Languages
javascript
184084 projects - #8 most used programming language
Projects that are alternatives of or similar to Wormhole
Nodefony Starter
Nodefony Starter Node.js Framework
Stars: ✭ 95 (-75.83%)
Mutual labels: websocket, cors
Joynr
A transport protocol agnostic (MQTT, HTTP, WebSockets etc.) Franca IDL based communication framework supporting multiple communication paradigms (RPC, Pub-Sub, broadcast etc.)
Stars: ✭ 124 (-68.45%)
Mutual labels: communication, websocket
Spring Boot Start Current
Spring Boot 脚手架 Mybatis Spring Security JWT 权限 Spring Cache + Redis
Stars: ✭ 246 (-37.4%)
Mutual labels: websocket, cors
Youi
Next generation user interface and application development in Scala and Scala.js for web, mobile, and desktop.
Stars: ✭ 186 (-52.67%)
Mutual labels: communication, websocket
Briefing
Secure direct video group chat
Stars: ✭ 710 (+80.66%)
Mutual labels: communication, websocket
Microwebsrv2
The last Micro Web Server for IoTs (MicroPython) or large servers (CPython), that supports WebSockets, routes, template engine and with really optimized architecture (mem allocations, async I/Os). Ready for ESP32, STM32 on Pyboard, Pycom's chipsets (WiPy, LoPy, ...). Robust, efficient and documented!
Stars: ✭ 295 (-24.94%)
Mutual labels: websocket, cors
Qtox
qTox is a chat, voice, video, and file transfer IM client using the encrypted peer-to-peer Tox protocol.
Stars: ✭ 3,843 (+877.86%)
Mutual labels: communication
Wssip
Application for capturing, modifying and sending custom WebSocket data from client to server and vice versa.
Stars: ✭ 373 (-5.09%)
Mutual labels: websocket
Dokit
基于 Spring Boot2、 Jpa、 Spring Security、JWT、redis、Vue的前后端分离的后台管理系统开发平台, 用户管理、菜单管理、角色管理、字典管理、权限控制的方式为RBAC,操作日志、异常日志、接口限流、项目支持数据权限管理,支持一键生成前后端代码(支持在线预览及打包下载),支持前端菜单动态路由 可一键部署服务器应用,数据库。系统中活跃用户状态监控,监视当前系统CPU、内存、磁盘、堆栈等相关信息,基于Element UI在线表单设计及生成Vue代码。
Stars: ✭ 348 (-11.45%)
Mutual labels: websocket
Kotlin Ktor Exposed Starter
Starter RESTful service with websocket notifications using Kotlin, Ktor and Exposed with H2, HikariCP and FlyWay
Stars: ✭ 343 (-12.72%)
Mutual labels: websocket
Vue Crud X
Vue+Express Cookbook & CRUD Component (with Vite and Web Components)
Stars: ✭ 393 (+0%)
Mutual labels: websocket
Echo
High performance, minimalist Go web framework
Stars: ✭ 21,297 (+5319.08%)
Mutual labels: websocket
Hyperf
🚀 A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.
Stars: ✭ 4,206 (+970.23%)
Mutual labels: websocket
Quickblox Ios Sdk
QuickBlox iOS SDK for messaging and video calling
Stars: ✭ 373 (-5.09%)
Mutual labels: communication
Laravel Swoole
High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
Stars: ✭ 3,726 (+848.09%)
Mutual labels: websocket
Vue Socket.io
😻 Socket.io implementation for Vuejs and Vuex
Stars: ✭ 3,746 (+853.18%)
Mutual labels: websocket
Downloadbot
(Currently) 🤖 A Telegram Bot that can control your Aria2 server, control server files and also upload to OneDrive.
Stars: ✭ 373 (-5.09%)
Mutual labels: websocket
Wormhole
It's better EventEmitter for communication between tabs with supporting Master/Slave.
npm i --save-dev wormhole.js
Features
- One connection on WebSocket for all tabs.
- Support Master/Slave
- Cross-domain communication
- SharedWorker or fallback to localStorage
- IE 8+, Chrome 10+, FireFox 10+, Opera 10+, Safari 6+
- Test coverage (run)
Basic example
import wormhole from 'wormhole.js'; // yes, with ".js", it's not mistake
// All tabs
wormhole().on('coords', (x, y) => {
console.log(x, y);
});
// Some tab
wormhole().emit('coords', [5, 10]);
// Master tab
if (wormhole().master) {
// ..
}
wormhole().on('master', () => {
console.log('Wow!');
});
One connection on WebSocket for all tabs
Module wormhole.js/ws
implements WebSocket-like interface:
https://rubaxa.github.io/wormhole/?ws=y
import WS from 'wormhole.js/ws';
// Create WebScoket (wormhole-socket)
const socket = new WS('ws://echo.websocket.org'); // OR new WS('...', null, hole);
socket.onopen = () => console.log('Connected');
socket.onmessage = ({data}) => console.log('Received:', data);
// Unique event
socket.onmaster = () => {
console.log('Yes, I\'m master!');
};
// Some tab
socket.send({foo: 'bar'})
// All tabs:
// "Received:" {foo: 'bar'}
CORS example
- Create a subdomain, ex.:
http://wormhole.youdomain.com/
; - Copy-paste universal.html and wormhole.js into root;
- Check access
http://wormhole.youdomain.com/universal.html
; - Profit:
// http://foo.youdomain.com/
import {Universal} from 'wormhole.js';
const hole = new Universal('http://wormhole.youdomain.com/universal.html');
hole.on('data', (data) => {
console.log(data);
});
// http://bar.youdomain.com/
import {Universal} from 'wormhole.js';
const hole = new Universal('http://wormhole.youdomain.com/universal.html');
hole.emit('data', 'any data');
Master/slave example
import wormhole from 'wormhole.js';
// All tabs (main.js)
// Define remote command (master)
wormhole()['get-data'] = (function (_cache) {
return function getData(req, callback) {
if (!_cache.hasOwnProperty(req.url)) {
_cache[req.url] = fetch(req.url).then(res => res.json());
}
return _cache[key];
};
})({});
// Get remote data method
function getData(url) {
return new Promise((resolve, reject) => {
// Calling command on master (from slave... or the master, is not important)
wormhole().call(
'get-data', // command
{url}, // arguments
(err, json) => err ? reject(err) : resolve(json) // callback(err, result)
);
});
};
// I'm master!
wormhole().on('master', () => {
// some code
});
// Tab #X
getData('/path/to/api').then((json) => {
// Send ajax request
console.log(result);
});
// Tab #Y
getData('/path/to/api').then((result) => {
// From master cache
console.log(result);
});
Peers
wormhole()
.on('peers', (peers) => {
console.log('ids:', peers); // ['tab-id-1', 'tab-id-2', ..]
})
.on('peers:add', (id) => {
// ..
})
.on('peers:remove', (id) => {
// ..
})
;
Executing the command on master
// Register command (all tabs)
wormhole()['foo'] = (data, next) => {
// bla-bla-bla
next(null, data.reverse()); // or `next('error')`
};
// Calling the command (some tab)
wormhole().call('foo', [1, 2, 3], (err, results) => {
console.log(results); // [3, 2, 1]
})
Modules
- Emitter — Micro event emitter
-
cors — Handy wrapper over
postMessage
. -
store — Safe and a handy wrapper over
localStorage
.
wormhole.Emitter
Micro event emitter.
-
on(type:
String
, fn:Function
):this
-
off(type:
String
, fn:Function
):this
-
emit(type:
String
[, args:*|Array
]):this
import {Emitter} from 'wormhole.js';
const obj = Emitter.apply({}); // or new wormhole.Emitter();
obj.on('foo', () => {
console.log(arguments);
});
obj.emit('foo'); // []
obj.emit('foo', 1); // [1]
obj.emit('foo', [1, 2, 3]); // [1, 2, 3]
wormhole.cors
Handy wrapper over postMessage
.
import {cors} from 'wormhole.js';
// Main-document
cors.on('data', (data) => {
console.log('Received:', data);
});
cors['some:command'] = (value) => value * 2;
// IFrame
cors(parent).send({foo: 'bar'});
// [main-document] "Received:" {foo: 'bar'}
cors(parent).call('some:command', 3, (err, result) => {
console.log('Error:', err, 'Result:', result);
// [iframe] "Error:" null "Result:" 6
});
wormhole.store
Safe and a handy wrapper over localStorage
.
-
get(key:
String
):*
-
set(key:
String
, value:*
) -
remove(key:
String
) -
on(type:
String
, fn:Function
) -
off(type:
String
, fn:Function
)
import {store} from 'wormhole.js';
store.on('change', (key, data) => {
console.log('change -> ', key, data);
});
store.on('change:prop', (key, value) => {
console.log('change:prop -> ', key, value);
});
store.set('foo', {bar: 'baz'});
// change -> foo {bar: 'baz'}
store.set('prop', {qux: 'ok'});
// change -> prop {qux: 'ok'}
// change:prop -> prop {qux: 'ok'}
Utils
String
wormhole.uuid():A universally unique identifier (UUID) is an identifier standard used in software construction, standardized by the Open Software Foundation (OSF) as part of the Distributed Computing Environment (DCE) (c) wiki.
Function
, delay:Number
[, immediate:Boolean
]):Function
wormhole.debounce(fn:Creates and returns a new debounced version of the passed function that will postpone its execution until after wait milliseconds have elapsed since the last time it was invoked.
Development
npm test
-
npm run dev
— run dev watcher npm run build
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].