[#3054] added core.RealtimeConnectEvent.IdleTimeout field
This commit is contained in:
parent
b1093baef7
commit
06d3e27e03
|
@ -4,6 +4,8 @@
|
||||||
to allow sending non-JSON body with the request ([#3058](https://github.com/pocketbase/pocketbase/discussions/3058)).
|
to allow sending non-JSON body with the request ([#3058](https://github.com/pocketbase/pocketbase/discussions/3058)).
|
||||||
The existing `data` prop will still work, but it will be recommended to use `body` instead (_to send JSON you can use `JSON.stringify(...)` as body value_).
|
The existing `data` prop will still work, but it will be recommended to use `body` instead (_to send JSON you can use `JSON.stringify(...)` as body value_).
|
||||||
|
|
||||||
|
- Added `core.RealtimeConnectEvent.IdleTimeout` field to allow specifying a different realtime idle timeout duration per client basis ([#3054](https://github.com/pocketbase/pocketbase/discussions/3054)).
|
||||||
|
|
||||||
|
|
||||||
## v0.17.1
|
## v0.17.1
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,7 @@ func (api *realtimeApi) connect(c echo.Context) error {
|
||||||
connectEvent := &core.RealtimeConnectEvent{
|
connectEvent := &core.RealtimeConnectEvent{
|
||||||
HttpContext: c,
|
HttpContext: c,
|
||||||
Client: client,
|
Client: client,
|
||||||
|
IdleTimeout: 5 * time.Minute,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnRealtimeConnectRequest().Trigger(connectEvent); err != nil {
|
if err := api.app.OnRealtimeConnectRequest().Trigger(connectEvent); err != nil {
|
||||||
|
@ -103,8 +104,8 @@ func (api *realtimeApi) connect(c echo.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// start an idle timer to keep track of inactive/forgotten connections
|
// start an idle timer to keep track of inactive/forgotten connections
|
||||||
idleDuration := 5 * time.Minute
|
idleTimeout := connectEvent.IdleTimeout
|
||||||
idleTimer := time.NewTimer(idleDuration)
|
idleTimer := time.NewTimer(idleTimeout)
|
||||||
defer idleTimer.Stop()
|
defer idleTimer.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -143,7 +144,7 @@ func (api *realtimeApi) connect(c echo.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
idleTimer.Stop()
|
idleTimer.Stop()
|
||||||
idleTimer.Reset(idleDuration)
|
idleTimer.Reset(idleTimeout)
|
||||||
case <-c.Request().Context().Done():
|
case <-c.Request().Context().Done():
|
||||||
// connection is closed
|
// connection is closed
|
||||||
if api.app.IsDebug() {
|
if api.app.IsDebug() {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/labstack/echo/v5"
|
"github.com/labstack/echo/v5"
|
||||||
"github.com/pocketbase/pocketbase/daos"
|
"github.com/pocketbase/pocketbase/daos"
|
||||||
|
@ -121,6 +122,7 @@ type MailerAdminEvent struct {
|
||||||
type RealtimeConnectEvent struct {
|
type RealtimeConnectEvent struct {
|
||||||
HttpContext echo.Context
|
HttpContext echo.Context
|
||||||
Client subscriptions.Client
|
Client subscriptions.Client
|
||||||
|
IdleTimeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
type RealtimeDisconnectEvent struct {
|
type RealtimeDisconnectEvent struct {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue