Add support for transport
Add support for transport parameter to use client with node js.
let socket = new Socket(`${this.endpoint}/socket`, {transport: W3CWebSocket, params: "mytoken"})
You mean this ?
Yes, exactly ^^. I am quite new on Reason. Could you provide an example with params ?
This grammar of BuckleScript should give you a appropriate params object:
[%bs.obj { include_current = true ; network_id = 1 } ]
I've never used Reason. It might be a little different in Reason.
Also checkout this section: _binding_to_js_objects
I tried this but for now it doesn't work.
let socketUri = url ^ "/socket";
let params = {
"params": {
"userToken": "Test"
}
};
let socket = initSocket socketUri params |> connectSocket;
I get this error
We've found a bug for you!
/Users/laibulle/Projects/HaumMobile/re/Api.re 68:37-42
66 ┆ };
67 ┆
68 ┆ let socket = initSocket socketUri params |> connectSocket;
69 ┆ {
70 ┆ "fetchHomes": fun () => fetchHomes url token
The function applied to this argument has type
opts::Js.t 'a? =>
Js.t
{. connectionState : string, endPointURL : string,
flushSendBuffer : Phx_abstract.void, isConnected : bool,
log : Js.Internal.meth
[ `Arity_3 (string, string, Phx_abstract.any) ] Phx_abstract.void,
makeRef : string,
onClose : Js.Internal.meth
[ `Arity_1 Phx_abstract.function_ ] Phx_abstract.void,
onConnClose : Js.Internal.meth
[ `Arity_1 Phx_abstract.any ] Phx_abstract.void,
onConnError : Js.Internal.meth
[ `Arity_1 Phx_abstract.any ] Phx_abstract.void,
onConnMessage : Js.Internal.meth
[ `Arity_1 Phx_abstract.any ] Phx_abstract.void,
onConnOpen : Phx_abstract.void,
onError : Js.Internal.meth
[ `Arity_1 Phx_abstract.function_ ] Phx_abstract.void,
onMessage : Js.Internal.meth
[ `Arity_1 Phx_abstract.function_ ] Phx_abstract.void,
onOpen : Js.Internal.meth
[ `Arity_1 Phx_abstract.function_ ] Phx_abstract.void,
protocol : string,
push : Js.Internal.meth [ `Arity_1 Phx_abstract.any ] Phx_abstract.void,
remove : Js.Internal.meth [ `Arity_1 Phx_channel.t ] Phx_abstract.void,
sendHeartbeat : Phx_abstract.void,
triggerChanError : Phx_abstract.void }
This argument cannot be applied without label
let params = [%bs.obj { userToken = "Test" } ]
Try this
It give me
We've found a bug for you!
/Users/laibulle/Projects/HaumMobile/re/Api.re 62:25-46
60 │ let connect = fun url token => {
61 │ let socketUri = url ^ "/socket";
62 │ let params = [%bs.obj { userToken = "Test" } ];
63 │
64 │ /*let params = {
Unbound instance variable userToken
Looks like in ReasonML it is
let params = [%bs.obj { userToken : "Test" } ];
Please go to discord of ReasonML. There are a lot of people know Reason well.
I'm not sure if I this information is pertinent but being new to Reason and Phoenix I had a hell of a time figuring out how to add argument to initSocket beyond the mount point string. Something like this works:
let opts = { "params": { "user_id": 1 } }
let socket =
initSocket("ws://foo.localhost:4000/socket", ~opts)
|> connectSocket
|> putOnClose(() => Js.log("Socket closed"));
The [bs.obj ] part I don't think is necessary. The key is just labeling the argument "opts".
@lleolin that is a syntax sugar in reason I guess.