go-socket.io icon indicating copy to clipboard operation
go-socket.io copied to clipboard

Raw proposal for go-socket.io v2

Open sshaplygin opened this issue 3 years ago • 17 comments

Is your feature request related to a problem? Please describe. Current libs version doesn't supported socket.io v2

It is not completed proposal version. I suggest some changes. At the future this document will be edit

API:

  • Change create new server object

    Current version

    server := socketio.NewServer(nil)
    

    New version client code

    server := socketio.New()
    

    inner code

    // New create go-socket.io server instance
    func New(opts ...Options) *Server {
       ...
    }
    
  • Hide server.Serve() and server.Close() method

    Current version

    go server.Serve()
    defer server.Close()
    

    New version

    //empty
    
  • Change adapter interface

    Current version

    ok, err := server.Adapter(&socketio.RedisAdapterOptions
    if err != nil {
    log.Println("error:", err)
    return
    
    

    New version client code

    err := server.Adapter()
    if err != nil {
    log.Println("error:", err)
    return
    
    

    inner code

    func (s *Server) Adapter(opts ...AdapterOptions) (error) {
        ...
    }
    

Inner changes:

  • Add level mode for full server logs

sshaplygin avatar May 04 '21 21:05 sshaplygin

  • NewServer()

As I still want to have client code, NewServer() is more clear that it returns a server, and NewClient() returns a client.

  • Serve() and Close()

Serve() gives a preparing period before a server working.

s := gio.NewServer()
// Prepare before the server working
go s.Serve()

Another we could keep that function, and make new creators like LaunchServer() which calls Serve() before returning.

I also hope to keep Close() to have a graceful way to quit a server. If someone wants a server running forever, they could ignore calling this function.

  • Adaptor

I have more thoughts about the adaptor. I hope to support middleware to let adaptor hook messages, and no need to limit adaptor as Redis or other queue implementation.

googollee avatar May 05 '21 07:05 googollee

I agree with @googollee here. I prefer to have the option to close a connection and choose to prepare the server, than to hide it inside the library. It's a bit more verbose but in this case I'd say it's a good thing

erkie avatar May 05 '21 09:05 erkie

I think it's possible to remove Serve() function, by redesign engine.io. I'd like to do that in the new version and to see if it's possible to down-merge the new version to the old one. (If API doesn't change too much.)

googollee avatar May 05 '21 20:05 googollee

If API doesn't change too much.

Why not? It is good changelog for new version ))

sshaplygin avatar May 05 '21 21:05 sshaplygin

In this implementation run go-socket,io server without Server() and Close() method

sshaplygin avatar May 05 '21 21:05 sshaplygin

Another we could keep that function, and make new creators like LaunchServer() which calls Serve() before returning.

I also hope to keep Close() to have a graceful way to quit a server. If someone wants a server running forever, they could ignore calling this function.

It is good decision by my opinion.

sshaplygin avatar May 05 '21 21:05 sshaplygin

Currently engine.io wraps a connection as a sock and that's why socket.io needs a Serve() to start a goroutine to do the "listen" thing.

As it requires changing the design of engine.io, I hope to remove Serve() and Close() in the next version. Also, I don't think breaking API in this version is good for users.

googollee avatar May 06 '21 20:05 googollee

Why not?

sshaplygin avatar May 09 '21 23:05 sshaplygin

I suggest add debug mode into socket.io and egnine.io level. What are you thins about this idea?

sshaplygin avatar May 09 '21 23:05 sshaplygin

For the engineio design in v3-dev, as it provides hooks for all kind of messages, I tend to not add log in engineio.

No idea for socketio new design yet.

googollee avatar May 10 '21 19:05 googollee

I suggest update new major version in socketio with changes cleaner public API. i think it changes is worthy new major version. I think, current API does not implement full functionality original API by js version socketio

sshaplygin avatar May 13 '21 22:05 sshaplygin

Hey, @ralfbawg! If you havta some ideas by public API or some deep things realisation in new second major version, please, tell to us.

sshaplygin avatar May 13 '21 22:05 sshaplygin

Does this mean the corresponding server version is only 1.x ? here

Cinux-Chosan avatar May 24 '21 14:05 Cinux-Chosan

Current version of socket.io is 4.4.1. Does this library works only with 1.x which is 6 years old?

Mistic92 avatar Mar 01 '22 16:03 Mistic92

@Mistic92 yes, this project needs help

erkie avatar Mar 01 '22 16:03 erkie

@erkie How can i contribute? I would love to contribute

sailingwithsandeep avatar Jan 06 '23 08:01 sailingwithsandeep

There is a telegram channel, and there are a bunch of issues here in github. Just pick one and get going!

erkie avatar Jan 06 '23 10:01 erkie