/// <summary> /// Register a callback to a name with the given metadata. /// </summary> public void Register(string eventName, SocketIOCallback callback, bool onlyOnce, bool autoDecodePayload) { List <EventDescriptor> events; if (!Table.TryGetValue(eventName, out events)) { Table.Add(eventName, events = new List <EventDescriptor>(1)); } // Find a matching desriptor var desc = events.Find((d) => d.OnlyOnce == onlyOnce && d.AutoDecodePayload == autoDecodePayload); // If not found, create one if (desc == null) { events.Add(new EventDescriptor(onlyOnce, autoDecodePayload, callback)); } else // if found, add the new callback { desc.Callbacks.Add(callback); } // Log Log(); }
/// <summary> /// /// </summary> public void Unregister(string eventName, SocketIOCallback callback) { List<EventDescriptor> events; if (Table.TryGetValue(eventName, out events)) for (int i = 0; i < events.Count; ++i) events[i].Callbacks.Remove(callback); }
/// <summary> /// Constructor to create an EventDescriptor instance and set the meta-datas. /// </summary> public EventDescriptor(bool onlyOnce, bool autoDecodePayload, SocketIOCallback callback) { this.OnlyOnce = onlyOnce; this.AutoDecodePayload = autoDecodePayload; this.Callbacks = new List<SocketIOCallback>(1); if (callback != null) Callbacks.Add(callback); }
public EventDescriptor(bool onlyOnce, bool autoDecodePayload, SocketIOCallback callback) { this.OnlyOnce = onlyOnce; this.AutoDecodePayload = autoDecodePayload; this.Callbacks = new List <SocketIOCallback>(1); if (callback != null) { this.Callbacks.Add(callback); } }
public void Unregister(string eventName, SocketIOCallback callback) { if (Table.TryGetValue(eventName, out List <EventDescriptor> value)) { for (int i = 0; i < value.Count; i++) { value[i].Callbacks.Remove(callback); } } }
/// <summary> /// /// </summary> public void Unregister(string eventName, SocketIOCallback callback) { List <EventDescriptor> events; if (Table.TryGetValue(eventName, out events)) { for (int i = 0; i < events.Count; ++i) { events[i].Callbacks.Remove(callback); } } }
public void Unregister(string eventName, SocketIOCallback callback) { List <EventDescriptor> list; if (this.Table.TryGetValue(eventName, out list)) { for (int i = 0; i < list.Count; i++) { list[i].Callbacks.Remove(callback); } } }
/// <summary> /// Register a callback to a name with the given metadata. /// </summary> public void Register(string eventName, SocketIOCallback callback, bool onlyOnce, bool autoDecodePayload) { List<EventDescriptor> events; if (!Table.TryGetValue(eventName, out events)) Table.Add(eventName, events = new List<EventDescriptor>(1)); // Find a matching desriptor var desc = events.Find((d) => d.OnlyOnce == onlyOnce && d.AutoDecodePayload == autoDecodePayload); // If not found, create one if (desc == null) events.Add(new EventDescriptor(onlyOnce, autoDecodePayload, callback)); else // if found, add the new callback desc.Callbacks.Add(callback); }
/// <summary> /// Will call the callback delegates with the given parameters and remove the callbacks if this descriptor marked with a true OnlyOnce property. /// </summary> public void Call(Socket socket, Packet packet, params object[] args) { int callbackCount = Callbacks.Count; if (CallbackArray == null || CallbackArray.Length < callbackCount) { Array.Resize(ref CallbackArray, callbackCount); } // Copy the callback delegates to an array, because in one of the callbacks we can modify the list(by calling On/Once/Off in an event handler) // This way we can prevent some strange bug Callbacks.CopyTo(CallbackArray); // Go through the delegates and call them for (int i = 0; i < callbackCount; ++i) { try { // Call the delegate. SocketIOCallback callback = CallbackArray[i]; if (callback != null) { callback(socket, packet, args); } } catch (Exception ex) { // Do not try to emit a new Error when we already tried to deliver an Error, possible causing a // stack overflow if (args == null || args.Length == 0 || !(args[0] is Error)) { (socket as ISocket).EmitError(SocketIOErrors.User, ex.Message + " " + ex.StackTrace); } HTTPManager.Logger.Exception("EventDescriptor", "Call", ex); } // If these callbacks has to be called only once, remove them from the main list if (this.OnlyOnce) { Callbacks.Remove(CallbackArray[i]); } // Don't keep any reference avoiding memory leaks CallbackArray[i] = null; } }
public void Register(string eventName, SocketIOCallback callback, bool onlyOnce, bool autoDecodePayload) { if (!Table.TryGetValue(eventName, out List <EventDescriptor> value)) { Table.Add(eventName, value = new List <EventDescriptor>(1)); } EventDescriptor eventDescriptor = value.Find((EventDescriptor d) => d.OnlyOnce == onlyOnce && d.AutoDecodePayload == autoDecodePayload); if (eventDescriptor == null) { value.Add(new EventDescriptor(onlyOnce, autoDecodePayload, callback)); } else { eventDescriptor.Callbacks.Add(callback); } }
/// <summary> /// Will call the callback delegates with the given parameters and remove the callbacks if this descriptor marked with a true OnlyOnce property. /// </summary> public void Call(Socket socket, Packet packet, params object[] args) { if (CallbackArray == null || CallbackArray.Length < Callbacks.Count) { Array.Resize(ref CallbackArray, Callbacks.Count); } // Copy the callback delegates to an array, because in one of the callbacks we can modify the list(by calling On/Once/Off in an event handler) // This way we can prevent some strange bug Callbacks.CopyTo(CallbackArray); // Go through the delegates and call them for (int i = 0; i < CallbackArray.Length; ++i) { try { // Call the delegate. SocketIOCallback callback = CallbackArray[i]; if (callback != null) { callback(socket, packet, args); } } catch (Exception ex) { (socket as ISocket).EmitError(SocketIOErrors.User, ex.Message + " " + ex.StackTrace); HTTPManager.Logger.Exception("EventDescriptor", "Call", ex); SocketIOController.Instance.LogInWaitingUI(ex.Message + " " + ex.StackTrace); SocketIOController.Instance.LoginBattleUI(ex.Message + " " + ex.StackTrace); } // If these callbacks has to be called only once, remove them from the main list if (this.OnlyOnce) { Callbacks.Remove(CallbackArray[i]); } // Don't keep any reference avoiding memory leaks CallbackArray[i] = null; } }
public void On(string eventName, SocketIOCallback callback, bool autoDecodePayload) { this.EventCallbacks.Register(eventName, callback, false, autoDecodePayload); }
/// <summary> /// Register a callback for a given name /// </summary> public void On(string eventName, SocketIOCallback callback) { EventCallbacks.Register(eventName, callback, false, this.AutoDecodePayload); }
public void On(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload) { string nameFor = EventNames.GetNameFor(type); EventCallbacks.Register(nameFor, callback, onlyOnce: false, autoDecodePayload); }
public void Once(string eventName, SocketIOCallback callback) { this.EventCallbacks.Register(eventName, callback, true, this.AutoDecodePayload); }
public void Register(string eventName, SocketIOCallback callback, bool onlyOnce, bool autoDecodePayload) {
public void Once(string eventName, SocketIOCallback callback) { EventCallbacks.Register(eventName, callback, onlyOnce: true, AutoDecodePayload); }
/// <summary> /// Remove the specified callback. /// </summary> public void Off(SocketIOEventTypes type, SocketIOCallback callback) { EventCallbacks.Unregister(EventNames.GetNameFor(type), callback); }
public void Off(string eventName, SocketIOCallback fn) { m_SocketManager.Socket.Off(eventName, fn); }
public void On(SocketIOEventTypes type, SocketIOCallback callback) { string nameFor = EventNames.GetNameFor(type); this.EventCallbacks.Register(nameFor, callback, false, this.AutoDecodePayload); }
/// <summary> /// Remove the specified callback. /// </summary> public void Off(string eventName, SocketIOCallback callback) { EventCallbacks.Unregister(eventName, callback); }
public void Once(string eventName, SocketIOCallback callback, bool autoDecodePayload) { EventCallbacks.Register(eventName, callback, true, autoDecodePayload); }
public void On(string socket_event, SocketIOCallback socket_callback) { socket.On(socket_event, socket_callback); }
public void Off(SocketIOEventTypes eventTypes, SocketIOCallback fn) { m_SocketManager.Socket.Off(eventTypes, fn); }
public void On(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload) { string eventName = EventNames.GetNameFor(type); EventCallbacks.Register(eventName, callback, false, autoDecodePayload); }
public void Once(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload) { EventCallbacks.Register(EventNames.GetNameFor(type), callback, true, autoDecodePayload); }