private async Task LoginUser(LogOnInfo logonInfo) { var myUserInfo = await this.jabbrClient.GetUserInfo(); this.username = myUserInfo.Name; this.userId = logonInfo.UserId; this.jabbrClient.JoinedRoom += OnRoomJoined; this.jabbrClient.MessageReceived += OnMessageReceived; this.jabbrClient.UserActivityChanged += OnUserActivityChanged; this.jabbrClient.UsersInactive += OnUsersInactive; this.jabbrClient.UserTyping += OnUserTypingChanged; this.jabbrClient.UserLeft += OnUserLeftRoom; this.jabbrClient.UserJoined += OnUserJoinedRoom; this.jabbrClient.PrivateMessage += OnPrivateMessageReceived; foreach (var roomName in logonInfo.Rooms.Select(r => r.Name)) { RoomViewModel room = this.dependencyResolver.Get <RoomViewModel>(); room.Name = roomName; this.RefreshRoomInfoAsync(room); this.rooms.Add(room); this.eventAggregator.Publish(new JoinedRoom { Room = room }); } }
async void Connect() { _client = new JabbRClient(this.Account.Url); _client.AddMessageContent += HandleAddMessageContent; //client.Disconnected += HandleDisconnected; _client.FlagChanged += HandleFlagChanged; _client.JoinedRoom += HandleJoinedRoom; _client.Kicked += HandleKicked; _client.LoggedOut += HandleLoggedOut; _client.MeMessageReceived += HandleMeMessageReceived; _client.MessageReceived += HandleMessageReceived; _client.NoteChanged += HandleNoteChanged; _client.OwnerAdded += HandleOwnerAdded; _client.OwnerRemoved += HandleOwnerRemoved; _client.PrivateMessage += HandlePrivateMessage; //_client.RoomCountChanged += HandleRoomCountChanged; //client.StateChanged += HandleStateChanged; _client.TopicChanged += HandleTopicChanged; _client.UserActivityChanged += HandleUserActivityChanged; _client.UserJoined += HandleUserJoined; _client.UserLeft += HandleUserLeft; _client.UsernameChanged += HandleUsernameChanged; _client.UsersInactive += HandleUsersInactive; _client.UserTyping += HandleUserTyping; LogOnInfo logonInfo = null; try { logonInfo = await _client.Connect(Account.Username, Account.Password); } catch (Exception ex) { Log("Connect Exception: " + ex); } if (logonInfo != null) { this.UserId = logonInfo.UserId; //Add us into the result's Rooms foreach (var r in logonInfo.Rooms) { Mvx.Trace("Rooms In: " + r.Name); RoomsIn.Add(r); } Log("Connected> " + this.UserId ?? "" + " -> Rooms: " + RoomsIn.Count); _messenger.Publish(new JabbrConnectedMessage(this, this, this.UserId, RoomsIn)); } }
/// <summary> /// Connects to the chat session /// </summary> public void PowerUp() { if (!_isActive) { client.Connect(Name, _password).ContinueWith(task => { if (!task.IsFaulted) { LogOnInfo info = task.Result; IntializeSprockets(); } else { Elmah.ErrorSignal.FromCurrentContext().Raise(task.Exception); } }).Wait(); _isActive = true; } else { throw new InvalidOperationException("Bot is already powered up. Call ShutDown first"); } //if (!_connection.IsActive) //{ // InitializeContainer(); // _chat.On<dynamic, string>("addMessage", ProcessMessage); // _chat.On("leave", OnLeave); // _chat.On("addUser", OnJoin); // _chat.On<IEnumerable<string>>("logOn", OnLogOn); // // Start the connection and wait // _connection.Start(new AutoTransport()).Wait(); // // Join the chat // var success = _chat.Invoke<bool>("Join").Result; // if (!success) // { // // Setup the name of the bot // Send(String.Format("/nick {0} {1}", Name, _password)); // IntializeSprockets(); // } //} }
private void CompleteSignin(LogOnInfo logOnInfo, TaskCompletionSource <UserViewModel> taskCompletionSource) { _logOnInfo = logOnInfo; User userinfo = _client.GetUserInfo().Result; UserViewModel userviewModel = _userService.GetUserViewModel(userinfo); userviewModel.IsCurrentUser = true; _roomService.JoinRooms(logOnInfo.Rooms); _roomService.GetRooms(); CurrentUser = userviewModel; taskCompletionSource.TrySetResult(userviewModel); }
/// <summary> /// Logs in the user. /// </summary> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <returns></returns> async Task <Boolean> IJabbRContext.LoginAsync(String username, String password) { try { this.LogoutUser(); LogOnInfo info = await this.jabbrClient.Connect(username, password); await this.LoginUser(info); return(true); } catch (Exception) { // todo } return(false); }
static void Main(string[] args) { string server = "http://jabbr-staging.apphb.com/"; string roomName = "test"; string userName = "******"; string password = "******"; var client = new JabbRClient(server); // Subscribe to new messages client.MessageReceived += (message, room) => { Console.WriteLine("[{0}] {1}: {2}", message.When, message.User.Name, message.Content); }; client.UserJoined += (user, room) => { Console.WriteLine("{0} joined {1}", user.Name, room); }; client.UserLeft += (user, room) => { Console.WriteLine("{0} left {1}", user.Name, room); }; client.PrivateMessage += (from, to, message) => { Console.WriteLine("*PRIVATE* {0} -> {1} ", from, message); }; // Connect to chat client.Connect(userName, password).ContinueWith(task => { LogOnInfo info = task.Result; Console.WriteLine("Logged on successfully. You are currently in the following rooms:"); foreach (var room in info.Rooms) { Console.WriteLine(room.Name); Console.WriteLine(room.Private); } Console.WriteLine("User id is {0}. Don't share this!", info.UserId); Console.WriteLine(); // Get my user info User myInfo = client.GetUserInfo().Result; Console.WriteLine(myInfo.Name); Console.WriteLine(myInfo.LastActivity); Console.WriteLine(myInfo.Status); Console.WriteLine(myInfo.Country); client.JoinRoom(roomName); Console.WriteLine(); // Join a room called test client.JoinRoom(roomName).ContinueWith(_ => { // Get info about the test room client.GetRoomInfo(roomName).ContinueWith(t => { Room roomInfo = t.Result; Console.WriteLine("Users"); foreach (var u in roomInfo.Users) { Console.WriteLine(u.Name); } Console.WriteLine(); foreach (var u in roomInfo.Users) { if (u.Name != userName) { client.SendPrivateMessage(u.Name, "hey there, this is private right?"); } } }); }); // Set the flag client.SetFlag("bb"); // Set the user note client.SetNote("This is testing a note"); // Mark the client as typing client.SetTyping(roomName); // Clear the note client.SetNote(null); // Say hello to the room client.Send("Hello world", roomName); Console.WriteLine("Press any key to leave the room and disconnect"); Console.Read(); client.LeaveRoom(roomName).ContinueWith(_ => { client.Disconnect(); }); }); Console.ReadKey(); }
static void Main(string[] args) { string server = "http://localhost:16207/"; string roomName = "test"; string userName = "******"; string password = "******"; var client = new JabbRClient(server); // Uncomment to see tracing // client.TraceWriter = Console.Out; // Subscribe to new messages client.MessageReceived += (message, room) => { Console.WriteLine("[{0}] {1}: {2}", message.When, message.User.Name, message.Content); }; client.UserJoined += (user, room, isOwner) => { Console.WriteLine("{0} joined {1}", user.Name, room); }; client.UserLeft += (user, room) => { Console.WriteLine("{0} left {1}", user.Name, room); }; client.PrivateMessage += (from, to, message) => { Console.WriteLine("*PRIVATE* {0} -> {1} ", from, message); }; var wh = new ManualResetEventSlim(); EnsureAccount(server, userName, password); // Connect to chat client.Connect(userName, password).ContinueWith(task => { if (task.IsFaulted) { Console.WriteLine("Error: " + task.Exception.GetBaseException()); wh.Set(); } LogOnInfo info = task.Result; Console.WriteLine("Logged on successfully. You are currently in the following rooms:"); foreach (var room in info.Rooms) { Console.WriteLine(room.Name); Console.WriteLine(room.Private); } Console.WriteLine("User id is {0}. Don't share this!", info.UserId); Console.WriteLine(); // Get my user info User myInfo = client.GetUserInfo().Result; Console.WriteLine(myInfo.Name); Console.WriteLine(myInfo.LastActivity); Console.WriteLine(myInfo.Status); Console.WriteLine(myInfo.Country); // Join a room called test client.JoinRoom(roomName).ContinueWith(_ => { // Get info about the test room client.GetRoomInfo(roomName).ContinueWith(t => { Room roomInfo = t.Result; Console.WriteLine("Users"); foreach (var u in roomInfo.Users) { Console.WriteLine(u.Name); } Console.WriteLine(); foreach (var u in roomInfo.Users) { if (u.Name != userName) { client.SendPrivateMessage(u.Name, "hey there, this is private right?"); } } }); }); // Set the flag client.SetFlag("bb"); // Set the user note client.SetNote("This is testing a note"); // Mark the client as typing client.SetTyping(roomName); // Clear the note client.SetNote(null); // Say hello to the room client.Send("Hello world", roomName); // Post a notification client.PostNotification(new ClientNotification { Source = "Github", Content = "This is a fake github notification from the client", ImageUrl = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAHD0lEQVR4nH2Xy28cWRXGf/dRVV3dfnWcOGOPMwxxJgLNgJAijRhWLCKxyyJ/CFt2rJDYjNjyLyDNfzA7YANEbACNFBQNyGDHdpzY7W7X4z5Z1KOrY4uSjrpVbt/73e985zvnCgbP8+fPAZQQAiEESimklCvRPUIIYgQEECMxRkIIeB/w3uOcxTmHcw5rLcYYrG3exRj9ixcvmnUAnj17hrX2SYzxS6XUJ1JKIaVcAlAK2YIS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LMsKv/a+a7AAAAABJRU5ErkJggg==", Room = "test" }); Console.WriteLine("Press any key to leave the room and disconnect"); Console.Read(); client.LeaveRoom(roomName).ContinueWith(_ => { client.Disconnect(); wh.Set(); }); }); wh.Wait(); }