3

Thanks for any help in advance!

Anyway, I want my JavaScript application to be able to "connect to" or otherwise "communicate with" IRC.

(I need it to run in browser, so no npmjs-dependent solutions, and yes, I have tried Browserify, but a lot of things seem to be un-Browserify-able, so please don't suggest a Browserfiy-related method, unless you're absolutely sure)

It would seem that it is not easy or maybe not possible to "connect" directly to IRC in JavaScript, so I am comfortable with using other, even if more redundant, methods to communicate, including usage of other languages that can be use in-browser, such as Java, or PHP if possible.

I'm open to any suggestions! Thanks so much!

Smudge
  • 31
  • 4
  • It isn’t possible with browser JavaScript alone, Java applets are long dead, and PHP can’t be used in-browser. Flash could probably do it, but it’d likely be nicer to use some sort of server side. – Ry- Jun 23 '15 at 00:08
  • It should be possible with the `WebSocket` API, but I don't know of any libraries that currently exist to implement the IRC protocol on top of JavaScript websockets. – Patrick Roberts Jun 23 '15 at 00:10
  • @PatrickRoberts it's impossible, you'd need a "raw" TCP socket which all major browsers provide but in privileged mode (extensions) only. – Benjamin Gruenbaum Jun 23 '15 at 00:12
  • [This library uses Node.js TCP sockets](https://github.com/martynsmith/node-irc), so if you're proficient in Node.js you might be able to port this to the [WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket). – Patrick Roberts Jun 23 '15 at 00:12
  • 2
    @PatrickRoberts That won't work. WebSockets are not TCP sockets; they can only used to communicate with WS servers, and even then only under the same origin. –  Jun 23 '15 at 00:13
  • @duskwuff Okay, that makes sense. – Patrick Roberts Jun 23 '15 at 00:14
  • "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow..." – JAAulde Jun 23 '15 at 01:03

2 Answers2

2

It is true that IRC per se can't talk to Websockets directly, but thankfully IRC servers, such as UnrealIRCd, have begun adopting Websockets on their end, so that manual tunneling or mediating is in many cases no longer necessary!

As a proof-of-concept I have written a basic browser-only Javascript IRC client, which connects directly to Websocket-capable IRC servers. Demo

The situation is improving, many years after the original question was asked.

oelna
  • 2,210
  • 3
  • 22
  • 40
1

HTML5 introduced stay-alive connections through the WebSocket protocol, which now (HyBi06, WS version 13) is implemented and accepted by almost any device, and very stable. The problem is that IRC does not have a WebSocket communication protocol.

The solution I've built is to create a WebSocket-server that creates a raw connection to the IRC-server for every client and acts as a mediator. Every client runs an IRC-bot I already had developed, which turns messages from the server into events, which means I had to implement all events I wanted to pass on to the Website.

Don
  • 3,876
  • 10
  • 47
  • 76