Skip to content

Commit

Permalink
Cleanup extension metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
arthuro555 committed Dec 25, 2022
1 parent cd3179d commit 0cae1f7
Show file tree
Hide file tree
Showing 7 changed files with 994 additions and 123 deletions.
2 changes: 2 additions & 0 deletions code/adapters/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace THNK {
async prepare(runtimeScene: gdjs.RuntimeScene): Promise<void> {
bc.addEventListener("message", this.boundOnBCMessage);
bc.postMessage({ message: "connect", from: ownID } as MessageTypes);
window.addEventListener("beforeunload", () => this.close());
}

close() {
Expand Down Expand Up @@ -58,6 +59,7 @@ namespace THNK {

async prepare(): Promise<void> {
bc.addEventListener("message", this.boundOnBCMessage);
window.addEventListener("beforeunload", () => this.close());
}

close() {
Expand Down
169 changes: 120 additions & 49 deletions extensions/THNK.json

Large diffs are not rendered by default.

710 changes: 687 additions & 23 deletions extensions/THNK_GeckosClient.json

Large diffs are not rendered by default.

60 changes: 38 additions & 22 deletions extensions/THNK_GeckosServer.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions extensions/THNK_Local.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": "// Load THNK Local Adapter (https://github.com/arthuro555/THNK)\n\"use strict\";\n(() => {\n // code/adapters/local.ts\n if(!window.THNK)window.THNK={};let THNK=window.THNK;\n ((THNK2) => {\n const logger = new gdjs.Logger(\"THNK - Local Testing Adapter\");\n if (!globalThis.BroadcastChannel)\n logger.error(\n \"This browser does not support the local adapter - please try using another adapter! (Prepare for an error)\"\n );\n const bc = new BroadcastChannel(\"thnk-local-server\");\n bc.addEventListener(\n \"messageerror\",\n (e) => logger.error(\"An error occured while sending a message!\", e)\n );\n const ownID = \"\" + Date.now() + Math.random() * 1e3;\n class LocalClientAdapter extends THNK2.ClientAdapter {\n constructor() {\n super(...arguments);\n this.boundOnBCMessage = this.onBCMessage.bind(this);\n }\n onBCMessage({ data }) {\n if (data.message === \"msg-for-client\" && data.for === ownID)\n this.onMessage(data.data);\n }\n async prepare(runtimeScene) {\n bc.addEventListener(\"message\", this.boundOnBCMessage);\n bc.postMessage({ message: \"connect\", from: ownID });\n }\n close() {\n bc.postMessage({ message: \"disconnect\", from: ownID });\n bc.removeEventListener(\"message\", this.boundOnBCMessage);\n }\n doSendMessage(message) {\n bc.postMessage({\n message: \"msg-for-server\",\n data: message,\n from: ownID\n });\n }\n }\n THNK2.LocalClientAdapter = LocalClientAdapter;\n class LocalServerAdapter extends THNK2.ServerAdapter {\n constructor() {\n super(...arguments);\n this.boundOnBCMessage = this.onBCMessage.bind(this);\n }\n onBCMessage({ data }) {\n if (data.message === \"msg-for-server\")\n this.onMessage(data.from, data.data);\n else if (data.message === \"connect\")\n this.onConnection(data.from);\n else if (data.message === \"disconnect\")\n this.onDisconnection(data.from);\n }\n async prepare() {\n bc.addEventListener(\"message\", this.boundOnBCMessage);\n }\n close() {\n bc.removeEventListener(\"message\", this.boundOnBCMessage);\n }\n doSendMessageTo(userID, message) {\n bc.postMessage({\n message: \"msg-for-client\",\n data: message.buffer.slice(\n message.buffer.byteLength - message.byteLength\n ),\n for: userID\n });\n }\n getServerID() {\n return ownID;\n }\n }\n THNK2.LocalServerAdapter = LocalServerAdapter;\n })(THNK || (THNK = {}));\n})();\n",
"inlineCode": "// Load THNK Local Adapter (https://github.com/arthuro555/THNK)\n\"use strict\";\n(() => {\n // code/adapters/local.ts\n if(!window.THNK)window.THNK={};let THNK=window.THNK;\n ((THNK2) => {\n const logger = new gdjs.Logger(\"THNK - Local Testing Adapter\");\n if (!globalThis.BroadcastChannel)\n logger.error(\n \"This browser does not support the local adapter - please try using another adapter! (Prepare for an error)\"\n );\n const bc = new BroadcastChannel(\"thnk-local-server\");\n bc.addEventListener(\n \"messageerror\",\n (e) => logger.error(\"An error occured while sending a message!\", e)\n );\n const ownID = \"\" + Date.now() + Math.random() * 1e3;\n class LocalClientAdapter extends THNK2.ClientAdapter {\n constructor() {\n super(...arguments);\n this.boundOnBCMessage = this.onBCMessage.bind(this);\n }\n onBCMessage({ data }) {\n if (data.message === \"msg-for-client\" && data.for === ownID)\n this.onMessage(data.data);\n }\n async prepare(runtimeScene) {\n bc.addEventListener(\"message\", this.boundOnBCMessage);\n bc.postMessage({ message: \"connect\", from: ownID });\n window.addEventListener(\"beforeunload\", () => this.close());\n }\n close() {\n bc.postMessage({ message: \"disconnect\", from: ownID });\n bc.removeEventListener(\"message\", this.boundOnBCMessage);\n }\n doSendMessage(message) {\n bc.postMessage({\n message: \"msg-for-server\",\n data: message,\n from: ownID\n });\n }\n }\n THNK2.LocalClientAdapter = LocalClientAdapter;\n class LocalServerAdapter extends THNK2.ServerAdapter {\n constructor() {\n super(...arguments);\n this.boundOnBCMessage = this.onBCMessage.bind(this);\n }\n onBCMessage({ data }) {\n if (data.message === \"msg-for-server\")\n this.onMessage(data.from, data.data);\n else if (data.message === \"connect\")\n this.onConnection(data.from);\n else if (data.message === \"disconnect\")\n this.onDisconnection(data.from);\n }\n async prepare() {\n bc.addEventListener(\"message\", this.boundOnBCMessage);\n window.addEventListener(\"beforeunload\", () => this.close());\n }\n close() {\n bc.removeEventListener(\"message\", this.boundOnBCMessage);\n }\n doSendMessageTo(userID, message) {\n bc.postMessage({\n message: \"msg-for-client\",\n data: message.buffer.slice(\n message.buffer.byteLength - message.byteLength\n ),\n for: userID\n });\n }\n getServerID() {\n return ownID;\n }\n }\n THNK2.LocalServerAdapter = LocalServerAdapter;\n })(THNK || (THNK = {}));\n})();\nif (new URL(location).searchParams.get(\"client\")) THNK.client.startClient(runtimeScene, new THNK.LocalClientAdapter());",
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": true
Expand All @@ -50,7 +50,7 @@
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"if (new URL(location).searchParams.get(\"client\"))\r",
" return console.error(\"Cannot start server - prevoew set as client!\");\r",
" return console.error(\"Cannot start server - preview set as client!\");\r",
"\r",
"THNK.server.startServer(\r",
" new THNK.LocalServerAdapter(),\r",
Expand Down
Loading

0 comments on commit 0cae1f7

Please sign in to comment.