internal void SetServer(DiscordMediaServer server) { _ssrcToUserDictionary.Clear(); _receivers.Clear(); if (_guildId.HasValue) { Livestream = new DiscordLivestreamClient(_client, _guildId.Value, _channelId.Value); } Connection = new DiscordMediaConnection(_client, server.Guild == null ? _channelId.Value : server.Guild.Id, server); Connection.OnReady += (c) => { Microphone = new DiscordVoiceInput(this); Connection.SetSSRC(Connection.SSRC.Audio); _client.TriggerVCConnect(this); }; Connection.OnMessage += Connection_OnMessage; Connection.OnUdpPacket += Connection_OnUdpPacket; Connection.OnDead += Connection_OnDead; Connection.Connect(); }
public DiscordMediaConnection(DiscordSocketClient parentClient, ulong serverId, DiscordMediaServer server) : base("wss://" + server.Endpoint + "?v=4") { _parentClient = parentClient; _server = server; _serverId = serverId; OnMessageReceived += HandleMessage; OnClosed += HandleClose; }
internal void SetSessionServer(ulong userId, DiscordMediaServer server) { if (userId == Client.User.Id) { Own.UpdateServer(server); } else { _watching[userId].UpdateServer(server); } }
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)); } }
internal void UpdateServer(DiscordMediaServer server) { _connection = new DiscordMediaConnection(Client, _rtcServerId, server); _connection.OnReady += (c) => { if (StreamerId == Client.User.Id) { Client.Send(GatewayOpcode.GoLiveUpdate, new StreamUpdate() { StreamKey = StreamKey, Paused = false }); } OnConnected?.Invoke(this); }; _connection.OnMessage += HandleMessage; _connection.Connect(); }