public void Run()
 {
     codec         = new DouyuCodec();
     ws            = new WebSocket(serverUrl);
     ws.OnMessage += WsOnMessage;
     ws.OnOpen    += WsOnOpen;
     ws.OnClose   += WsOnClose;
     ws.OnError   += WsOnError;
     ws.Connect();
 }
 public void Stop()
 {
     if (ws != null)
     {
         JObject obj = new JObject
         {
             ["type"] = "logout"
         };
         Send(obj);
         ws.Close();
         ws = null;
     }
     if (heartbeat != null)
     {
         heartbeat.Dispose();
         heartbeat = null;
     }
     callbacks     = new Dictionary <string, MessageHandler>();
     codec         = null;
     OnChatMessage = null;
 }