コード例 #1
0
        /// <summary>
        /// Connects to the gateway with the application key and authentication token. The gateway must be set before using this method.
        /// </summary>
        /// <param name="appKey">Your application key to use ORTC.</param>
        /// <param name="authToken">Authentication token that identifies your permissions.</param>
        /// <example>
        ///   <code>
        /// ortcClient.Connect("myApplicationKey", "myAuthenticationToken");
        ///   </code>
        ///   </example>
        public void Connect(string appKey, string authToken)
        {
            if (IsConnected)
            {
                DelegateExceptionCallback(new OrtcAlreadyConnectedException("Already connected"));
            }
            else if (String.IsNullOrEmpty(ClusterUrl) && String.IsNullOrEmpty(Url))
            {
                DelegateExceptionCallback(new OrtcEmptyFieldException("URL and Cluster URL are null or empty"));
            }
            else if (String.IsNullOrEmpty(appKey))
            {
                DelegateExceptionCallback(new OrtcEmptyFieldException("Application Key is null or empty"));
            }
            else if (String.IsNullOrEmpty(authToken))
            {
                DelegateExceptionCallback(new OrtcEmptyFieldException("Authentication ToKen is null or empty"));
            }
            else if (!IsCluster && !Url.OrtcIsValidUrl())
            {
                DelegateExceptionCallback(new OrtcInvalidCharactersException("Invalid URL"));
            }
            else if (IsCluster && !ClusterUrl.OrtcIsValidUrl())
            {
                DelegateExceptionCallback(new OrtcInvalidCharactersException("Invalid Cluster URL"));
            }
            else if (!appKey.OrtcIsValidInput())
            {
                DelegateExceptionCallback(new OrtcInvalidCharactersException("Application Key has invalid characters"));
            }
            else if (!authToken.OrtcIsValidInput())
            {
                DelegateExceptionCallback(new OrtcInvalidCharactersException("Authentication Token has invalid characters"));
            }
            else if (AnnouncementSubChannel != null && !AnnouncementSubChannel.OrtcIsValidInput())
            {
                DelegateExceptionCallback(new OrtcInvalidCharactersException("Announcement Subchannel has invalid characters"));
            }
            else if (!String.IsNullOrEmpty(ConnectionMetadata) && ConnectionMetadata.Length > Constants.MAX_CONNECTION_METADATA_SIZE)
            {
                DelegateExceptionCallback(new OrtcMaxLengthException(String.Format("Connection metadata size exceeds the limit of {0} characters", Constants.MAX_CONNECTION_METADATA_SIZE)));
            }
            else if (_client._isConnecting || _client._reconnectStartedAt != null)
            {
                DelegateExceptionCallback(new OrtcAlreadyConnectedException("Already trying to connect"));
            }
            else
            {
                _client._stopReconnecting = false;

                _authenticationToken = authToken;
                _applicationKey      = appKey;

                _client.DoConnect();
            }
        }
コード例 #2
0
        public override void Connect(string appKey, string authToken)
        {
            #region Sanity Checks
            //if (Application.internetReachability == NetworkReachability.NotReachable)
            //{
            //    RaiseOnException(new OrtcException(OrtcExceptionReason.InvalidArguments, "Internet not reachable"));
            //}
            //else
            if (IsConnected)
            {
                RaiseOnException(new OrtcException(OrtcExceptionReason.InvalidArguments, "Already connected"));
            }
            else if (_isConnecting)
            {
                RaiseOnException(new OrtcException(OrtcExceptionReason.InvalidArguments, "Already trying to connect"));
            }
            else if (String.IsNullOrEmpty(ClusterUrl) && String.IsNullOrEmpty(Url))
            {
                RaiseOnException(new OrtcException(OrtcExceptionReason.InvalidArguments, "URL and Cluster URL are null or empty"));
            }
            else if (String.IsNullOrEmpty(appKey))
            {
                RaiseOnException(new OrtcException(OrtcExceptionReason.InvalidArguments, "Application Key is null or empty"));
            }
            else if (String.IsNullOrEmpty(authToken))
            {
                RaiseOnException(new OrtcException(OrtcExceptionReason.InvalidArguments, "Authentication ToKen is null or empty"));
            }
            else if (!IsCluster && !Url.OrtcIsValidUrl())
            {
                RaiseOnException(new OrtcException(OrtcExceptionReason.InvalidArguments, "Invalid URL"));
            }
            else if (IsCluster && !ClusterUrl.OrtcIsValidUrl())
            {
                RaiseOnException(new OrtcException(OrtcExceptionReason.InvalidArguments, "Invalid Cluster URL"));
            }
            else if (AnnouncementSubChannel != null && !AnnouncementSubChannel.OrtcIsValidInput())
            {
                RaiseOnException(new OrtcException(OrtcExceptionReason.InvalidArguments, "Announcement Subchannel has invalid characters"));
            }
            else if (!String.IsNullOrEmpty(ConnectionMetadata) && ConnectionMetadata.Length > MAX_CONNECTION_METADATA_SIZE)
            {
                RaiseOnException(new OrtcException(OrtcExceptionReason.InvalidArguments, String.Format("Connection metadata size exceeds the limit of {0} characters", MAX_CONNECTION_METADATA_SIZE)));
            }
            else

            #endregion

            {
                Task.RunOnMain(() =>
                {
                    IosOrtcClientFactory.Connect(_id, appKey, authToken);
                });
            }
        }
