Skip to content

Conversation

@hello-smile6
Copy link
Contributor

@hello-smile6 hello-smile6 commented Apr 25, 2022

Make CloudConnection event-based
https://stackoverflow.com/a/39145058
@webdev03 Could you test this? I'm not sure if it works.

  • Compiles
  • Does not break existing features
  • Able to utilize EventEmitter interface

@webdev03
Copy link
Owner

I will review later today if I can! This looks really nice so I will try compilation as well. Before merging I will try to understand the code though

@hello-smile6
Copy link
Contributor Author

I will review later today if I can! This looks really nice so I will try compilation as well. Before merging I will try to understand the code though

Could you approve running workflows for this PR?

}
});
this.connection.on("message", (e) => {
this.emit("message-may-be-empty", e);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly for debugging.

@webdev03
Copy link
Owner

Hmm:
Error: . prepublish: src/classes/CloudConnection.ts(6,31): error TS4020: 'extends' clause of exported class 'CloudConnection' has or is using private name 'events'.

this.connection.on("message", (e) => {
this.emit("message-may-be-empty", e);
if (!e) return;
this.emit("message", e);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For situations when the raw responses need to be handled. (e.g. additional metadata sent by custom servers)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom servers don't have support right now if I remember correctly. That's something I would add in maybe 2.3.0 (this will go 2.2.0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webdev03: A server might send data about user joins/disconnects in some cases.

@webdev03
Copy link
Owner

Don't worry about linting, I can do it after merging

user: this.session.sessionJSON.user.username,
project_id: this.id.toString()
});
this.emit("connect", null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So command-line applications can show UI for the connection status.

this.connection.on("close", () => {
if (!this.disconnected) this.connect();
if (!this.disconnected) {
this.emit("reconnect", null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For debugging

* Sends a packet through cloud
*/
private send(data) {
this.emit("internal-send", data);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For debugging

* Closes the cloud connection
*/
close() {
this.emit("close", null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's easy to implement UI for connection status.

@webdev03
Copy link
Owner

Can you try just extends EventEmitter?

@hello-smile6
Copy link
Contributor Author

Don't worry about linting, I can do it after merging

Okay

@hello-smile6
Copy link
Contributor Author

Can you try just extends EventEmitter?

Okay

@hello-smile6
Copy link
Contributor Author

Why's it not running workflows?

@webdev03
Copy link
Owner

:/
Error: . prepublish: src/classes/CloudConnection.ts(6,31): error TS4020: 'extends' clause of exported class 'CloudConnection' has or is using private name 'EventEmitter'.

@hello-smile6
Copy link
Contributor Author

:/ Error: . prepublish: src/classes/CloudConnection.ts(6,31): error TS4020: 'extends' clause of exported class 'CloudConnection' has or is using private name 'EventEmitter'.

https://github.com/webdev03/meowclient/runs/6150669995?check_suite_focus=true#step:4:43
Maybe import it?

@hello-smile6
Copy link
Contributor Author

https://www.npmjs.com/package/events
events.eventEmitter WAS right!!!

@hello-smile6
Copy link
Contributor Author

Need it approved to run

@hello-smile6
Copy link
Contributor Author

@webdev03 Need to make a change to tsconfig.json for this

@webdev03
Copy link
Owner

webdev03 commented Apr 25, 2022

I might have to change tsconfig - I will do it later

Sure you can try!

@hello-smile6
Copy link
Contributor Author

I might have to change tsconfig - I will do it later

Builds will fail otherwise, so there'll be no way to know if it runs.

@hello-smile6
Copy link
Contributor Author

@webdev03 Could you approve workflows?


class CloudConnection {
class CloudConnection extends events.EventEmitter {
super();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super in constructor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webdev03 Could you change it?

@webdev03
Copy link
Owner

FYI: neotest is really broken so I am going to switch to a better solution soon

@webdev03
Copy link
Owner

It compiles!!

session: Session;
server?: string;
}) {
super();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it build now?

@hello-smile6
Copy link
Contributor Author

It compiles!!

Will it get merged now?

@webdev03
Copy link
Owner

Just a few more changes, such as me adding a queue system. Now I can merge it. You are a really smart person!

@webdev03 webdev03 merged commit b01bb57 into webdev03:main Apr 25, 2022
@webdev03
Copy link
Owner

Just wondering, do you want to add more emitters? I removed message since it was a bit confusing - set makes more sense.

@hello-smile6
Copy link
Contributor Author

Just wondering, do you want to add more emitters? I removed message since it was a bit confusing - set makes more sense.

I'm not sure. Maybe add one for notifications??? (Then it'd be easy to make a prebuilt QEMU vm that sends emails for notifications)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants