Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HueBot"/> class.
        /// </summary>
        /// <param name="options">The bot options.</param>
        /// <param name="serviceContext">Service context.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        private MediaPlatformSettings MediaInit(BotOptions options, StatefulServiceContext serviceContext)
        {
            var instanceNumber = serviceContext.NodeInstance();
            var publicMediaUrl = options.BotMediaProcessorUrl ?? options.BotBaseUrl;

            var instanceAddresses = Dns.GetHostEntry(publicMediaUrl.Host).AddressList;

            if (instanceAddresses.Length == 0)
            {
                throw new InvalidOperationException("Could not resolve the PIP hostname. Please make sure that PIP is properly configured for the service");
            }

            return(new MediaPlatformSettings()
            {
                MediaPlatformInstanceSettings = new MediaPlatformInstanceSettings()
                {
                    CertificateThumbprint = options.Certificate,
                    InstanceInternalPort = serviceContext.CodePackageActivationContext.GetEndpoint("MediaPort").Port,
                    InstancePublicIPAddress = instanceAddresses[0],
                    InstancePublicPort = publicMediaUrl.Port + instanceNumber,
                    ServiceFqdn = publicMediaUrl.Host,
                },
                ApplicationId = options.AppId,
            });
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Bot"/> class.
        /// </summary>
        /// <param name="options">The bot options.</param>
        /// <param name="graphLogger">The graph logger.</param>
        /// <param name="serviceContext">Service context.</param>
        public Bot(BotOptions options, IGraphLogger graphLogger, StatefulServiceContext serviceContext)
        {
            this.Options = options;
            this.logger  = graphLogger;

            var name    = this.GetType().Assembly.GetName().Name;
            var builder = new CommunicationsClientBuilder(
                name,
                options.AppId,
                this.logger);

            var authProvider = new AuthenticationProvider(
                name,
                options.AppId,
                options.AppSecret,
                this.logger);

            builder.SetAuthenticationProvider(authProvider);
            builder.SetNotificationUrl(options.BotBaseUrl.ReplacePort(options.BotBaseUrl.Port + serviceContext.NodeInstance()));
            builder.SetMediaPlatformSettings(this.MediaInit(options, serviceContext));
            builder.SetServiceBaseUrl(options.PlaceCallEndpointUrl);

            this.Client = builder.Build();

            this.Client.Calls().OnIncoming += this.CallsOnIncoming;
            this.Client.Calls().OnUpdated  += this.CallsOnUpdated;

            this.OnlineMeetings = new OnlineMeetingHelper(authProvider, options.PlaceCallEndpointUrl);
        }