Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arpc.js in /extension is out of sync with /examples #52

Closed
neomantra opened this issue Oct 5, 2023 · 3 comments
Closed

arpc.js in /extension is out of sync with /examples #52

neomantra opened this issue Oct 5, 2023 · 3 comments
Labels

Comments

@neomantra
Copy link

I was noting that the JavaScript arpc.js files are out of sync a bit, with the extension folder missing keepalive/ping/pong. Is that intentional?

> find . -name 'arpc.js' | xargs shasum
fb68d9ec55c510ddf9774d582db7be84f7282868  ./extension/jsclient/arpc.js
bf8402a8d060a8df4cf62090f93e03159831dc2e  ./examples/httprpc/arpc.js
bf8402a8d060a8df4cf62090f93e03159831dc2e  ./examples/webchat/arpc.js
bf8402a8d060a8df4cf62090f93e03159831dc2e  ./examples/protocols/websocket/jsclient/arpc.js

> diff ./extension/jsclient/arpc.js ./examples/httprpc/arpc.js

8a9,10
> var _CmdPing = 4;
> var _CmdPong = 5;
81a84,86
>             if (typeof (cb) == 'function') {
>                 cb({ data: null, err: _ErrClosed });
>             }
86a92,94
>             if (typeof (cb) == 'function') {
>                 cb({ data: null, err: _ErrReconnecting });
>             }
91,92d98
<         this.seqNum++;
<         var seq = this.seqNum;
108,142c114
< 
<         var buffer;
<         if (request) {
<             var data = this.codec.Marshal(request);
<             if (data) {
<                 buffer = new Uint8Array(16 + method.length + data.length);
<                 for (var i = 0; i < data.length; i++) {
<                     buffer[16 + method.length + i] = data[i];
<                 }
<             }
<         } else {
<             buffer = new Uint8Array(16 + method.length);
<         }
<         var bodyLen = buffer.length - 16;
<         for (var i = _HeaderIndexBodyLenBegin; i < _HeaderIndexBodyLenEnd; i++) {
<             buffer[i] = (bodyLen >> ((i - _HeaderIndexBodyLenBegin) * 8)) & 0xFF;
<         }
< 
<         buffer[_HeaderIndexCmd] = _CmdRequest & 0xFF;
<         buffer[_HeaderIndexMethodLen] = method.length & 0xFF;
<         for (var i = _HeaderIndexSeqBegin; i < _HeaderIndexSeqBegin + 4; i++) {
<             buffer[i] = (seq >> ((i - _HeaderIndexSeqBegin) * 8)) & 0xFF;
<         }
< 
<         var methodBuffer = new TextEncoder("utf-8").encode(method);
<         for (var i = 0; i < methodBuffer.length; i++) {
<             buffer[16 + i] = methodBuffer[i];
<         }
< 
<         if (!isHttp) {
<             this.ws.send(buffer);
<         } else {
<             this.request(buffer, this._onMessage);
<         }
< 
---
>         this.write(_CmdRequest, method, request, this.seqNum, this._onMessage, isHttp);
156c128,155
<         this.seqNum++;
---
>         this.write(_CmdNotify, method, notify, function () { }, isHttp);
>     }
>     this.ping = function () {
>         if (client.state == _SOCK_STATE_CLOSED) {
>             return _ErrClosed;
>         }
>         if (client.state == _SOCK_STATE_CONNECTING) {
>             return _ErrReconnecting;
>         }
>         client.write(_CmdPing, "", null, function () { });
>     }
>     this.pong = function () {
>         if (client.state == _SOCK_STATE_CLOSED) {
>             return _ErrClosed;
>         }
>         if (client.state == _SOCK_STATE_CONNECTING) {
>             return _ErrReconnecting;
>         }
>         client.write(_CmdPong, "", null, function () { });
>     }
>     this.keepalive = function (timeout) {
>         if (this._keepaliveInited) return;
>         this._keepaliveInited = true;
>         if (!timeout) timeout = 1000 * 30;
>         setInterval(this.ping, timeout);
>     }
> 
>     this.write = function (cmd, method, arg, cb, isHttp) {
158,159c157,158
<         if (notify) {
<             var data = this.codec.Marshal(notify);
---
>         if (arg) {
>             var data = this.codec.Marshal(arg);
168a168
> 
173c173
<         buffer[_HeaderIndexCmd] = _CmdNotify & 0xFF;
---
>         buffer[_HeaderIndexCmd] = cmd & 0xFF;
174a175
>         this.seqNum++;
178d178
< 
183d182
< 
187c186
<             this.request(buffer, function () { });
---
>             this.request(buffer, cb);
246a246,253
>                 switch (cmd) {
>                     case _CmdPing:
>                         client.pong();
>                         return;
>                     case _CmdPong:
>                         return;
>                 }
> 
neomantra added a commit to neomantra/arpc that referenced this issue Oct 5, 2023
@lesismal
Copy link
Owner

lesismal commented Oct 6, 2023

Thank you for your feedback, I've pr more commit:
#54

Copy link

github-actions bot commented Nov 6, 2023

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Nov 6, 2023
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants