static void Main(string[] args) { loadConfig(); if (!_configDictionary.ContainsKey("username") || !_configDictionary.ContainsKey("password")) { return; } BeamWeb bWeb = new BeamWeb(); Task <BeamUser> res = bWeb.Authenticate(_configDictionary["username"], _configDictionary["password"]); BeamUser user = res.Result; if (user == null) { throw new ArgumentException("Login incorrect?"); } BeamChatInfo chatInfo = bWeb.ChatInfo(user.channel.id).Result; if (chatInfo == null || chatInfo.endpoints.Count == 0) { throw new ArgumentException("Channel Id incorrect?"); } Console.WriteLine("UserID: {0}, ChannelID: {1}", user.id, user.channel.id); BeamChat bChat = new BeamChat(); bChat.SetupWebsocket(chatInfo.endpoints[0]); bChat.SetupCredentials(user.id, user.channel.id, chatInfo.authkey); bChat.Connect(); BeamEventHandler.AddEventHandler(EventHandlerTypes.ChatMessageEvent, (message, underlayingMessage) => { BeamEventChatMessage chatMessage = JsonConvert.DeserializeObject <BeamEventChatMessage>(underlayingMessage); Console.WriteLine("Received Chat message: {0}", chatMessage.data.message.message[0].text); }); Console.ReadKey(); bChat.Disconnect(); /*BeamChat beamChat = new BeamChat(); * * beamChat.SetupCredentials(""); * * beamChat.SetupWebsocket("wss://chat3-dal.beam.pro"); * beamChat.Connect(); * while (true) * { * Thread.Sleep(5000); * }*/ /* * beamChat.websocket_MessageReceived(null, new MessageReceivedEventArgs("{\"type\":\"event\",\"event\":\"WelcomeEvent\",\"data\":{\"server\":\"891c12de-d4f8-4b4f-971f-5e69b6b65075\"}}"));*/ }
private static void SendLoginEvent() { var args = new List <string> { BeamChat.ChannelId }; if (!string.IsNullOrEmpty(BeamChat.AuthKey) && !string.IsNullOrEmpty(BeamChat.ChannelId) && !string.IsNullOrEmpty(BeamChat.UserId)) { args.Add(BeamChat.UserId); // UserID args.Add(BeamChat.AuthKey); } else if (!string.IsNullOrEmpty(BeamChat.Username) && !string.IsNullOrEmpty(BeamChat.Password)) { // WARNING: This is unsecure and NOT recommended! var beamWeb = new BeamWeb(); var user = beamWeb.Authenticate(BeamChat.Username, BeamChat.Password).Result; if (user == null) { return; } var chat = beamWeb.ChatInfo(user.channel.id).Result; if (string.IsNullOrEmpty(chat.authkey)) { return; } args.Clear(); args.Add(user.channel.id.ToString()); args.Add(user.id.ToString()); args.Add(chat.authkey); } BeamChat.SendBeamMessage(new BeamMethodMessage { method = "auth", arguments = args }, replyMessage => { if (!(bool)replyMessage.data["authenticated"] && !string.IsNullOrEmpty(BeamChat.Username) && !string.IsNullOrEmpty(BeamChat.Password) ) { throw new Exception("Chat authentication failed!"); } }); }
public void Test_ChatConnect() { BeamWeb bWeb = new BeamWeb(); Task <BeamChatInfo> res = bWeb.ChatInfo(197242); BeamChatInfo chatInfo = res.Result; if (chatInfo == null || chatInfo.endpoints.Count == 0) { Assert.Fail("Could not get chatinfo"); } BeamChat bChat = new BeamChat(); bChat.SetupWebsocket(chatInfo.endpoints[0]); bChat.Connect(); bChat.Disconnect(); Assert.Pass("Successfully connected to beam chat subtixx!"); }