Skip to content

Commit

Permalink
let talkerapi only handle what it is addressed to
Browse files Browse the repository at this point in the history
  • Loading branch information
steam0r committed Apr 19, 2024
1 parent 306d29e commit e839a58
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions shared/client/src/talkerapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ export default class TalkerAPI extends Events

this._talker.onMessage = (msg) =>
{
if (msg.data.cmd === "callback")
if (msg.data && msg.data.cmd) // other messages are not for talkerapi, i.e. anything that somehow is sent via .postMessage
{
if (this._callbacks[msg.data.cb]) this._callbacks[msg.data.cb](msg.data.error, msg.data.response);
}
else
{
if (!this.hasListenerForEventName(msg.data.cmd))
if (msg.data.cmd === "callback")
{
console.error("TalkerAPI has no listener for", msg.data.cmd);
if (this._callbacks[msg.data.cb]) this._callbacks[msg.data.cb](msg.data.error, msg.data.response);
}
this.emitEvent(msg.data.cmd, msg.data.data, (error, r) =>
else
{
this._talker.send("cables", { "cmd": "callback", "cb": msg.data.cb, "response": r, "error": error });
});
if (!this.hasListenerForEventName(msg.data.cmd))
{
console.error("TalkerAPI has no listener for", msg.data.cmd);
}
this.emitEvent(msg.data.cmd, msg.data.data, (error, r) =>
{
this._talker.send("cables", { "cmd": "callback", "cb": msg.data.cb, "response": r, "error": error });
});
}
}
};
}
Expand Down

0 comments on commit e839a58

Please sign in to comment.