예제 #1
0
        public Client(
            string project, string token,
            string host           = null,
            bool jwt              = false,
            TimeSpan?connectDelay = null, TimeSpan?connectTimeout = null, TimeSpan?closeTimeout = null)
        {
            if (string.IsNullOrWhiteSpace(project))
            {
                throw new ArgumentNullException("Must provide a project");
            }
            if (string.IsNullOrWhiteSpace(token))
            {
                throw new ArgumentNullException("Must provide a token");
            }
            if (string.IsNullOrWhiteSpace(host))
            {
                host = "relay.signalwire.com";
            }

            string authentication = null;

            if (!jwt)
            {
                authentication = CreateAuthentication(project, token);
            }
            else
            {
                authentication = CreateJWTAuthentication(project, token);
            }

            UpstreamSession.SessionOptions options = new UpstreamSession.SessionOptions()
            {
                Bootstrap      = new Uri("wss://" + host),
                Authentication = authentication,
            };
            if (connectDelay.HasValue)
            {
                options.ConnectDelay = connectDelay.Value;
            }
            if (connectTimeout.HasValue)
            {
                options.ConnectTimeout = connectTimeout.Value;
            }
            if (closeTimeout.HasValue)
            {
                options.CloseTimeout = closeTimeout.Value;
            }

            Session = new UpstreamSession(options);

            Session.OnReady        += s => OnReady?.Invoke(this);
            Session.OnDisconnected += s => OnDisconnected?.Invoke(this);

            mSignalwireAPI = new SignalwireAPI(this);
            mCallingAPI    = new CallingAPI(mSignalwireAPI);
        }
예제 #2
0
 internal MessagingAPI(SignalwireAPI api)
 {
     mLogger              = SignalWireLogging.CreateLogger <Client>();
     mAPI                 = api;
     mAPI.OnNotification += OnNotification;
 }
예제 #3
0
 internal ProvisioningAPI(SignalwireAPI api)
 {
     mAPI = api;
 }
예제 #4
0
        public Client(
            string project,
            string token,
            string host        = null,
            string certificate = null,
            string agent       = null,
            UncertifiedConnectParams uncertifiedConnectParams = null,
            bool jwt = false,
            TimeSpan?connectDelay   = null,
            TimeSpan?connectTimeout = null,
            TimeSpan?closeTimeout   = null)
        {
            if (string.IsNullOrWhiteSpace(project))
            {
                throw new ArgumentNullException("Must provide a project");
            }
            if (string.IsNullOrWhiteSpace(token))
            {
                throw new ArgumentNullException("Must provide a token");
            }
            if (string.IsNullOrWhiteSpace(host))
            {
                host = "relay.signalwire.com";
            }

            mHost        = host;
            mProjectID   = project;
            mToken       = token;
            mCertificate = certificate;

            string authentication = null;

            if (!jwt)
            {
                authentication = CreateAuthentication(project, token);
            }
            else
            {
                authentication = CreateJWTAuthentication(project, token);
            }

            UpstreamSession.SessionOptions options = new UpstreamSession.SessionOptions()
            {
                Bootstrap                = new Uri("wss://" + host),
                Authentication           = authentication,
                Agent                    = agent,
                UncertifiedConnectParams = uncertifiedConnectParams
            };
            if (connectDelay.HasValue)
            {
                options.ConnectDelay = connectDelay.Value;
            }
            if (connectTimeout.HasValue)
            {
                options.ConnectTimeout = connectTimeout.Value;
            }
            if (closeTimeout.HasValue)
            {
                options.CloseTimeout = closeTimeout.Value;
            }
            if (!string.IsNullOrWhiteSpace(certificate))
            {
                options.ClientCertificate = certificate;
            }

            Session = new UpstreamSession(options);

            mSignalwireAPI = new SignalwireAPI(this);
            mCallingAPI    = new CallingAPI(mSignalwireAPI);
            mTaskingAPI    = new TaskingAPI(mSignalwireAPI);
            mMessagingAPI  = new MessagingAPI(mSignalwireAPI);
            mTestingAPI    = new TestingAPI(mSignalwireAPI);

            Session.OnReady += s =>
            {
                if (s.Options.UncertifiedConnectParams?.Protocol != null)
                {
                    // A little bit hacky, but this ensures the protocol is propagated correctly to where it's needed further down the road, and that we register a handler for events
                    mSignalwireAPI.Protocol = s.Options.UncertifiedConnectParams.Protocol;
                    Session.RegisterSubscriptionHandler(s.Options.UncertifiedConnectParams.Protocol, "notifications", (s2, r, p) => mSignalwireAPI.ExecuteNotificationCallback(p));
                }
                OnReady?.Invoke(this);
            };
            Session.OnRestored     += s => OnRestored?.Invoke(this);
            Session.OnDisconnected += s => OnDisconnected?.Invoke(this);
        }
예제 #5
0
        public Client(
            string project,
            string token,
            string host        = null,
            string certificate = null,
            string agent       = null,
            ConnectParams.NetworkParam network = null,
            bool jwt = false,
            TimeSpan?connectDelay   = null,
            TimeSpan?connectTimeout = null,
            TimeSpan?closeTimeout   = null)
        {
            if (string.IsNullOrWhiteSpace(project))
            {
                throw new ArgumentNullException("Must provide a project");
            }
            if (string.IsNullOrWhiteSpace(token))
            {
                throw new ArgumentNullException("Must provide a token");
            }
            if (string.IsNullOrWhiteSpace(host))
            {
                host = "relay.signalwire.com";
            }

            mHost        = host;
            mProjectID   = project;
            mToken       = token;
            mCertificate = certificate;

            string authentication = null;

            if (!jwt)
            {
                authentication = CreateAuthentication(project, token);
            }
            else
            {
                authentication = CreateJWTAuthentication(project, token);
            }

            UpstreamSession.SessionOptions options = new UpstreamSession.SessionOptions()
            {
                Bootstrap      = new Uri("wss://" + host),
                Authentication = authentication,
                Agent          = agent,
                NetworkData    = network,
            };
            if (connectDelay.HasValue)
            {
                options.ConnectDelay = connectDelay.Value;
            }
            if (connectTimeout.HasValue)
            {
                options.ConnectTimeout = connectTimeout.Value;
            }
            if (closeTimeout.HasValue)
            {
                options.CloseTimeout = closeTimeout.Value;
            }
            if (!string.IsNullOrWhiteSpace(certificate))
            {
                options.ClientCertificate = certificate;
            }

            Session = new UpstreamSession(options);

            Session.OnReady        += s => OnReady?.Invoke(this);
            Session.OnRestored     += s => OnRestored?.Invoke(this);
            Session.OnDisconnected += s => OnDisconnected?.Invoke(this);

            mSignalwireAPI = new SignalwireAPI(this);
            mCallingAPI    = new CallingAPI(mSignalwireAPI);
            mTaskingAPI    = new TaskingAPI(mSignalwireAPI);
            mMessagingAPI  = new MessagingAPI(mSignalwireAPI);
        }
예제 #6
0
 internal TestingAPI(SignalwireAPI api)
 {
     mLogger = SignalWireLogging.CreateLogger <Client>();
     mAPI    = api;
 }