Example #1
0
        public Dictionary <string, string> emoji_map; //emoji映射
        public MainWindow()
        {
            try {
                InitializeComponent();

                // init
                AppendLog("Welcome to DanmakuChi CSharp Client!");
                //读取弹幕配置文件
                emoji_map = new Dictionary <string, string>();
                var    con_moj   = File.ReadAllText("../emoji_con");
                var    input_moj = new StringReader(con_moj);
                string tmp;
                while ((tmp = input_moj.ReadLine()) != null)
                {
                    string[] sArray = tmp.Split(',');
                    emoji_map.Add(sArray[1], sArray[0]);
                }
                //chkShadow.IsChecked = config.Advanced.enableShadow;
                textServer.Text = "ws://192.168.191.1:8686";
                //textChannel.Text = "aitucao";
                aiTuCaoMsg = new AiTuCaoMsg();
            } catch (Exception e) {
                AppendLog(e.Message);
            }
        }
Example #2
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (!isConnected)
            {
                btnConnect.Content   = "Connecting...";
                btnConnect.IsEnabled = false;

                var server  = textServer.Text;
                var channel = textChannel.Text;

                //ws = new WebSocket(server + "/ws?channel=" + channel);
                ws         = new WebSocket(server);
                ws.OnOpen += (s, ee) => {
                    //AppendLog("connected!");
                    btnConnect.Content   = "DisConnect";
                    btnConnect.IsEnabled = true;
                    isConnected          = true;

                    aiTuCaoMsg.type = "CREATE_ROOM";
                    aiTuCaoMsg.data = textChannel.Text;
                    string json = JsonConvert.SerializeObject(aiTuCaoMsg);
                    ws.Send(json);
                };
                ws.OnMessage += (s, ee) => {
                    Console.WriteLine(ee.Data.ToString());
                    recvBody = ee.Data.ToString();
                    // 反序列化Json的字符串
                    AiTuCaoMsg jsonRecvBody = JsonConvert.DeserializeObject <AiTuCaoMsg>(recvBody);

                    switch (jsonRecvBody.type)
                    {
                    case "ROOM_ID":     // 房间号
                        // 逻辑:为二维码的增加url,并初始化InitDanmuku()
                        qrCodeUrl = jsonRecvBody.data;
                        InitDanmaku();
                        break;

                    case "TEXT":
                        ShootDanmaku(jsonRecvBody.data, 0);
                        break;

                    case "EMOJ":
                    {
                        string tmp = "";
                        emoji_map.TryGetValue(jsonRecvBody.data, out tmp);        //传进去"[鬼脸]"等emoji代码
                        string path = "../emoji/" + tmp;
                        ShootDanmaku(path, 1);
                        break;
                    }

                    case "PICTURE":
                        ShootDanmaku(jsonRecvBody.data, 2);
                        break;

                    default:
                        break;
                    }
                };
                ws.OnClose += (s, ee) => {
                    AppendLog("Disconnected!");
                };
                ws.Connect();
            }
            else
            {
                CancelDMK();
            }
        }