Ublock allows you to block websocket requests. eg.
*$websocket
will block all websocket connections. You probably want to operate on a whitelist on a site by site basis. Blocking localhost or 127.0.0.1 isn't reliable because sites can use dns rebinding attacks to bypass your filters.
Ublock origin says it supports ABP filter rules which allow for whitelisting sites which seems like it should allow something approximating:
~site.com$websocket
*,~site.com$websocket
However this seems like it's invalid syntax because switching your example to this opens all websocket use back up tested via https://websocketstest.com/