コード例 #3
0
ファイル: OrtcClient.cs プロジェクト: gbanfill/geogames
        /// <summary>
        /// Connects to the gateway with the application key and authentication token. The gateway must be set before using this method.
        /// </summary>
        /// <param name="appKey">Your application key to use ORTC.</param>
        /// <param name="authToken">Authentication token that identifies your permissions.</param>
        /// <example>
        ///   <code>
        /// ortcClient.Connect("myApplicationKey", "myAuthenticationToken");
        ///   </code>
        ///   </example>
        public void Connect(string appKey, string authToken)
        {
            if (IsConnected)
            {
                DelegateExceptionCallback(new OrtcAlreadyConnectedException("Already connected"));
            }
            else if (String.IsNullOrEmpty(ClusterUrl) && String.IsNullOrEmpty(Url))
            {
                DelegateExceptionCallback(new OrtcEmptyFieldException("URL and Cluster URL are null or empty"));
            }
            else if (String.IsNullOrEmpty(appKey))
            {
                DelegateExceptionCallback(new OrtcEmptyFieldException("Application Key is null or empty"));
            }
            else if (String.IsNullOrEmpty(authToken))
            {
                DelegateExceptionCallback(new OrtcEmptyFieldException("Authentication ToKen is null or empty"));
            }
            else if (!IsCluster && !Url.OrtcIsValidUrl())
            {
                DelegateExceptionCallback(new OrtcInvalidCharactersException("Invalid URL"));
            }
            else if (IsCluster && !ClusterUrl.OrtcIsValidUrl())
            {
                DelegateExceptionCallback(new OrtcInvalidCharactersException("Invalid Cluster URL"));
            }
            else if (!appKey.OrtcIsValidInput())
            {
                DelegateExceptionCallback(new OrtcInvalidCharactersException("Application Key has invalid characters"));
            }
            else if (!authToken.OrtcIsValidInput())
            {
                DelegateExceptionCallback(new OrtcInvalidCharactersException("Authentication Token has invalid characters"));
            }
            else if (AnnouncementSubChannel != null && !AnnouncementSubChannel.OrtcIsValidInput())
            {
                DelegateExceptionCallback(new OrtcInvalidCharactersException("Announcement Subchannel has invalid characters"));
            }
            else if (!String.IsNullOrEmpty(ConnectionMetadata) && ConnectionMetadata.Length > Constants.MAX_CONNECTION_METADATA_SIZE)
            {
                DelegateExceptionCallback(new OrtcMaxLengthException(String.Format("Connection metadata size exceeds the limit of {0} characters", Constants.MAX_CONNECTION_METADATA_SIZE)));
            }
            else if (_client._isConnecting)
            {
                DelegateExceptionCallback(new OrtcAlreadyConnectedException("Already trying to connect"));
            }
            else
            {
                _client.DoStopReconnecting();

                _authenticationToken = authToken;
                _applicationKey      = appKey;

                if (Device.OS == TargetPlatform.Android && !String.IsNullOrEmpty(_googleProjectNumber))
                {
                    var regId = Settings.RegistrationId;
                    if (String.IsNullOrEmpty(regId))
                    {
                        MessagingCenter.Send(this, "GoogleProjectNumber", _googleProjectNumber);
                    }
                    else
                    {
                        _registrationId = regId;
                    }
                }
                _client.DoConnect();
            }
        }