Task ISpectatorClient.UserBeganPlaying(int userId, SpectatorState state) { lock (userLock) { if (!playingUsers.Contains(userId)) { playingUsers.Add(userId); } playingUserStates[userId] = state; } OnUserBeganPlaying?.Invoke(userId, state); return(Task.CompletedTask); }
Task ISpectatorClient.UserFinishedPlaying(int userId, SpectatorState state) { Schedule(() => { playingUsers.Remove(userId); if (watchedUsers.Contains(userId)) { watchedUserStates[userId] = state; } OnUserFinishedPlaying?.Invoke(userId, state); }); return(Task.CompletedTask); }
Task ISpectatorClient.UserBeganPlaying(int userId, SpectatorState state) { Schedule(() => { if (!playingUsers.Contains(userId)) { playingUsers.Add(userId); } if (watchedUsers.Contains(userId)) { watchedUserStates[userId] = state; } OnUserBeganPlaying?.Invoke(userId, state); }); return(Task.CompletedTask); }
Task ISpectatorClient.UserBeganPlaying(int userId, SpectatorState state) { Schedule(() => { if (!playingUsers.Contains(userId)) { playingUsers.Add(userId); } // UserBeganPlaying() is called by the server regardless of whether the local user is watching the remote user, and is called a further time when the remote user is watched. // This may be a temporary thing (see: https://github.com/ppy/osu-server-spectator/blob/2273778e02cfdb4a9c6a934f2a46a8459cb5d29c/osu.Server.Spectator/Hubs/SpectatorHub.cs#L28-L29). // We don't want the user states to update unless the player is being watched, otherwise calling BindUserBeganPlaying() can lead to double invocations. if (watchingUsers.Contains(userId)) { playingUserStates[userId] = state; } OnUserBeganPlaying?.Invoke(userId, state); }); return(Task.CompletedTask); }
protected override async Task BeginPlayingInternal(SpectatorState state) { if (!IsConnected.Value) { return; } Debug.Assert(connection != null); try { await connection.SendAsync(nameof(ISpectatorServer.BeginPlaySession), state); } catch (HubException exception) { if (exception.GetHubExceptionMessage() == HubClientConnector.SERVER_SHUTDOWN_MESSAGE) { connector?.Reconnect(); } throw; } }
Task ISpectatorClient.UserFinishedPlaying(int userId, SpectatorState state) { playingUsers.Remove(userId); return(Task.CompletedTask); }
protected abstract Task EndPlayingInternal(SpectatorState state);
/// <summary> /// Attempts to retrieve the <see cref="SpectatorState"/> for a currently-playing user. /// </summary> /// <param name="userId">The user.</param> /// <param name="state">The current <see cref="SpectatorState"/> for the user, if they're playing. <c>null</c> if the user is not playing.</param> /// <returns><c>true</c> if successful (the user is playing), <c>false</c> otherwise.</returns> public bool TryGetPlayingUserState(int userId, out SpectatorState state) { lock (userLock) return(playingUserStates.TryGetValue(userId, out state)); }