Compare commits
No commits in common. "7206624cb50e92c57ec3d178ba1b831d147a7e72" and "875af2773329cbf32d0db49a408e634854eddd00" have entirely different histories.
7206624cb5
...
875af27733
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
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
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
43
src/index.ts
43
src/index.ts
|
@ -445,7 +445,7 @@ async function createProtomuxChannel(aq: ActiveQuery) {
|
|||
}
|
||||
return (...args: any) => {
|
||||
args = args.filter(
|
||||
(item: any) => item?.constructor.name.toLowerCase() !== "channel"
|
||||
(item: any) => item.constructor.name.toLowerCase() !== "channel"
|
||||
);
|
||||
|
||||
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,
|
||||
id: data?.id,
|
||||
handshake: data?.handshake,
|
||||
|
@ -478,8 +485,6 @@ async function createProtomuxChannel(aq: ActiveQuery) {
|
|||
return;
|
||||
}
|
||||
|
||||
channel.open();
|
||||
|
||||
const channelId = getChannelId();
|
||||
|
||||
connections.get(aq.callerInput.id)?.channels.set(channelId, channel);
|
||||
|
@ -530,11 +535,9 @@ async function createProtomuxMessage(aq: ActiveQuery) {
|
|||
});
|
||||
|
||||
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].end = ret[1].end;
|
||||
}
|
||||
|
@ -550,34 +553,18 @@ async function createProtomuxMessage(aq: ActiveQuery) {
|
|||
return update("encode", args);
|
||||
},
|
||||
async decode(...args: any) {
|
||||
return update("decode", args);
|
||||
return update("encode", args);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
aq.setReceiveUpdate?.((data) => {
|
||||
if (data.action === "send") {
|
||||
message.send(...data.args);
|
||||
}
|
||||
|
||||
defers[data.action]?.resolve(data.args);
|
||||
defers[data.action]?.resolve(data.args[0]);
|
||||
});
|
||||
|
||||
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({
|
||||
encoding: handleEncoding(data.encoding ?? false),
|
||||
onmessage: data.onmessage ?? noop,
|
||||
onmessage: data.encoding ?? undefined,
|
||||
});
|
||||
|
||||
aq.sendUpdate({
|
||||
|
@ -604,5 +591,3 @@ function getSwarmToSwarmId(swarm: any) {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
|
Loading…
Reference in New Issue