kataras / neffos

A modern, fast and scalable websocket framework with elegant API written in Go
http://bit.ly/neffos-wiki
MIT License
572 stars 47 forks source link

Hello kataras, how does neffos send messages from one websocket server to another, just like the code #48

Closed ezewu closed 4 years ago

ezewu commented 4 years ago
    app := iris.Default()

    event := neffos.Namespaces{
        "web": neffos.Events{
            neffos.OnNamespaceConnected: func(nsConn *neffos.NSConn, msg neffos.Message) error {
                log.Printf("connected to namespace: %s", msg.Namespace)
                return nil
            },
            neffos.OnNamespaceDisconnect: func(nsConn *neffos.NSConn, msg neffos.Message) error {
                log.Printf("disconnected from namespace: %s", msg.Namespace)
                return nil
            },
            "msg": func(nsConn *neffos.NSConn, msg neffos.Message) error {
                return nil
            },
        },
    }

    nativeEvents := neffos.Events{
        neffos.OnNativeMessage: func(c *neffos.NSConn, msg neffos.Message) error {
            log.Printf("Got: %s", string(msg.Body))
            //  ???  to  namespaces   web   msg
                       // Send a message from here to the web namespace msg event
            return nil
        },
    }

    ws := neffos.New(gorilla.Upgrader(gorillaWs.Upgrader{CheckOrigin: func(*http.Request) bool { return true }}), event)

    nativeWs := neffos.New(gorilla.Upgrader(gorillaWs.Upgrader{CheckOrigin: func(*http.Request) bool { return true }}), nativeEvents)

    app.Get("/websocket", websocket.Handler(ws))

    app.Get("/websocket-two", websocket.Handler(nativeWs))