forked from decentraland/kernel-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: incoming, outgoing, running working
- Loading branch information
Showing
13 changed files
with
348 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,47 @@ | ||
import { tapFunction } from '../../jslibs/tapFunction' | ||
|
||
declare var window: any | ||
|
||
function tryInjectIn() { | ||
try { | ||
if (typeof window === undefined) { | ||
console.log('ℹ️ tried to inject into undefined window :/') | ||
} | ||
if (window.browserInterface && !window.__browserSendMessage) { | ||
console.log('ℹ️ browser interface intervened') | ||
var browserBackup = window.browserInterface | ||
var backup = window.browserInterface.onMessage | ||
Object.defineProperty(window, 'browserInterface', { | ||
get: () => browserBackup, | ||
set: (newBrowser) => { | ||
console.log('ℹ️ browser interface reinsert') | ||
browserBackup = newBrowser | ||
backup = newBrowser.onMessage | ||
newBrowser.onMessage = tapOnMessage | ||
}, | ||
}) | ||
function tapOnMessage(a, b, c, d) { | ||
window.postMessage({ | ||
name: 'dcl-explorer-incoming', | ||
source: 'dcl-debugger', | ||
payload: { | ||
name: a, | ||
key: b, | ||
}, | ||
}) | ||
backup.apply(backup, [a, b, c, d]) | ||
} | ||
} else if (window.browserInterface) { | ||
console.log('ℹ️ browser interface inject called twice') | ||
} else { | ||
console.log('ℹ️ browser interface not found yet') | ||
setTimeout(tryInjectIn, 1000) | ||
} | ||
} catch (e) { | ||
console.log('🥂', e) | ||
} | ||
} | ||
|
||
export function setup(connection: any, tap: Function) { | ||
tapFunction( | ||
connection, | ||
'incoming', | ||
tap, | ||
` | ||
function tryInject() { | ||
if (typeof window === undefined) { | ||
console.log("ℹ️ tried to inject into undefined window :/"); | ||
} | ||
if (window.browserInterface && !window.__browserSendMessage) { | ||
console.log("ℹ️ browser interface intervened"); | ||
const backup = window.browserInterface.OnMessage; | ||
window.browserInterface.OnMessage = function(a, b, c, d) { | ||
console.log("ℹ️ ---", a, b) | ||
try { | ||
window.postMessage({ | ||
name: 'dcl-explorer-incoming', | ||
source: 'dcl-debugger', | ||
payload: { | ||
name: a | ||
key: b | ||
} | ||
}) | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
backup.apply(window.browserInterface, [a, b, c, d]) | ||
} | ||
} else if (window.browserInterface) { | ||
console.log("ℹ️ browser interface inject called twice"); | ||
} else { | ||
console.log("ℹ️ browser interface not found yet"); | ||
setTimeout(tryInject, 1000) | ||
} | ||
} | ||
console.log('🥂') | ||
tryInject() | ||
` | ||
) | ||
tapFunction(connection, 'incoming', tap, `${tryInjectIn.toString()};tryInjectIn()`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
import { tapFunction } from '../../jslibs/tapFunction' | ||
|
||
declare var window: any | ||
|
||
function tryInjectOut() { | ||
try { | ||
if (typeof window === undefined) { | ||
console.log('ℹ️ unity tried to inject into undefined window :/') | ||
} | ||
if (window.unityInterface && window.unityInterface.SendGenericMessage) { | ||
console.log('ℹ️ unity interface intervened') | ||
for (let triggerSend in window.unityInterface) { | ||
if (window.unityInterface.hasOwnProperty(triggerSend) && triggerSend !== 'debug') { | ||
const backup = window.unityInterface[triggerSend] | ||
window.unityInterface[triggerSend] = function (a) { | ||
console.log('ℹ️ unity interface outgoing', a) | ||
try { | ||
backup.apply(window.unityInterface, arguments) | ||
window.postMessage( | ||
{ | ||
name: 'dcl-explorer-outgoing', | ||
source: 'dcl-debugger', | ||
payload: { | ||
name: triggerSend, | ||
value: a, | ||
}, | ||
}, | ||
'*' | ||
) | ||
} catch (e) { | ||
console.log('🥂', e.stack) | ||
} | ||
} | ||
} | ||
} | ||
} else if (window.unityInterface) { | ||
console.log('ℹ️ unity interface exists -- no SendMessage though') | ||
setTimeout(tryInjectOut, 1000) | ||
} else { | ||
console.log('ℹ️ unity interface not found yet') | ||
setTimeout(tryInjectOut, 1000) | ||
} | ||
} catch (e) { | ||
console.log('ℹ️ unity intercept problem:', e) | ||
} | ||
} | ||
export function setup(connection: any, tap: Function) { | ||
tapFunction( | ||
connection, | ||
'outgoing', | ||
tap, | ||
`function tryInject() { | ||
if (typeof window === undefined) { | ||
console.log("ℹ️ tried to inject into undefined window :/"); | ||
} | ||
if (window.unityInterface && window.unityInterface.SendGenericMessage) { | ||
console.log("ℹ️ unity interface intervened"); | ||
for (let triggerSend in window.unityInterface) { | ||
if (window.unityInterface.hasOwnProperty(triggerSend) && triggerSend !== 'debug') { | ||
const backup = window.unityInterface[triggerSend] | ||
window.unityInterface[triggerSend] = function(a, b, c, d, e) { | ||
if (b || c || d || e) { | ||
console.log('ℹ️ unexpected extra argument') | ||
} | ||
backup.apply(window.unityInterface, arguments) | ||
try { | ||
window.postMessage({ | ||
name: 'dcl-explorer-outgoing', | ||
source: 'dcl-debugger', | ||
payload: { | ||
name: triggerSend, | ||
value: a, | ||
extra: [b, c, d, e] | ||
} | ||
}, '*') | ||
} catch (e) { | ||
console.log("ℹ️ unity intercept problem:", triggerSend, e, arguments); | ||
} | ||
} | ||
} | ||
} | ||
} else if (window.unityInterface) { | ||
console.log("ℹ️ unity interface exists -- no SendMessage though"); | ||
setTimeout(tryInject, 1000) | ||
} else { | ||
console.log("ℹ️ unity interface not found yet"); | ||
setTimeout(tryInject, 1000) | ||
} | ||
} | ||
tryInject() | ||
` | ||
) | ||
tapFunction(connection, 'outgoing', tap, `${tryInjectOut.toString()};tryInjectOut();`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.