Нет описания

luis 0a0326a695 Added js as 'wsrpc.js' too 7 лет назад
client 1ba9e54fd3 Added reject to wsprc.js 7 лет назад
doc 255840fdbb Samples, readme 7 лет назад
sample 31587520a4 Browser and node support 7 лет назад
wsrpcAssets 42264fa0f1 Added export method for structs 7 лет назад
README.md 710f6f3672 Readme update 7 лет назад
clientctx.go 0727ac7dab omitdefault 7 лет назад
wsrpc.go 0a0326a695 Added js as 'wsrpc.js' too 7 лет назад
wsrpc_test.go 1ba9e54fd3 Added reject to wsprc.js 7 лет назад

README.md

WebSocket RPC

Usage:

func MyCliFunc(cli *wsrpc.ClientCtx) {

	cli.Define("btn1.click", func(param ...interface{}) interface{} { // Define a remote interface so javascript client can call
		log.Println("Async button clicked")
		return "ok"

	})
	ret := cli.Call("Hello", wsrpc.DataObj{
		"couldbe": "interface",
	})
	t := <-ret

	log.Println("Response:", t)
}

func main() {
	var mux = http.NewServeMux()

	wsrpc.RegisterTo(mux, MyCliFunc)  // Client websocket handler, this registers also the JS library
	mux.HandleFunc("/", webGenerated.AssetHandleFunc)

	log.Println("Listening :8080")
	http.ListenAndServe(":8080", mux)

}

Client side:

	wsrpc = new WsRpc();
	wsrpc.connect("ws://"+location.host +"/wsrpc");

	obj = {
		Hello: function(response,param) {
			console.log("Hello world")
			response({ok:"OK"})
		}
	}
	wsrpc.export(obj)


	btn = document.querySelector("#btn1")

	btn.addEventListener("click",function(){
		console.log("Button clicked")
		wsrpc.call("btn1.click",{"hello":"ok"}, (res) =>{   // Will call server defined procedure
			console.log("Answered:",res	);
		})
	})