public async Task Subscribe_ProcessAsync(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken) { var args = new SubscribeArgs(); await args.ReadAsync(iprot, cancellationToken); await iprot.ReadMessageEndAsync(cancellationToken); var result = new SubscribeResult(); try { result.Success = await _iAsync.SubscribeAsync(args.Message, cancellationToken); await oprot.WriteMessageBeginAsync(new TMessage("Subscribe", TMessageType.Reply, seqid), cancellationToken); await result.WriteAsync(oprot, cancellationToken); } catch (TTransportException) { throw; } catch (Exception ex) { Console.Error.WriteLine("Error occurred in processor:"); Console.Error.WriteLine(ex.ToString()); var x = new TApplicationException(TApplicationException.ExceptionType.InternalError, " Internal error."); await oprot.WriteMessageBeginAsync(new TMessage("Subscribe", TMessageType.Exception, seqid), cancellationToken); await x.WriteAsync(oprot, cancellationToken); } await oprot.WriteMessageEndAsync(cancellationToken); await oprot.Transport.FlushAsync(cancellationToken); }
public async Task <Ruyi.SDK.Http.SubscribeReply> SubscribeAsync(Ruyi.SDK.Http.SubscribeRequest message, CancellationToken cancellationToken) { await OutputProtocol.WriteMessageBeginAsync(new TMessage("Subscribe", TMessageType.Call, SeqId), cancellationToken); var args = new SubscribeArgs(); args.Message = message; await args.WriteAsync(OutputProtocol, cancellationToken); await OutputProtocol.WriteMessageEndAsync(cancellationToken); await OutputProtocol.Transport.FlushAsync(cancellationToken); var msg = await InputProtocol.ReadMessageBeginAsync(cancellationToken); if (msg.Type == TMessageType.Exception) { var x = await TApplicationException.ReadAsync(InputProtocol, cancellationToken); await InputProtocol.ReadMessageEndAsync(cancellationToken); throw x; } var result = new SubscribeResult(); await result.ReadAsync(InputProtocol, cancellationToken); await InputProtocol.ReadMessageEndAsync(cancellationToken); if (result.__isset.success) { return(result.Success); } throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "Subscribe failed: unknown result"); }
/// <summary> /// Handles subscribing to the session channel and connecting to subscribed clients. /// /// See the Subscribing to the Session Channel and Connecting to Subscribed Clients sections /// of the Advanced Topics Manual Signalling Guide for more info. /// </summary> /// <returns> Future </returns> private Future <object> SubscribeToSessionChannel() { Promise <object> promise = new Promise <object>(); try { SubscribeArgs SubscribeArgs = new SubscribeArgs(SessionChannel) { OnSuccess = (args) => { promise.Resolve(null); }, OnFailure = (e) => { promise.Reject(e.Exception); } }; FM.WebSync.Subscribers.SubscribeArgsExtensions.SetOnClientSubscribe(SubscribeArgs, (o) => { string RemoteClientId = o.Client.ClientId.ToString(); Record Value; if (o.SubscribedClient.BoundRecords.TryGetValue(UserIdKey, out Value)) { string RemoteUserId = Serializer.DeserializeString(Value.ValueJson); var Con = CreateConnectionAndWireOnLocalCandidate(new PeerClient(o.SubscribedClient.ClientId.ToString(), o.SubscribedClient.BoundRecords), RemoteUserId); Con.ExternalId = RemoteClientId; Connections.Add(Con); Con.CreateOffer().Then(new Function1 <SessionDescription, Future <SessionDescription> >((offer) => { return(Con.SetLocalDescription(offer)); })) .Then((offer) => { try { Client.Publish(new PublishArgs(RemoteUserChannel(RemoteUserId), offer.ToJson(), OfferTag) { OnSuccess = (PublishSuccessArgs) => { Log.Info("Published offer to remote peer."); }, OnFailure = (e) => { Log.Error("Could not publish offer to remote peer.", e.Exception); } }); } catch (Exception ex) { Log.Error(ex.Message); } }); } }); FM.WebSync.Subscribers.SubscribeArgsExtensions.SetOnClientUnsubscribe(SubscribeArgs, (o) => { string RemoteClientId = o.Client.ClientId.ToString(); Connection Con = Connections.GetById(RemoteClientId); if (Con != null) { Connections.Remove(Con); Con.Close(); } }); Client.Subscribe(SubscribeArgs); } catch (Exception ex) { Log.Error("Could not subscribe to session channel.", ex); } return(promise); }