public IHttpActionResult CreatePublicChannel(ChatCreatePublicChannelMessage message) { var channel = this.GameManager.ChatManager.CreatePublicChannel(this.WarsimUser, message.ChannelName); NotificationManager.Create(this.GameManager, this.DbContext).SendPublicChannelInvite(channel, message.ParticipantsIds); return(this.Ok(channel.Id)); }
private static void Create_channel_then_join_then_send_message() { WaitFor("Create channel"); var postData = new ChatCreatePublicChannelMessage { ChannelName = "Channel de test", ParticipantsIds = new List <string>() }; var result = HttpRequestHelper.PostAsync("http://127.0.0.1:4321/api/chat/channel", postData, Token).Result; var channelId = JsonConvert.DeserializeObject <Guid>(result.Content.ReadAsStringAsync().Result); WaitFor("Join channel"); var chatWebSocket = new WebSocketClient($"ws://127.0.0.1:6789/Chat?auth_token={Token}&channel_id={channelId}"); chatWebSocket.RegisterHandler((UserJoinedChannelMessage msg, DateTime timestamp) => { Console.WriteLine($"Utilisateur connecté {msg.Username}"); }); chatWebSocket.OnCloseHandler = (o, args) => { Console.WriteLine($"{args.Code}: {args.Reason}"); }; chatWebSocket.Connect(); WaitFor("Send chat message"); chatWebSocket.Send(EventBuilder.Build(new ChatMessageMessage { Content = "Hello channel!" }).Serialize()); WaitFor("Exit channel"); chatWebSocket.Close(); }