Documentation icon indicating copy to clipboard operation
Documentation copied to clipboard

Documentation of Websocket API

Open anoadragon453 opened this issue 7 years ago • 6 comments

Not entirely sure if this is a large or small amount of work, but if I'm not mistaken, it should be possible to control ZeroNet's python daemon by speaking Websocket to it from places outside of the browser? Such as a C++ websockets library?

If so, some documentations of commands accepted by the Websockets server would be appreciated. I imagine they're very similar to those in the ZeroFrame API, but some guidance on the formatting for the actual Websocket request would most definitely be appreciated!

anoadragon453 avatar Nov 16 '18 10:11 anoadragon453

Yes, it's totally possible. The commands are the same as ZeroFrame API. Here is an example, standalone client:

https://github.com/HelloZeroNet/ZeroNet/issues/1137#issuecomment-337019878

HelloZeroNet avatar Nov 16 '18 15:11 HelloZeroNet

Very cool, thanks! I'll make a note about it in the docs somewhere.

This means we can make libraries for third-party programs to store data on ZeroNet, and then have that data be readable in a nice UI in the browser!

anoadragon453 avatar Nov 16 '18 15:11 anoadragon453

~~Is it possible to retrieve a cert and change user to that cert entirely over the WebSocket API?~~

~~Edit: Would it possibly have to be a clearnet request for ZeroID?~~

Yes, it is!

anoadragon453 avatar Nov 23 '18 16:11 anoadragon453

Note: Document that IP's are accepted in v>XXX.

anoadragon453 avatar Dec 12 '18 13:12 anoadragon453

Note: Document how Multiuser uses cookies in the WebSocket handshake.

Example of a python2 script that can talk to the Multiuser plugin:

import urllib2
import re
import json
import time

import websocket

req = urllib2.Request("http://127.0.0.1:43110/1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/", headers={"Accept" : "text/html"})
wrapper_body = urllib2.urlopen(req).read()
wrapper_key = re.search('wrapper_key = "(.*?)"', wrapper_body).group(1)
wrapper_nonce = re.search('wrapper_nonce = "(.*?)"', wrapper_body).group(1)

# 

ws = websocket.create_connection("ws://127.0.0.1:43110/Websocket?wrapper_key=%s" % wrapper_key,
        cookie="master_address=1JtHVmhWqmvK6KLbVcQ8RT2oEhW9TLAmRv")
ws.send(json.dumps({"cmd":"userLoginForm","params":{},"id":-2}))
res = ws.recv()
print res

anoadragon453 avatar Feb 17 '19 18:02 anoadragon453

@anoadragon453 I created ZeroFrame WebSocket API for JavaScript. I'm currently also creating clients for other languages. See https://github.com/HelloZeroNet/ZeroNet/issues/1289#issuecomment-507374004 for details.

filips123 avatar Jul 01 '19 18:07 filips123