//---------------------------------------------------------------------------------------------------- // return message format void Send(string id, string msg, string data) { var sb = new StringBuilder(); sb.Append("{"); if (String.IsNullOrEmpty(id) == false) { sb.AppendFormat(@"""id"":{0},", JsonTypeConverters.EscapedString(id)); } sb.AppendFormat(@"""{0}"":{1}", msg, data); sb.Append("}"); mSocket.SendAsync(sb.ToString()); }
// unbind an event public void Unbind(string id) { var num = mListeners.Count; if (id == "*") { mListeners.ForEach(i => i.Unbind()); mListeners.Clear(); } else { mListeners.ForEach(i => { if (i.Message.id == id) { i.Unbind(); } }); mListeners.RemoveAll(i => i.Message.id == id); } if (mListeners.Count == num) { Send(id, "error", JsonTypeConverters.EscapedString("not found")); } }
//---------------------------------------------------------------------------------------------------- // handler interface // stop a repeater public void Stop(string id) { var num = mRepeaters.Count; if (id == "*") { mRepeaters.ForEach(r => r.Cancel()); mRepeaters.Clear(); } else { mRepeaters.ForEach(s => { if (s.ID == id) { s.Cancel(); } }); mRepeaters.RemoveAll(s => s.IsFinished); } if (mRepeaters.Count == num) { Send(id, "error", JsonTypeConverters.EscapedString("not found")); } }
public void Error(ResponseCode code) { Socket.Send(id, "error", JsonTypeConverters.EscapedString(HttpUtils.CodeToString(code))); }
public void Info(string msg) { Socket.Send(id, "info", JsonTypeConverters.EscapedString(msg)); }
public void Info(string msg) { SendImpl(ID, "info", JsonTypeConverters.EscapedString(msg)); }