From 726876d42270f8974fd495be91127ea7585472ff Mon Sep 17 00:00:00 2001 From: Alexander M Pickering Date: Sun, 22 Dec 2024 22:17:44 -0600 Subject: Get things working --- src/js_bridge.js | 45 ++++++++++++++++++++++++++------------------- src/main.lua | 5 +++-- 2 files changed, 29 insertions(+), 21 deletions(-) (limited to 'src') 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); + }, +}; diff --git a/src/main.lua b/src/main.lua index 176cddc..8c8461a 100644 --- a/src/main.lua +++ b/src/main.lua @@ -4,11 +4,12 @@ print("Hello, world!") am.eval_js("console.log('Hello, js!')") local win = am.window{ - title = "Hi", + title = "ggj25", width = 1280, height = 720, clear_color = vec4(0.8, 0.8, 0.3, 1) } print("about to pcall") -local a,b = pcall(am.eval_js, require("js_bridge")) +am.eval_js(require("js_bridge")) +--local a,b = pcall(am.eval_js, require("js_bridge")) print("done with pcall", a,b) -- cgit v1.2.3-70-g09d2