Support for gofiber.
itzTheMeow opened this issue · 16 comments
Is there a working example for using this library with gofiber?
I tried this:
import (
"github.com/gofiber/adaptor/v2"
"github.com/zishang520/socket.io/socket"
)
// ...
io := socket.NewServer(nil, nil)
App.Use("/socket.io", adaptor.HTTPHandler(io.ServeHandler(nil)))
and socket.io can not connect to the websocket. (it resorts to using polling)
I have received your question and will give you a relevant answer after follow-up research.
Thanks for your patience, as Fiber is built on top of Fasthttp, Fiber is not compatible with net/http interface, please look forward to follow-up support.
alright, thanks
Maybe need a abstract interface. My project is based Hertz framework. It costs a lot to transfer Hertz context to Standard Net request and writer.
@zishang520 any status on this?
@zishang520 any status on this?
At present, the work based on fasthttp is basically completed, and it is still being debugged. There are still some other work in progress: redis-based adapter.
sounds good!
any status on this?
any status on this?
It may take some time. I am updating engine.io to 6.5.3 and some work has not been completed yet.
another status?
another status?
I'm really sorry. The project is progressing slowly. I've been experiencing some financial stress recently. I have been without income for more than half a year, and my baby is about to be born. For me, it's double pressure. But don't be discouraged, I will continue to complete the development when I have enough time and financial resources. Thank you all for your anticipation and understanding. Finally say sorry again.
That's perfectly fine, take any time you need to sort yourself out. Life comes first.
is there a way we can support this implementation? gofiber is quite popular that it won't be supported
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
New progress: Currently it can only be implemented based on the Websocket transport
interface, and the Polling transport
interface will be abandoned.
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
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)
}