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

feat(websocket): Add generics type to WSContext #3337

Merged
merged 5 commits into from
Sep 8, 2024

Conversation

hayatosc
Copy link
Contributor

@hayatosc hayatosc commented Aug 30, 2024

Fix #3327

Description

In this pull request, you can set ws.raw type as ServerWebSocket on Bun.
So, you can now use Bun own WebSocket API, including Pub/Sub feature!

import { Hono } from 'hono'
import { createBunWebSocket } from 'hono/bun'
import type { ServerWebSocket } from 'bun'

const app = new Hono()

const { upgradeWebSocket, websocket } = createBunWebSocket<ServerWebSocket>()

app.get(
  '/ws',
  upgradeWebSocket((c) => {
    return {
      onMessage(event, ws) {
        ws.raw.subscribe('chat-test') // ws.raw type is unknown now, but we will be able to set ServerWebSocket.
      },
    }
  })
)

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

@hayatosc hayatosc changed the title Add generics type to upgradeWebSocket Add generics type to WSContext Aug 30, 2024
@yusukebe yusukebe changed the title Add generics type to WSContext feat(websocket): Add generics type to WSContext Aug 31, 2024
Copy link

codecov bot commented Aug 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.76%. Comparing base (f9349ec) to head (c3afc37).
Report is 19 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #3337      +/-   ##
==========================================
- Coverage   96.32%   95.76%   -0.56%     
==========================================
  Files         151      151              
  Lines       15385     9166    -6219     
  Branches     2687     2809     +122     
==========================================
- Hits        14819     8778    -6041     
+ Misses        566      388     -178     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

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

LGTM!

@yusukebe
Copy link
Member

Hi @hayatosc !

It looks good. I'm wondering if we should include this feature in the next patch or minor release. After I decide, I'll merge it. Thank you for your contribution!

@yusukebe yusukebe changed the base branch from main to next September 8, 2024 06:46
@yusukebe yusukebe merged commit 6f69bf0 into honojs:next Sep 8, 2024
14 checks passed
@hayatosc hayatosc deleted the types/fix-wscontext-raw-types branch September 8, 2024 08:49
@yusukebe yusukebe mentioned this pull request Sep 11, 2024
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Types: ws.raw type should be ServerWebSocket on bun
2 participants