Compare commits
4 Commits
875af27733
...
7206624cb5
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | 7206624cb5 | |
Derrick Hammer | 64ec4bb91c | |
Derrick Hammer | 4712b50447 | |
Derrick Hammer | dc806ba98e |
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2022 Lume Web
|
Copyright (c) 2022 Hammer Technologies LLC
|
||||||
|
|
||||||
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
|
||||||
|
|
43
src/index.ts
43
src/index.ts
|
@ -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,14 +464,7 @@ async function createProtomuxChannel(aq: ActiveQuery) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
aq.setReceiveUpdate?.((data: any) => {
|
let channel = mux.createChannel({
|
||||||
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,
|
||||||
|
@ -485,6 +478,8 @@ 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);
|
||||||
|
@ -535,9 +530,11 @@ async function createProtomuxMessage(aq: ActiveQuery) {
|
||||||
});
|
});
|
||||||
|
|
||||||
const ret = await defers[action]?.promise;
|
const ret = await defers[action]?.promise;
|
||||||
|
|
||||||
if (ret[1]) {
|
if (ret[1]) {
|
||||||
args[0].buffer = Buffer.from(ret[1].buffer);
|
if (ret[1].buffer) {
|
||||||
|
args[0].buffer = b4a.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;
|
||||||
}
|
}
|
||||||
|
@ -553,18 +550,34 @@ async function createProtomuxMessage(aq: ActiveQuery) {
|
||||||
return update("encode", args);
|
return update("encode", args);
|
||||||
},
|
},
|
||||||
async decode(...args: any) {
|
async decode(...args: any) {
|
||||||
return update("encode", args);
|
return update("decode", args);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
aq.setReceiveUpdate?.((data) => {
|
aq.setReceiveUpdate?.((data) => {
|
||||||
defers[data.action]?.resolve(data.args[0]);
|
if (data.action === "send") {
|
||||||
|
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.encoding ?? undefined,
|
onmessage: data.onmessage ?? noop,
|
||||||
});
|
});
|
||||||
|
|
||||||
aq.sendUpdate({
|
aq.sendUpdate({
|
||||||
|
@ -591,3 +604,5 @@ function getSwarmToSwarmId(swarm: any) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function noop() {}
|
||||||
|
|
Loading…
Reference in New Issue