Skip to content

v-hono/v-hono-realtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hono_realtime

Real-time communication (WebSocket, SSE) for v-hono-core framework.

Features

  • RFC 6455 compliant WebSocket support
  • Server-Sent Events (SSE)
  • Streaming responses
  • Event-based WebSocket API
  • Connection lifecycle management

Installation

v install --git https://github.com/v-hono/v-hono-core
v install --git https://github.com/v-hono/v-hono-realtime

Usage

WebSocket

import hono
import hono_realtime

fn main() {
    mut app := hono.Hono.new()

    app.get('/ws', hono_realtime.upgrade_websocket(fn (c hono.Context) hono_realtime.WSEvents {
        return hono_realtime.WSEvents{
            on_open: fn (mut ws hono_realtime.WSContext) {
                ws.send('Welcome!') or {}
            }
            on_message: fn (event hono_realtime.WSMessageEvent, mut ws hono_realtime.WSContext) {
                ws.send('Echo: ${event.data}') or {}
            }
        }
    }))

    app.listen(':3000')
}

Server-Sent Events

import hono
import hono_realtime

fn main() {
    mut app := hono.Hono.new()

    app.get('/sse', fn (mut c hono.Context) http.Response {
        return hono_realtime.c_stream_sse(mut c, fn (mut stream hono_realtime.StreamContext) ! {
            for i in 0 .. 10 {
                stream.write_sse(hono_realtime.SSEEvent{
                    data: 'Message ${i}'
                    event: 'update'
                })!
                stream.sleep(1000)
            }
        })
    })

    app.listen(':3000')
}

Dependencies

  • hono - Core framework

License

MIT

About

Real-time communication support for v-hono, including WebSockets and SSE.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors