summaryrefslogtreecommitdiff
path: root/src/js_bridge.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js_bridge.js')
-rw-r--r--src/js_bridge.js45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/js_bridge.js b/src/js_bridge.js
index a9c8873..46065cb 100644
--- a/src/js_bridge.js
+++ b/src/js_bridge.js
@@ -1,24 +1,31 @@
var s = document.createElement('script');
-var PEER = {};
s.setAttribute('src','https://unpkg.com/peerjs@1.5.2/dist/peerjs.min.js');
document.body.appendChild(s);
function genRanHex(size) {
- return Array.apply(null,Array(size)).map(() => Math.floor(Math.random() * 16).toString(16)).join('');
+ return Array.apply(null,Array(size)).map(function(){
+ Math.floor(Math.random() * 16).toString(16);
+ }).join('');
+
}
-PEER.event_queue = {};
-PEER.peers = {};
-PEER.message_queue = {};
-PEER.create = function(name, options) {
- var peer = new Peer(name, options);
- PEER.peers[name] = peer;
-};
-/*
-PEER["on"] = function(name, e, message) {
- PEER.peers[name].on(e, function(data) {
- PEER.message_queue.push({"message":message, "data":data})
- }
-}
-PEER["connect"] = function(name, id, options) {
- PEER.peers[name].connect(id, options)
-}
-*/
+window.PEER = {
+ event_queue: {},
+ peers: {},
+ message_queue: {},
+ create: function(name, options) {
+ var peer = new Peer(name, options);
+ PEER.peers[name] = peer;
+ },
+ on: function(name, e, message) {
+ PEER.peers[name].on(e, function(data) {
+ PEER.message_queue.push({"message":message, "data":{
+ "call": "on",
+ "peer": name,
+ "e": e,
+ "data": data
+ }});
+ });
+ },
+ connect: function(name, id, options) {
+ PEER.peers[name].connect(id, options);
+ },
+};