Beispiel #1
0
        private void ThreadEventDispatch()
        {
            while (false == EventStop.Wait(1))
            {
                string json   = "";
                bool   pop_ok = EventJsonQueue.TryDequeue(out json);

                if (!pop_ok || json == null || json == "")
                {
                    continue;
                }

                OnEventRawString?.Invoke(this, json);

                JObject    jdata = null;
                EVENT_TYPE type  = ParseEventType(json, out jdata);

                //因為必須在conference裡面中轉各個customized header,不得已只好自己維護live channel的資料...
                //收到CHANNEL_CREATE事件時就收錄channel資訊
                //留在Conference Create時撈出來看 variable_sip_h_X-* 變數....
                switch (type)
                {
                case EVENT_TYPE.CALL_TO_SWITCH:
                    OnCall?.Invoke(this, new CCallEvent(jdata));
                    break;

                case EVENT_TYPE.SWITCH_CALL_USER:
                    OnCall?.Invoke(this, new CCallEvent(jdata));
                    break;

                case EVENT_TYPE.ANSWER:
                    OnAnswer?.Invoke(this, new CAnswerEvent(jdata));
                    break;

                case EVENT_TYPE.HANGUP:
                    OnHangUp?.Invoke(this, new CHangUpEvent(jdata));
                    break;

                case EVENT_TYPE.DESTROY_CALL:
                    OnCallDestroy?.Invoke(this, new CCallEvent(jdata));
                    break;

                case EVENT_TYPE.CONFERENCE_CREATE:
                    OnRoomCreate?.Invoke(this, new CConferenceCreateEvent(jdata));
                    break;

                case EVENT_TYPE.CONFERENCE_DELETE:
                    OnRoomDelete?.Invoke(this, new CConferenceDeleteEvent(jdata));
                    break;

                case EVENT_TYPE.JOIN_CONFERENCE:
                    OnJoinRoom?.Invoke(this, new CJoinConferenceEvent(jdata));
                    break;

                case EVENT_TYPE.LEAVE_CONFERENCE:
                    OnLeaveRoom?.Invoke(this, new CLeaveConferenceEvent(jdata));
                    break;

                case EVENT_TYPE.REGISTER:
                    OnSipRegister?.Invoke(this, new CSipRegister(jdata));
                    break;

                default:
                    Log.Warn($"Unsupported event type {type.ToString()}, skip it...");
                    break;
                }
            }

            //Queue沒有Clear(),只能用這種蠢方法清除
            while (EventJsonQueue.Count > 0)
            {
                string msg = "";
                EventJsonQueue.TryDequeue(out msg);
            }
        }