public void Subscribe_Test() { IEventBus bus = ServiceLocator.Instance.GetService <IEventBus>(); bus.UnsubscribeAll <HelloEventData>(); bus.Subscribe <HelloEventData, HelloEventHandler>(); HelloEventData data = new HelloEventData("hello world"); bus.PublishSync(data); Thread.Sleep(50); data.List.ShouldContain(data.Message); data.List.Clear(); bus.UnsubscribeAll <HelloEventData>(); Action <HelloEventData> action = m => m.List.Add(m.Message); bus.Subscribe <HelloEventData>(action); bus.PublishSync(data); Thread.Sleep(50); data.List.ShouldContain(data.Message); data.List.Clear(); bus.Unsubscribe(action); IEventHandler <HelloEventData> handler = new HelloEventHandler(); bus.Subscribe <HelloEventData>(handler); bus.PublishSync(typeof(HelloEventData), (IEventData)data); Thread.Sleep(50); data.List.ShouldContain(data.Message); data.List.Clear(); bus.Unsubscribe(handler); }
public async Task PublishAsync_Test() { IEventBus bus = ServiceLocator.Instance.GetService <IEventBus>(); bus.UnsubscribeAll <HelloEventData>(); bus.Subscribe <HelloEventData, HelloEventHandler>(); HelloEventData data = new HelloEventData("hello world"); await bus.PublishAsync(data); //Thread.Sleep(50); //data.List.ShouldContain(data.Message); //data.List.Clear(); //bus.UnsubscribeAll<HelloEventData>(); }
//TODO: Handle Resume: ///<summary> ///See <a href="https://discordapp.com/developers/docs/topics/voice-connections#resuming-voice-connection">Discord API Documentation</a> ///</summary> /// private void OnHello(HelloEventData e) { var payload = new GatewayPayload { OpCode = GatewayOpCode.Voice_Identify, Data = new VoiceIdentifyRequest { server_id = guildId, user_id = userId, session_id = sessionId, token = token } }; voiceGateway.Send(payload); heartbeatService = new VoiceHeartbeatService(voiceGateway, e.heartbeat_interval); }
private void OnHello(HelloEventData e) { heartbeatService = new HeartbeatService(gateway, e.heartbeat_interval); heartbeatService.Start(); }