Skip to content

ActionheroWebsocketClient typescript support #1946

Open
@mfvargo

Description

@mfvargo

When developing a websocket client for an actionhero server it would be great to have a typescript implementation that could be imported to give rich typing to developers. In the current situation, you need to add the script import to your layout and then in the code you just make a new client but typescript has no idea what the client is. Also the messages that the client creates do not have any interfaces as well.

Desired solution: new package that would have the interfaces and the primus code.

Users would just

npm i actionhero-web-socket

You would not need to include the javascript anymore. In your front end code you would:

import { ActionheroWebsocketClient, ChatMessage } from 'actionhero-web-socket';

const client = new ActionheroWebsocketClient();
const messages = new Array<ChatMessage>;

I think the ChatMessage might be the existing ChatPubSubMessage but I'm not sure.

My current alternative is to include the javascript in my layout and just use the code without any type information.

Extra thoughts:

I think maybe it might also be possible to have the ActionheroWebsocketClient keep the list of messages and expose them via the client

const message = client.messages.shift();
// message is a ChatMessage

Also, the state of the connection could be kept in the client as well. So as a user of this api I would just need to construct the client, connect it and then process callbacks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions