/// <summary> /// Send message to All people in this room /// </summary> /// <param name="message"></param> /// <returns></returns> public async Task SendMessagePublic(string message) { Room callingRoom = GetRoomByConnectionID(Context.ConnectionId); if (callingRoom == null) { await Clients.Client(Context.ConnectionId).SendMessageOnError("Room is not exist!"); return; } UserCall callingUser = callingRoom.UserCalls.SingleOrDefault(u => u.ConnectionID == Context.ConnectionId); if (callingUser == null) { await Clients.Client(Context.ConnectionId).SendMessageOnError("You is not exist in room"); return; } callingRoom.UserCalls.ForEach(async usr => { if (usr.ConnectionID != callingUser.ConnectionID) { await Clients.Client(usr.ConnectionID).ReceiveMessagePublic(callingUser, message); } else { await Clients.Client(callingUser.ConnectionID).SendMessageOnSuccess(message, true); } }); }
/// <summary> /// Send message to a person in this rom with his connectionid /// </summary> /// <returns></returns> public async Task SendMessagePrivate(string targetConnectionId, string message) { Room callingRoom = GetRoomByConnectionID(Context.ConnectionId); if (callingRoom == null) { await Clients.Client(Context.ConnectionId).SendMessageOnError("Room is not exist!"); return; } UserCall callingUser = callingRoom.UserCalls.SingleOrDefault(uc => uc.ConnectionID == Context.ConnectionId); if (callingUser == null) { await Clients.Client(Context.ConnectionId).SendMessageOnError("You is not exist in room"); return; } UserCall targetUser = callingRoom.UserCalls.SingleOrDefault(uc => uc.ConnectionID == targetConnectionId); if (targetUser == null) { // doesn't find out target user await Clients.Client(callingUser.ConnectionID).SendMessageOnError("Target user is not exist"); return; } await Clients.Client(targetUser.ConnectionID).ReceiveMessagePrivate(callingUser, message); await Clients.Client(callingUser.ConnectionID).SendMessageOnSuccess(message, false); }
public async override void ViewDidLoad() { base.ViewDidLoad(); users = new List <iOSUser>(); //Get all the users (for better performance, convert to paginated lists) var userList = await UserCall.getUsers(); if (userList == null) { var alertController = UIAlertController.Create("Warning", "Could not connect to server, please try again.", UIAlertControllerStyle.Alert); alertController.AddAction(UIAlertAction.Create("Try Again", UIAlertActionStyle.Default, alert => ViewDidLoad())); alertController.AddAction(UIAlertAction.Create("No thanks", UIAlertActionStyle.Default, alert => System.Diagnostics.Debug.Write("No thanks was selected"))); this.PresentViewController(alertController, true, null); } else { // Get the image and reload the list when done foreach (var user in userList) { UIImage image = await IOSImageUtil.FromUrl(user.imageUrl); var iosUser = new iOSUser(image, user); users.Add(iosUser); System.Diagnostics.Debug.WriteLine("NR OF USERS IN LIST: " + users.Count); playersTableView.Source = new SelectPlayerDatasource(users, this); playersTableView.ReloadData(); } } }
public async Task HangUp() { Room callingRoom = GetRoomByConnectionID(Context.ConnectionId); if (callingRoom == null) { await base.OnDisconnectedAsync(new Exception("Room is not exist.")); return; } UserCall callingUser = callingRoom.UserCalls.SingleOrDefault(u => u.ConnectionID == Context.ConnectionId); if (callingUser == null) { await base.OnDisconnectedAsync(new Exception("User is not exist")); return; } callingRoom.UserCalls.RemoveAll(u => u.ConnectionID == Context.ConnectionId); if (callingRoom.UserCalls.Count <= 0) { _rooms.Remove(callingRoom); } // Send a hang up message to each user in the call, if there is one if (callingRoom != null) { foreach (UserCall user in callingRoom.UserCalls.Where(u => u.ConnectionID != callingUser.ConnectionID)) { await Clients.Client(user.ConnectionID).CallEnded(callingUser, string.Format("{0} has hung up.", callingUser.FullName)); } await SendUserListUpdate(callingRoom); } }
public static UserCall GetCall(long userID) { UserCall userCall = null; lock (userCalls) userCall = UserCalls.FirstOrDefault(x => x.UserID == userID); return(userCall); }
/** * Create a new user * Send post to server */ async void HandleTouchUpInside(object sender, EventArgs ea) { if (userInput.Text != "") { User user = new User(); user.username = userInput.Text; byte[] image = ReadFully(imageStream); await UserCall.createUser(image, "jpg", user); } }
public async Task Join(string username, string classid, bool isCaller) { UserCall usr = new UserCall { FullName = username, ConnectionID = Context.ConnectionId, IsCaller = isCaller, InCall = false }; Classes clr = _context.Classes.Find(classid); if (clr == null) { //do something if no class has been found return; } else { Room room = GetRoomByClassID(classid); if (room == null) { _rooms.Add(new Room { RoomIF = clr, UserCalls = new List <UserCall> { usr } }); await SendUserListUpdate(GetRoomByClassID(classid)); } else { if (usr.IsCaller) { await SendUserListUpdate(room); room.UserCalls.Add(usr); await Clients.Client(Context.ConnectionId).Reconnect(room.UserCalls.Where(u => u.ConnectionID != Context.ConnectionId).ToList()); } else { room.UserCalls.Add(usr); await SendUserListUpdate(room); room.UserCalls.ForEach(async u => { if (u != usr) { await Clients.Client(u.ConnectionID).NotifyNewMember(usr); } }); } } } }
// WebRTC Signal Handler public async Task SendSignal(string signal, string targetConnectionId) { Room callingRoom = GetRoomByConnectionID(Context.ConnectionId); UserCall callingUser = callingRoom.UserCalls.SingleOrDefault(u => u.ConnectionID == Context.ConnectionId); UserCall targetUser = callingRoom.UserCalls.SingleOrDefault(u => u.ConnectionID == targetConnectionId); // Make sure both users are valid if (callingUser == null || targetUser == null) { return; } // These folks are in a call together, let's let em talk WebRTC await Clients.Client(targetConnectionId).ReceiveSignal(callingUser, signal); }
public async Task CallUser(UserCall targetUser) { Room callingRoom = GetRoomByConnectionID(Context.ConnectionId); UserCall callingUser = callingRoom.UserCalls.SingleOrDefault(u => u.ConnectionID == Context.ConnectionId); // Make sure the person we are trying to call is still here if (targetUser == null) { // If not, let the caller know await Clients.Caller.CallDeclined(targetUser, "The user you called has left."); return; } // They are here, so tell them someone wants to talk await Clients.Client(targetUser.ConnectionID).IncomingCall(callingUser); }
private async void Page_Loaded(object sender, RoutedEventArgs e) { try { var res = await UserCall.GetUserAsync(log.Username); nameblock.Text = res.Name; emailBlock.Text = res.Email; sexBlock.Text = res.Sex; dobBLock.Text = res.DOB; addressBlock.Text = res.Address; puid = res.UID; } catch (Exception) { } }
//Saves the new game and makes the call to the server public async void saveAndCreateGame() { if (team1Player1 != null && team1Player2 != null && team2Player1 != null && team2Player2 != null) { //Save the new game and dismiss Team team1 = new Team(); team1.player1 = team1Player1; team1.player2 = team1Player2; Team team2 = new Team(); team2.player1 = team2Player1; team2.player2 = team2Player2; Game game = new Game(); game.team1 = team1; game.team2 = team2; //Get the current user and add it as the owner var plist = NSUserDefaults.StandardUserDefaults; var userId = (int)plist.IntForKey("userId"); User owner = await UserCall.getUserWithid(userId); if (owner != null) { game.owner = owner; Game createdGame = await GameCall.createGame(game); if (createdGame.id != 0 || createdGame.id != -1) { DismissViewController(true, null); } else { showAlertController("Error", "Unable to create the game"); } } } else { showAlertController("Warning", "Please select all four players"); } }
//Prepares and performs an api call to register the new user public async void handleRegisterUser() { var byteArray = IOSImageUtil.CompressImage(profileImage.Image); User user = new User(); user.username = tfUsername.Text; var userId = await UserCall.createUser(byteArray, "jpg", user); if (userId == -1) { lblWarning.Text = "Something went wrong, try again"; } else { var plist = NSUserDefaults.StandardUserDefaults; plist.SetString(tfUsername.Text, "username"); plist.SetString(imageUrl, "imageUrl"); plist.SetInt(userId, "userId"); DismissViewController(true, null); } }
public async Task AnswerCall(bool acceptCall, UserCall targetConnectionId) { Room callingRoom = GetRoomByConnectionID(Context.ConnectionId); UserCall callingUser = callingRoom.UserCalls.SingleOrDefault(u => u.ConnectionID == Context.ConnectionId); var targetUser = callingRoom.UserCalls.SingleOrDefault(u => u.ConnectionID == targetConnectionId.ConnectionID); // This can only happen if the server-side came down and clients were cleared, while the user // still held their browser session. if (callingUser == null) { return; } // Make sure the original caller has not left the page yet if (targetUser == null) { await Clients.Caller.CallEnded(targetConnectionId, "The other user in your call has left."); return; } // Send a decline message if the callee said no if (acceptCall == false) { await Clients.Client(targetConnectionId.ConnectionID).CallDeclined(callingUser, string.Format("{0} did not accept your call.", callingUser.FullName)); return; } callingUser.InCall = true; targetUser.InCall = true; // Make sure there is still an active offer. If there isn't, then the other use hung up before the Callee answered. // Tell the original caller that the call was accepted await Clients.Client(targetConnectionId.ConnectionID).CallAccepted(callingUser); // Update the user list, since thes two are now in a call //await SendUserListUpdate(); }
public async Task getConnectionID() { Room callingRoom = GetRoomByConnectionID(Context.ConnectionId); UserCall callingUser = callingRoom.UserCalls.SingleOrDefault(u => u.ConnectionID == Context.ConnectionId); await Clients.Client(Context.ConnectionId).getConnectionID(callingUser); }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.NewGame); // Get all the users from the server users = await UserCall.getUsers(); //Set click to imageView to set user ImageView newTeam1Player1Image = FindViewById <ImageView>(Resource.Id.newTeam1Player1Image); newTeam1Player1Image.SetImageResource(Resource.Mipmap.noImage); newTeam1Player1Image.Click += (object sender, EventArgs e) => { clicked = 1; createAlert(); }; //Set click to imageView to set user ImageView newTeam1Player2Image = FindViewById <ImageView>(Resource.Id.newTeam1Player2Image); newTeam1Player2Image.SetImageResource(Resource.Mipmap.noImage); newTeam1Player2Image.Click += (object sender, EventArgs e) => { clicked = 2; createAlert(); }; //Set click to imageView to set user ImageView newTeam2Player1Image = FindViewById <ImageView>(Resource.Id.newTeam2Player1Image); newTeam2Player1Image.SetImageResource(Resource.Mipmap.noImage); newTeam2Player1Image.Click += (object sender, EventArgs e) => { clicked = 3; createAlert(); }; //Set click to imageView to set user ImageView newTeam2Player2Image = FindViewById <ImageView>(Resource.Id.newTeam2Player2Image); newTeam2Player2Image.SetImageResource(Resource.Mipmap.noImage); newTeam2Player2Image.Click += (object sender, EventArgs e) => { clicked = 4; createAlert(); }; //Create a new game game = new Game(); game.team1 = new Team(); game.team2 = new Team(); Button createGame = FindViewById <Button>(Resource.Id.createGameBtn); createGame.Click += async(object sender, EventArgs e) => { if (game.team1.player1 != null && game.team2.player1 != null) { //Create a new game await GameCall.createGame(game); //Open main activity var activity = new Intent(this, typeof(MainActivity)); StartActivity(activity); } }; }