StartWS starts the websocket RPC API server.
(host *string, port *int, allowedOrigins *string, apis *string)
| 164 | |
| 165 | // StartWS starts the websocket RPC API server. |
| 166 | func (api *PrivateAdminAPI) StartWS(host *string, port *int, allowedOrigins *string, apis *string) (bool, error) { |
| 167 | api.node.lock.Lock() |
| 168 | defer api.node.lock.Unlock() |
| 169 | |
| 170 | if api.node.wsHandler != nil { |
| 171 | return false, fmt.Errorf("WebSocket RPC already running on %s", api.node.wsEndpoint) |
| 172 | } |
| 173 | |
| 174 | if host == nil { |
| 175 | h := DefaultWSHost |
| 176 | if api.node.config.WSHost != "" { |
| 177 | h = api.node.config.WSHost |
| 178 | } |
| 179 | host = &h |
| 180 | } |
| 181 | if port == nil { |
| 182 | port = &api.node.config.WSPort |
| 183 | } |
| 184 | |
| 185 | origins := api.node.config.WSOrigins |
| 186 | if allowedOrigins != nil { |
| 187 | origins = nil |
| 188 | for _, origin := range strings.Split(*allowedOrigins, ",") { |
| 189 | origins = append(origins, strings.TrimSpace(origin)) |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | modules := api.node.config.WSModules |
| 194 | if apis != nil { |
| 195 | modules = nil |
| 196 | for _, m := range strings.Split(*apis, ",") { |
| 197 | modules = append(modules, strings.TrimSpace(m)) |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | if err := api.node.startWS(fmt.Sprintf("%s:%d", *host, *port), api.node.rpcAPIs, modules, origins, api.node.config.WSExposeAll); err != nil { |
| 202 | return false, err |
| 203 | } |
| 204 | return true, nil |
| 205 | } |
| 206 | |
| 207 | // StopWS terminates an already running websocket RPC API endpoint. |
| 208 | func (api *PrivateAdminAPI) StopWS() (bool, error) { |