StartWSEndpoint starts a websocket endpoint
(endpoint string, apis []API, modules []string, wsOrigins []string, exposeAll bool)
| 53 | |
| 54 | // StartWSEndpoint starts a websocket endpoint |
| 55 | func StartWSEndpoint(endpoint string, apis []API, modules []string, wsOrigins []string, exposeAll bool) (net.Listener, *Server, error) { |
| 56 | |
| 57 | // Generate the whitelist based on the allowed modules |
| 58 | whitelist := make(map[string]bool) |
| 59 | for _, module := range modules { |
| 60 | whitelist[module] = true |
| 61 | } |
| 62 | // Register all the APIs exposed by the services |
| 63 | handler := NewServer() |
| 64 | for _, api := range apis { |
| 65 | if exposeAll || whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) { |
| 66 | if err := handler.RegisterName(api.Namespace, api.Service); err != nil { |
| 67 | return nil, nil, err |
| 68 | } |
| 69 | log.Debug("WebSocket registered", "service", api.Service, "namespace", api.Namespace) |
| 70 | } |
| 71 | } |
| 72 | // All APIs registered, start the HTTP listener |
| 73 | var ( |
| 74 | listener net.Listener |
| 75 | err error |
| 76 | ) |
| 77 | if listener, err = net.Listen("tcp", endpoint); err != nil { |
| 78 | return nil, nil, err |
| 79 | } |
| 80 | go NewWSServer(wsOrigins, handler).Serve(listener) |
| 81 | return listener, handler, err |
| 82 | |
| 83 | } |
| 84 | |
| 85 | // StartIPCEndpoint starts an IPC endpoint. |
| 86 | func StartIPCEndpoint(ipcEndpoint string, apis []API) (net.Listener, *Server, error) { |
nothing calls this directly
no test coverage detected