Beispiel #1
0
        bool Init()
        {
            // Default to using binary protocol
            Func <TClientTransport, TProtocol> createProtocolFunc = (transport) => new TBinaryProtocolTS(transport);

            if (context.Transport == null)
            {
                if (context.endpoint == RuyiSDKContext.Endpoint.Web)
                {
                    lowLatencyTransport  = new THttpClientTransport(new Uri(context.RemoteAddress), null);
                    highLatencyTransport = lowLatencyTransport;
                    createProtocolFunc   = (transport) => new TJsonProtocol(transport);
                }
                else
                {
                    var host = OS.Util.GetIPAddress(context.RemoteAddress);
                    // init and open high/low latency transport, create protocols
                    var lowLatencyPort = context.LowLatencyPort == 0 ? ConstantsSDKDataTypesConstants.low_latency_socket_port : context.LowLatencyPort;
                    lowLatencyTransport = new TSocketTransportTS(host, lowLatencyPort, context.Timeout <= 0 ? SDKUtility.Instance.LowLatencyTimeout : context.Timeout);

                    var highLatencyPort = context.HighLatencyPort == 0 ? ConstantsSDKDataTypesConstants.high_latency_socket_port : context.HighLatencyPort;
                    highLatencyTransport = new TSocketTransportTS(host, highLatencyPort, context.Timeout <= 0 ? SDKUtility.Instance.HighLatencyTimeout : context.Timeout);
                }
            }
            else
            {
                lowLatencyTransport  = context.Transport;
                highLatencyTransport = context.Transport;
            }

            // If we have 1 transport we need 1 protocol, if 2 transports 2 protocol
            if (Object.ReferenceEquals(lowLatencyTransport, highLatencyTransport))
            {
                LowLatencyProtocol  = createProtocolFunc(lowLatencyTransport);
                HighLatencyProtocol = LowLatencyProtocol;
                lowLatencyTransport.OpenAsync().Wait();
            }
            else
            {
                LowLatencyProtocol  = createProtocolFunc(lowLatencyTransport);
                HighLatencyProtocol = createProtocolFunc(highLatencyTransport);

                Task.WaitAll(
                    lowLatencyTransport.OpenAsync(),
                    highLatencyTransport.OpenAsync()
                    );
            }

            if (!ValidateVersion())
            {
                return(false);
            }

            var pubout = ConstantsSDKDataTypesConstants.layer0_publisher_out_uri.SetAddress(context.RemoteAddress);

            factory = new Layer0.ZeroMQ.MDPSDKFactory(string.Empty, pubout);

            // init subscriber
            if (context.endpoint != RuyiSDKContext.Endpoint.Web && IsFeatureEnabled(SDKFeatures.Subscriber))
            {
                Subscriber = factory.CreateSubscriber();
            }

            // init storage layer
            if (IsFeatureEnabled(SDKFeatures.Storage))
            {
                var stoProtocol = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.STORAGELAYER.ServiceID());
                Storage = new StorageLayerService.Client(stoProtocol);
            }

            // init braincloud service
            if (IsFeatureEnabled(SDKFeatures.Online))
            {
                var bcProtocol = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.BCSERVICE.ServiceID());
                RuyiNetService = new RuyiNetClient(bcProtocol, Storage);
                //BCService = new BrainCloudService.Client(bcProtocal);
            }

            // init setting system
            if (IsFeatureEnabled(SDKFeatures.Settings))
            {
                var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.SETTINGSYSTEM_EXTERNAL.ServiceID());
                SettingSys = new SDK.SettingSystem.Api.SettingSystemService.Client(proto);
            }

            // init L10N
            if (IsFeatureEnabled(SDKFeatures.L10N))
            {
                var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.L10NSERVICE.ServiceID());
                L10NService = new LocalizationService.Client(proto);
            }

            // user manager
            if (IsFeatureEnabled(SDKFeatures.Users))
            {
                var proto = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.USER_SERVICE_EXTERNAL.ServiceID());
                UserService = new UserServExternal.Client(proto);
            }

            // input manger
            if (IsFeatureEnabled(SDKFeatures.Input))
            {
                var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.INPUTMANAGER_EXTERNAL.ServiceID());
                InputMgr = new InputManagerService.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.Speech))
            {
                var proto = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.SPEECH.ServiceID());
                SpeechService = new SpeechService.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.Media))
            {
                var proto = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.MEDIA.ServiceID());
                Media = new MediaService.Client(proto);
            }
            if (IsFeatureEnabled(SDKFeatures.Overlay))
            {
                var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.OVERLAYMANAGER_EXTERNAL.ServiceID());
                OverlayService = new ExternalOverlayManagerService.Client(proto);
            }
            return(true);
        }
