I’ve had the very same problem and had quite some difficulties figuring out why it’s not working.
You need to have peers connected in order to get what you want.
The annoying thing is that there is in essence no way to do that in the browser. There are projects that allow you to do pubsub communication between browsers (so an ipfs node still won’t see your message).
I assume you want to send a message on any node and expect it to show up on any other node that is subscribed to is. Regardless of desktop or browser, it just needs to show up if you’re subscribed, right? The same with publish.
I only know of one way to get around this.
What i did was:
Run a node on a server.
On that same server, create a sort of API proxy accessible through socket.io. I used node.js on the server. Remember, on the server you have access to the web API of IPFS. You should not open that in it’s entirety to the outside world! In node.js i create a socket.io in which i made a format to do publish and subscribe to ipfs. So if that socket receives a publish from, say, a website then the socket will nicely re-transmit it to the actual IPFS API. The socket itself is also subscribed to a channel of my choosing. If anything arrives on that channel (the node.js instance listens on IPFS pubsub for messages that arrive there) then it re-transmits it to people connected to the socket.
That way i made publish and subscribe accessible on a website.
I have quite a lot of code for it already but i stopped by securing it. Right now, in my code, anyone can publish and subscribe. That on it’s own is fine’ish… but i want some authentication there.
A big downside of this approach is that you now have a 1-on-1 connection between the server and your site that uses the socket connection. Thus you have a single point of failure. But then again, you have the awesome power of IPFS pubsub at your disposal!
Would you be up to help finish this code i have with authentication in it?