public async static Task <WCConnectionRequest> CreateSession(string bridgeUrl, dynamic myMeta , Dictionary <string, List <Func <WCSession, JsonRpc, JsonRpc> > > requestHandler = null , int chainId = 1, int timeoutSec = 0) { var sessionTopic = Guid.NewGuid().ToString(); var myPeerId = Guid.NewGuid().ToString(); var keyHex = RandomBytes(32).ToHexString(); var wcVersion = 1; var wcUri = new WCUri() { bridgeUrl = bridgeUrl, keyHex = keyHex, topic = sessionTopic, version = wcVersion }; var wcSession = new WCSession() { bridgeUrl = bridgeUrl, sessionTopic = sessionTopic, keyHex = keyHex, ourPeerId = myPeerId, eventHandler = requestHandler }; await wcSession.Connect(); var sessionRequest = await wcSession.SendSessionRequestAsync(myMeta, timeoutSec); return(new WCConnectionRequest() { wcUri = wcUri.ToString(), wcSession = wcSession, wcSessionRequest = sessionRequest }); }
public async static Task <KeyValuePair <WCSession, JsonRpc> > ConnectSession(string wcUrl, dynamic myMeta , Dictionary <string, List <Func <WCSession, JsonRpc, JsonRpc> > > requestHandler = null , int chainId = 1, int timeoutSec = 0) { TaskCompletionSource <KeyValuePair <WCSession, JsonRpc> > completer = new TaskCompletionSource <KeyValuePair <WCSession, JsonRpc> >(); Action <WCSession, JsonRpc> requestRetrieved = (session, jsonrpc) => { completer.SetResult(new KeyValuePair <WCSession, JsonRpc>(session, jsonrpc)); }; var wcUri = WCUri.FromString(wcUrl); var myPeerId = Guid.NewGuid().ToString(); var keyHex = wcUri.keyHex; var wcVersion = wcUri.version; var bridgeUrl = wcUri.bridgeUrl; var sessionTopic = wcUri.topic; var wcSession = new WCSession() { bridgeUrl = bridgeUrl, sessionTopic = sessionTopic, keyHex = keyHex, ourPeerId = myPeerId, eventHandler = requestHandler }; await wcSession.Connect(sessionTopic, requestRetrieved); return(await completer.Task.TimeoutAfter(timeoutSec)); }