fregante/GhostText

Reuse HTTP port for WebSocket

Open

#272 opened on Mar 19, 2023

 (1 comment) (0 reactions) (0 assignees)JavaScript (133 forks)github user discovery
enhancementhelp wantedsublime-text

Repository metrics

Stars
 (3,611 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Findings:

  • There's no need to create a new WebSocket server for every connection
  • WebSocket servers can live on the same connection as HTTP servers

Changes suggested:

  • Have the HTTP server return a static response: {ProtocolVersion: 1, WebSocketPort: 4001} (the port is still user-configurable)
  • Move the connection logic behind the WebSocket instead of the HTTP server, because in the future the browser extension will be able to skip the HTTP request

This change is backwards-compatible in editor extensions, it can already be seen in the new VS Code extension: https://github.com/fregante/GhostText-for-VSCode/blob/17a6d24f066aef98c2561b8690592c08e5c8c6ff/source/extension.ts#L120-L122

I think the ACME plugin has also been doing this for years: https://github.com/fhs/Ghost/blob/aaff3cd0ec26f69a7f6bc59e8a419fafa5d7aa6d/main.go#L80

Contributor guide