# src/EventManager.js

    function EventManager() {
      const definedEvents = [
        'onInit',
        'onConnectChannel',
        'onCreateChannel',
        'onComplete',
        'onDisplayUserMedia',
        'onAddLocalStream',
        'onAddRemoteStream',
        'onStateChange',
        'onDisconnectChannel',
        'onMessage',
        'onError',
        'onStat',
        'onSearch',
      ];
      const listeners = new Map(definedEvents.map(item => [item]));

      function addEventListener({ type, listenerItem }) {
        if (typeof listenerItem !== 'function') {
          throw new Error('EventManager:listenerMustBeAFunction');
        } else if (!definedEvents.includes(type)) {
          throw new Error('EventManager:UnmatchedEvent');
        } else {
          listeners.set(type, listenerItem);
        }
      }

      function hasEventListener(type) {
        if (!definedEvents.includes(type)) {
          throw new Error('EventManager:UnmatchedEvent');
        } else if (typeof listeners.get(type) === 'undefined') {
          return false;
        } else {
          return true;
        }
      }

      function removeEventListener(type) {
        if (definedEvents.includes(type) && listeners.has(type)) {
          listeners.set(type, undefined);
        } else {
          throw new Error('EventManager:UnmatchedEventOrDidNotContainAnylistener');
        }
      }

      function getEventListeners() {
        return listeners;
      }

      function dispatchEvent(type, ...args) {
        if (!definedEvents.includes(type)) {
          throw new Error('EventManager:UnmatchedEvent');
        } else if (typeof listeners.get(type) === 'undefined') {
          //throw new Error('EventManager:Undefinedlistener');
          return;
        } else {
          return listeners.get(type)(...args);
        }
      }

      return Object.freeze({
        addEventListener,
        hasEventListener,
        removeEventListener,
        getEventListeners,
        dispatchEvent,
      });
    }

    export default EventManager;