Your JOIN is missing # from before the channel name. You should also end each message with \r\n per IRC protocol, even though it’s not strictly required when using websockets instead of a raw connection.
I would personally use socket.onopen instead of checking readystate in send, too.
From a code maintainability point of view using socket on a line before you’ve defined it is bad practice, but doesn’t change anything functionally (vars are scoped to the entire function, even code that lies before it)