Skip to content

Commit

Permalink
Update client.js
Browse files Browse the repository at this point in the history
  • Loading branch information
tshemsedinov authored Feb 12, 2024
1 parent 2ce68a7 commit f8456ca
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,30 +162,8 @@ class Metacom extends EventEmitter {
}
}

httpCall(iname, ver) {
return (methodName) =>
(args = {}) => {
const callId = ++this.callId;
const interfaceName = ver ? `${iname}.${ver}` : iname;
const target = interfaceName + '/' + methodName;
const packet = { call: callId, [target]: args };
const dest = new URL(this.url);
const protocol = dest.protocol.endsWith('s') ? 'https' : 'http';
const url = `${protocol}://${dest.host}/api`;
return fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(packet),
}).then((json) => {
const packet = JSON.parse(json);
if (packet.error) throw new MetacomError(packet.error);
return packet.result;
});
};
}

socketCall(iname, ver) {
return (methodName) =>
scaffold(unit, ver) {
return (method) =>
async (args = {}) => {
const id = ++this.callId;
const unitName = unit + (ver ? '.' + ver : '');
Expand Down

0 comments on commit f8456ca

Please sign in to comment.