コード例 #1
0
ファイル: EaseHelper.cs プロジェクト: wuearl/imPC
        private EaseHelper()
        {
            EMChatConfigs configs = new EMChatConfigs(System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\Changliao", /*System.Environment.GetFolderPath(Environment.SpecialFolder.Personal)+ "\\Changliao"*/ System.Environment.CurrentDirectory, AppSettingHelper.getAppConfig("hxKey"), 0);

            client = EMClient.create(configs);
            queue  = new BackgroundQueue();
            ChangLiaoConnection              = new EMConnectionListener();
            ChangLiaoConnection.onConntect   = onConnect;
            ChangLiaoConnection.onDisconnect = onDisconnect;
            ChangLiaoConnection.onPong       = onPong;
            client.addConnectionListener(ChangLiaoConnection);
            ChangLiaoChatManager = new EMChatManagerListener();
            ChangLiaoChatManager.onReceiveMessages    = onReciveMessage;
            ChangLiaoChatManager.onReceiveCmdMessages = onReciveCmdMessage;
            ContactListener = new EMContactListener();
            ContactListener.onContactAdded   = onContactAdded;
            ContactListener.onContactDeleted = onContactDeleted;
            ContactListener.onContactInvited = onContactInvited;
            client.getChatManager().addListener(ChangLiaoChatManager);
            client.getContactManager().registerContactListener(ContactListener);
            GroupManagerListener = new EMGroupManagerListener();
            GroupManagerListener.onLeaveGroup = onLeaveGroup;
            GroupManagerListener.onReceiveJoinGroupApplication   = onReceiveJoinGroupApplication;
            GroupManagerListener.onMemberLeftGroup               = onMemberLeaveGroup;
            GroupManagerListener.onMemberJoinedGroup             = onMemberJoinedGroup;
            GroupManagerListener.onAutoAcceptInvitationFromGroup = onAutoAcceptInvitationFromGroup;
            GroupManagerListener.onUpdateMyGroupList             = onUpdateMyGroupList;
            client.getGroupManager().addListener(GroupManagerListener);
            relogin = false;
        }
コード例 #2
0
        void RegisterHyphenate()
        {
            var apnsCertName = "";

#if DEBUG
            apnsCertName = "demoappstore-dev";
#else
            apnsCertName = "demoappstore";
#endif
            var appkey = NSUserDefaults.StandardUserDefaults.StringForKey("identifier_appkey");
            if (string.IsNullOrEmpty(appkey))
            {
                appkey = "easemob-demo#chatdemoui";
                NSUserDefaults.StandardUserDefaults.SetString(appkey, "identifier_appkey");
                NSUserDefaults.StandardUserDefaults.Synchronize();
            }
            var isHttpsOnly = NSUserDefaults.StandardUserDefaults.BoolForKey("identifier_httpsonly");

            EMOptions options = EMOptions.OptionsWithAppkey(appkey);
            options.ApnsCertName = apnsCertName;
            options.IsAutoAcceptGroupInvitation = false;
            options.EnableConsoleLog            = true;
            options.UsingHttpsOnly = isHttpsOnly;

            var error = EMClient.SharedClient().InitializeSDKWithOptions(options);
            if (error != null)
            {
                System.Console.WriteLine($"Register hyphenate sdk failed: [{error.Code} {error.Description}]!");
            }
        }
コード例 #3
0
        void HandleLoginEventHandler(object sender, EventArgs e)
        {
            var account  = AccountTextField.Text?.Trim();
            var password = PasswordTextField.Text;

            if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
            {
                AlertText("Promot", "Account or password cannot be empty!");
                return;
            }
            EMClient.SharedClient().LoginWithUsernameAndPasswordAndCompletion(account, password, (userName, error) =>
            {
                if (error != null)
                {
                    AlertText("Prompt", $"Login {account} failed: {error.ErrorDescription}!");
                }
                else
                {
                    AlertText("Promot", $"Login {account} success!");
                    NavigationController.PushViewController(new ViewController {
                        Account = account
                    }, true);
                }
            });
        }
コード例 #4
0
        void HandleRegisterEventHandler(object sender, EventArgs e)
        {
            var account  = AccountTextField.Text?.Trim();
            var password = PasswordTextField.Text;

            if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
            {
                AlertText("Promot", "Account or password cannot be empty!");
                return;
            }
            EMClient.SharedClient().AsyncRegisterWithUsername(account, password, () =>
            {
                AlertText("Promot", $"Register {account} success!");
            }, (error) =>
            {
                AlertText("Promot", $"Register {account} failed: {error.ErrorDescription}!");
            });
        }
コード例 #5
0
        void HandleSendMessageEventHandler(object sender, EventArgs e)
        {
            var contact = ContactTextField.Text?.Trim();
            var msg     = SendMessageTextField.Text?.Trim();

            if (string.IsNullOrEmpty(contact))
            {
                AlertText("Prompt", "Please input a contact");
                return;
            }
            if (string.IsNullOrEmpty(msg))
            {
                AlertText("Prompt", "Please input a message");
                return;
            }

            var chatManager = EMClient.SharedClient().ChatManager;

            var message = new EMMessage(
                contact,
                EMClient.SharedClient().CurrentUsername,
                contact,
                new EMTextMessageBody(msg),
                new NSDictionary())
            {
                ChatType = EMChatType.Chat
            };

            chatManager.SendMessage(message, (progress) => {
                System.Console.WriteLine($"Send message with progress {progress}");
            }, (EMMessage aMessage, EMError error) =>
            {
                if (error != null)
                {
                    AlertText("Prompt", $"Send message failed: {error.ErrorDescription}!");
                }
                else
                {
                    var text      = TextView.Text;
                    TextView.Text = $"{text}\n>>>>>>>>>Send message:{msg}";
                }
            });
        }
コード例 #6
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                // Free any other manage object here.
            }

            // Free any unmanaged object here.
            if (_authenticate != null)
            {
                try
                {
                    _authenticate.Close();
                }
                catch (Exception)
                {
                    _authenticate.Abort();
                    throw;
                }

                _authenticate = null;
            }

            if (_creativeBuilder != null)
            {
                try
                {
                    _creativeBuilder.Close();
                }
                catch (Exception)
                {
                    _creativeBuilder.Abort();
                    throw;
                }

                _creativeBuilder = null;
            }

            if (_dmPlus != null)
            {
                try
                {
                    _dmPlus.Close();
                }
                catch (Exception)
                {
                    _dmPlus.Abort();
                    throw;
                }
                _dmPlus = null;
            }

            if (_emService != null)
            {
                try
                {
                    _emService.Close();
                }
                catch (Exception)
                {
                    _emService.Abort();
                    throw;
                }
                _emService = null;
            }

            if (_listImport != null)
            {
                try
                {
                    _listImport.Close();
                }
                catch (Exception)
                {
                    _listImport.Abort();
                    throw;
                }
                _listImport = null;
            }

            if (_listManager != null)
            {
                try
                {
                    _listManager.Close();
                }
                catch (Exception)
                {
                    _listManager.Abort();
                    throw;
                }
                _listManager = null;
            }

            if (_reporting != null)
            {
                try
                {
                    _reporting.Close();
                }
                catch (Exception)
                {
                    _reporting.Abort();
                    throw;
                }
                _reporting = null;
            }

            if (_sendMessage != null)
            {
                try
                {
                    _sendMessage.Close();
                }
                catch (Exception)
                {
                    _sendMessage.Abort();
                    throw;
                }
                _sendMessage = null;
            }

            _disposed = true;
        }
コード例 #7
0
        public override void ViewDidDisappear(bool animated)
        {
            base.ViewDidDisappear(animated);

            EMClient.SharedClient().ChatManager.RemoveDelegate(this);
        }
コード例 #8
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            EMClient.SharedClient().ChatManager.AddDelegate(this, null);
        }