port wss code from https://github.com/turnpedallabs/ws