public async Task NoAcksOrHandlerNotifications() { // Arrange var serializer = new NewtonSoftJsonSerializer(); var logger = new NullLogger <SocketIoClient>(); var opts = new SocketIoClientOptions( serializer, logger, Encoding.UTF8 ); var client = new SocketIoClient(opts); client.Events.OnConnect.Subscribe( args => Log($"[1] Connected: {args}")); client.Events.OnPacket.Subscribe(packet => { Log($"[1] Received packet: {packet}"); }); string clientId1 = null; client.Events.OnHandshake.Subscribe(res => { clientId1 = res.Sid; }); // Act await client.OpenAsync(new Uri("http://localhost:3300")); var data1 = new Payload() { Id = 42, Name = "Douglas Adams" }; var data2 = new Payload() { Id = 86, Name = "Carl Sagan" }; while (clientId1 is null) { Thread.Sleep(50); } client.On("/consume") .Subscribe(message => { Log($"Received notification: {message.EventName}, data: {message.Data}"); }); Log($"- subscribe to 'test' topic {clientId1} -"); client.Emit("/subscribe", new SubscribeRequest( clientId1, "test", 0, 10, 0 ) ).Subscribe(ack => { Log($"subscribe ack: {ack}"); }); Log("- about to publish - "); client.Emit("/publish", new PublishRequest { Topic = "test", Channel = 1, Message = JsonConvert.SerializeObject(data1) } ).Subscribe(ack => { Log($"publish ack: {JsonConvert.SerializeObject(ack)}"); }); client.Emit("/publish", new PublishRequest { Topic = "test", Channel = 1, Message = JsonConvert.SerializeObject(data1) } ).Subscribe(ack => { Log($"publish ack: {JsonConvert.SerializeObject(ack)}"); }); // Assert Log("- waiting for 2s just in case -"); await Task.Delay(2000); Log("- test ends -"); }
public static Task OpenTestAsync(this SocketIoClient client, Uri uri = null, string path = "some-path") { uri ??= new Uri("http://localhost:8764"); return(client.OpenAsync(uri, new SocketIoOpenOptions(path))); }