Compare commits

..

No commits in common. "7206624cb50e92c57ec3d178ba1b831d147a7e72" and "875af2773329cbf32d0db49a408e634854eddd00" have entirely different histories.

2 changed files with 15 additions and 30 deletions

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2022 Hammer Technologies LLC Copyright (c) 2022 Lume Web
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -445,7 +445,7 @@ async function createProtomuxChannel(aq: ActiveQuery) {
} }
return (...args: any) => { return (...args: any) => {
args = args.filter( args = args.filter(
(item: any) => item?.constructor.name.toLowerCase() !== "channel" (item: any) => item.constructor.name.toLowerCase() !== "channel"
); );
if (name === "destroy") { if (name === "destroy") {
@ -464,7 +464,14 @@ async function createProtomuxChannel(aq: ActiveQuery) {
}; };
}; };
let channel = mux.createChannel({ aq.setReceiveUpdate?.((data: any) => {
switch (data.action) {
case "open":
channel.open();
}
});
const channel = mux.createChannel({
protocol: data?.protocol, protocol: data?.protocol,
id: data?.id, id: data?.id,
handshake: data?.handshake, handshake: data?.handshake,
@ -478,8 +485,6 @@ async function createProtomuxChannel(aq: ActiveQuery) {
return; return;
} }
channel.open();
const channelId = getChannelId(); const channelId = getChannelId();
connections.get(aq.callerInput.id)?.channels.set(channelId, channel); connections.get(aq.callerInput.id)?.channels.set(channelId, channel);
@ -530,11 +535,9 @@ async function createProtomuxMessage(aq: ActiveQuery) {
}); });
const ret = await defers[action]?.promise; const ret = await defers[action]?.promise;
if (ret[1]) {
if (ret[1].buffer) {
args[0].buffer = b4a.from(ret[1].buffer);
}
if (ret[1]) {
args[0].buffer = Buffer.from(ret[1].buffer);
args[0].start = ret[1].start; args[0].start = ret[1].start;
args[0].end = ret[1].end; args[0].end = ret[1].end;
} }
@ -550,34 +553,18 @@ async function createProtomuxMessage(aq: ActiveQuery) {
return update("encode", args); return update("encode", args);
}, },
async decode(...args: any) { async decode(...args: any) {
return update("decode", args); return update("encode", args);
}, },
}; };
}; };
aq.setReceiveUpdate?.((data) => { aq.setReceiveUpdate?.((data) => {
if (data.action === "send") { defers[data.action]?.resolve(data.args[0]);
message.send(...data.args);
}
defers[data.action]?.resolve(data.args);
}); });
if (data.onmessage) {
data.onmessage = (...args: any) => {
args = args.filter(
(item: any) => item?.constructor.name.toLowerCase() !== "channel"
);
aq.sendUpdate({
action: "onmessage",
args,
});
};
}
const message = channel.addMessage({ const message = channel.addMessage({
encoding: handleEncoding(data.encoding ?? false), encoding: handleEncoding(data.encoding ?? false),
onmessage: data.onmessage ?? noop, onmessage: data.encoding ?? undefined,
}); });
aq.sendUpdate({ aq.sendUpdate({
@ -604,5 +591,3 @@ function getSwarmToSwarmId(swarm: any) {
return false; return false;
} }
function noop() {}