Beispiel #2
0
        bool Init()
        {
            if (context.Transport == null)
            {
                // init and open high/low latency transport, create protocols
                var lowLatencyPort = context.LowLatencyPort == 0 ? ConstantsSDKDataTypesConstants.low_latency_socket_port : context.LowLatencyPort;
                lowLatencyTransport = new TSocketTransportTS(context.RemoteAddress, lowLatencyPort, context.Timeout <= 0 ? SDKUtility.Instance.LowLatencyTimeout : context.Timeout);

                var highLatencyPort = context.HighLatencyPort == 0 ? ConstantsSDKDataTypesConstants.high_latency_socket_port : context.HighLatencyPort;
                highLatencyTransport = new TSocketTransportTS(context.RemoteAddress, highLatencyPort, context.Timeout <= 0 ? SDKUtility.Instance.HighLatencyTimeout : context.Timeout);
            }
            else
            {
                lowLatencyTransport  = context.Transport;
                highLatencyTransport = context.Transport;
            }

            LowLatencyProtocol  = new TBinaryProtocolTS(lowLatencyTransport);
            HighLatencyProtocol = new TBinaryProtocolTS(highLatencyTransport);

            lowLatencyTransport.Open();
            highLatencyTransport.Open();

            if (!ValidateVersion())
            {
                return(false);
            }

            if (IsFeatureEnabled(SDKFeatures.Subscriber))
            {
                var pubout = ConstantsSDKDataTypesConstants.layer0_publisher_out_uri.SetAddress(context.RemoteAddress);
                Subscriber = SubscribeClient.CreateInstance(pubout);
            }

            if (IsFeatureEnabled(SDKFeatures.Storage))
            {
                var stoProtocol = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.STORAGELAYER.ServiceID());
                Storage = new StorageLayerService.Client(stoProtocol);
            }

            if (IsFeatureEnabled(SDKFeatures.Online))
            {
                var bcProtocol = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.BCSERVICE.ServiceID());
                RuyiNetService = new RuyiNetClient(bcProtocol, Storage);
                //BCService = new BrainCloudService.Client(bcProtocal);
            }

            if (IsFeatureEnabled(SDKFeatures.Settings))
            {
                var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.SETTINGSYSTEM_EXTERNAL.ServiceID());
                SettingSys = new SDK.SettingSystem.Api.SettingSystemService.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.L10N))
            {
                var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.L10NSERVICE.ServiceID());
                L10NService = new LocalizationService.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.Users))
            {
                var proto = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.USER_SERVICE_EXTERNAL.ServiceID());
                UserService = new UserServExternal.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.Input))
            {
                var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.INPUTMANAGER_EXTERNAL.ServiceID());
                InputMgr = new InputManagerService.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.Speech))
            {
                var proto = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.SPEECH.ServiceID());
                SpeechService = new SpeechService.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.Media))
            {
                var proto = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.MEDIA.ServiceID());
                Media = new MediaService.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.Overlay))
            {
                var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.OVERLAYMANAGER_EXTERNAL.ServiceID());
                OverlayService = new ExternalOverlayManagerService.Client(proto);
            }

            return(true);
        }