private void Socket_OnError(object sender, ErrorEventArgs e)
 {
     if (OnWSError != null)
     {
         OnWSError.Invoke(sender, new WSErrorEventArgs(e.Message, Url)
         {
             Exception = e.Exception, Tag = e
         });
     }
 }
    public AntMediaSignaling(string url)
    {
        jsonSettings = new JsonSerializerSettings
        {
            NullValueHandling = NullValueHandling.Ignore
        };
        context = SynchronizationContext.Current;
        ws      = new WebSocket(url);
        ws.SslConfiguration.EnabledSslProtocols = sslProtocolHack;

        ws.OnOpen += (s, e) =>
        {
            context.Post(_ =>
            {
                OnOpen.Invoke();
            }, null);
        };
        ws.OnMessage += (s, e) =>
        {
            context.Post(_ =>
            {
                //log.AppendLine($"({e.Data})");
                var msg = JsonUtility.FromJson <AntMediaSignalingMessage>(e.Data);
                ProcessMessage(msg);
            }, null);
        };
        ws.OnClose += (s, e) =>
        {
            context.Post(_ =>
            {
                OnClose.Invoke();
            }, null);
        };
        ws.OnError += (s, e) =>
        {
            context.Post(_ =>
            {
                OnWSError.Invoke(e.Message);
            }, null);
        };
    }