private void _HandleConnectionFailure() { ConnectionFailed = true; if (m_RetryingConnection == false) { _StartReconnectLoop(); } OnServerUpdated?.Invoke(); // force refresh of all listeners - I hope they're checking for null! :-) return; }
/// <summary> /// Called when snapserver reports server update (= all data! requires a full ui reload) /// </summary> /// <param name="data"></param> private void _ServerUpdated(ServerData data) { if (ServerData != null) { // if we already had ServerData, make sure all UI elements know it's about to be chucked out ServerData.SERVER_Invalidate(); } ServerData = data; // if any incoming messages got queued while we were waiting for ServerData, handle them now (see Client.OnConnect local rpc method) while (m_QueuedMessages.Count > 0) { m_QueuedMessages.Dequeue()(); } // hook up events so we can update the server whenever data gets modified foreach (Group group in ServerData.groups) { foreach (JsonRpcData.Client client in group.clients) { client.config.volume.CLIENT_OnModified += () => { _OnLocalVolumeDataModified(client); }; client.CLIENT_OnNameModified += () => { _OnLocalClientNameModified(client); }; client.config.CLIENT_OnLatencyModified += () => { _OnLocalClientLatencyModified(client); }; client.CLIENT_OnRemoved += () => { _OnLocalClientRemoved(client); }; } group.SubscribeToClientEvents(); group.CLIENT_OnMuteModified += () => { _OnLocalGroupMuteModified(group); }; group.CLIENT_OnNameModified += () => { _OnLocalGroupNameModified(group); }; group.CLIENT_OnStreamModified += () => { _OnLocalGroupStreamModified(group); }; group.CLIENT_OnClientListModified += (clientIds) => { _OnLocalGroupClientListModified(group, clientIds); }; } foreach (Stream stream in ServerData.streams) { stream.CLIENT_OnControlCommand += command => { _OnStreamControlCommandSent(stream, command); }; } OnServerUpdated?.Invoke(); }
internal void UpdateServer(DiscordMediaServer server) { CurrentServer = server; Log($"Set server to {server.Endpoint}"); State = MediaSessionState.StandBy; if (server.Endpoint != null && WebSocket != null) { Log("Changing server"); Task.Run(() => Connect()); } if (OnServerUpdated != null) { Task.Run(() => OnServerUpdated.Invoke(this, server)); } }
/// <summary> /// Updates the Server message /// </summary> internal static void ServerUpdate() { if (!AutoFollow.Enabled) { return; } if (!IsValid) { Log.Info("Server is Invalid", Service.ConnectionMode); ShutdownServer(); ServerInitialize(); return; } if (DateTime.UtcNow.Subtract(LastServerUpdate).TotalMilliseconds < Settings.Network.UpdateInterval) { return; } ProcessClientMessages(); UpdateDataAsServer(); Log.Debug("Communicating with {0} other bots:", AutoFollow.NumberOfConnectedBots); if (DateTime.UtcNow.Subtract(LastSummaryTime).TotalSeconds > 2) { Log.Debug("{0}", AutoFollow.ServerMessage.ShortSummary); foreach (var otherMessage in AutoFollow.ClientMessages.Values) { Log.Debug("{0}", otherMessage.ShortSummary); } LastSummaryTime = DateTime.UtcNow; } if (OnServerUpdated != null) { OnServerUpdated.Invoke(AutoFollow.ClientMessages); } LastServerUpdate = DateTime.UtcNow; }
/// <summary> /// Adds a server tag item to this list, or updates it if a sever with that address already exists /// </summary> /// <param name="tag">The server tag to add</param> public void AddItem(ServerTag tag) { int slot = myBackingList.FindIndex(X => X.Address == tag.Address); if (slot != -1) { if (myBackingList[slot] != tag) { OnServerUpdated?.Invoke(this, tag); } myBackingList[slot] = tag; } else { myBackingList.Add(tag); OnNewServerDiscovered?.Invoke(this, tag); } }