Do you mind looking into Fiber adaptor for net/http interface to make this library work with fiber applications? #65
Replies: 6 comments 1 reply
-
This is part of the plan and will be a refactored branch. |
Beta Was this translation helpful? Give feedback.
-
that would be much appreciated @zishang520 as this would allow me serve both rest and websocket on the same port |
Beta Was this translation helpful? Give feedback.
-
Thank you for your support. I will try to prioritize the implementation of this plan in the near future. After all, the plan has been on hold for some time. I am really sorry. |
Beta Was this translation helpful? Give feedback.
-
Sorry, due to technical issues, I cannot solve this problem: valyala/fasthttp#965. Currently, this requirement will be updated after fasthttp has a next step plan. Currently, the submitted engine.io-server-go-fasthttp project and socket.io-server-go-fasthttp project cannot be used normally |
Beta Was this translation helpful? Give feedback.
-
New research finds that it is now available, However, I also made a fasthttp related adaptation, but it only supports websocket: socket.io-server-go-fasthttp |
Beta Was this translation helpful? Give feedback.
-
Fasthttp has been updated not long ago (valyala/fasthttp@9c12719), and it was found to work properly in the test case: package main
import (
"os"
"os/signal"
"syscall"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/adaptor"
"github.com/zishang520/engine.io/v2/log"
"github.com/zishang520/engine.io/v2/types"
"github.com/zishang520/socket.io/v2/socket"
)
func main() {
log.DEBUG = true
c := socket.DefaultServerOptions()
c.SetServeClient(true)
// c.SetConnectionStateRecovery(&socket.ConnectionStateRecovery{})
// c.SetAllowEIO3(true)
c.SetPingInterval(300 * time.Millisecond)
c.SetPingTimeout(200 * time.Millisecond)
c.SetMaxHttpBufferSize(1000000)
c.SetConnectTimeout(1000 * time.Millisecond)
c.SetCors(&types.Cors{
Origin: "*",
Credentials: true,
})
socketio := socket.NewServer(nil, nil)
socketio.On("connection", func(clients ...interface{}) {
client := clients[0].(*socket.Socket)
client.On("message", func(args ...interface{}) {
client.Emit("message-back", args...)
})
client.Emit("auth", client.Handshake().Auth)
client.On("message-with-ack", func(args ...interface{}) {
ack := args[len(args)-1].(func([]any, error))
ack(args[:len(args)-1], nil)
})
})
socketio.Of("/custom", nil).On("connection", func(clients ...interface{}) {
client := clients[0].(*socket.Socket)
client.Emit("auth", client.Handshake().Auth)
})
app := fiber.New()
// app.Put("/socket.io", adaptor.HTTPHandler(socketio.ServeHandler(c))) // test
app.Get("/socket.io", adaptor.HTTPHandler(socketio.ServeHandler(c)))
app.Post("/socket.io", adaptor.HTTPHandler(socketio.ServeHandler(c)))
go app.Listen(":3000")
exit := make(chan struct{})
SignalC := make(chan os.Signal)
signal.Notify(SignalC, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
for s := range SignalC {
switch s {
case syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT:
close(exit)
return
}
}
}()
<-exit
socketio.Close(nil)
os.Exit(0)
} |
Beta Was this translation helpful? Give feedback.
-
here's the link: https://docs.gofiber.io/api/middleware/adaptor/
`go
package main
import (
"fmt"
"os"
)
type Message struct {
Name string
json:"name"
Message string
json:"message"
}
func main() {
app := fiber.New()
var opts *socket.ServerOptions = socket.DefaultServerOptions()
var _ = &socket.ServerOptions{
// cors: {
// origin: "http://localhost:8100",
// methods: ["GET", "POST"],
// credentials: true
// },
// transports: ['websocket', 'polling'],
// allowEIO3: true
`
printing opts gave me nil all through...
&{{ 0xc0001703f0 } { } }
Beta Was this translation helpful? Give feedback.
All reactions