/// <summary> /// Call (MSRP, Audio, Video, T.38, ...) events /// </summary> /// <param name="e"></param> /// <returns></returns> public override int OnInviteEvent(InviteEvent e) { tsip_invite_event_type_t type = e.getType(); short code = e.getCode(); String phrase = e.getPhrase(); InviteSession session = e.getSession(); switch (type) { case tsip_invite_event_type_t.tsip_i_newcall: if (session != null) /* As we are not the owner, then the session MUST be null */ { LOG.Error("Invalid incoming session"); session.hangup(); // To avoid another callback event return -1; } SipMessage message = e.getSipMessage(); if (message == null) { LOG.Error("Invalid message"); return -1; } twrap_media_type_t sessionType = e.getMediaType(); switch (sessionType) { case twrap_media_type_t.twrap_media_msrp: { if ((session = e.takeMsrpSessionOwnership()) == null) { LOG.Error("Failed to take MSRP session ownership"); return -1; } MyMsrpSession msrpSession = MyMsrpSession.TakeIncomingSession(this.sipService.SipStack, session as MsrpSession, message); if (msrpSession == null) { LOG.Error("Failed to create new session"); session.hangup(); session.Dispose(); return 0; } msrpSession.State = MyInviteSession.InviteState.INCOMING; InviteEventArgs eargs = new InviteEventArgs(msrpSession.Id, InviteEventTypes.INCOMING, phrase); eargs.AddExtra(InviteEventArgs.EXTRA_SESSION, msrpSession); EventHandlerTrigger.TriggerEvent<InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, eargs); break; } case twrap_media_type_t.twrap_media_audio: case twrap_media_type_t.twrap_media_audiovideo: case twrap_media_type_t.twrap_media_video: { if ((session = e.takeCallSessionOwnership()) == null) { LOG.Error("Failed to take audio/video session ownership"); return -1; } MyAVSession avSession = MyAVSession.TakeIncomingSession(this.sipService.SipStack, session as CallSession, sessionType, message); avSession.State = MyInviteSession.InviteState.INCOMING; InviteEventArgs eargs = new InviteEventArgs(avSession.Id, InviteEventTypes.INCOMING, phrase); eargs.AddExtra(InviteEventArgs.EXTRA_SESSION, avSession); EventHandlerTrigger.TriggerEvent<InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, eargs); break; } default: LOG.Error("Invalid media type"); return 0; } break; case tsip_invite_event_type_t.tsip_ao_request: if (code == 180 && session != null) { EventHandlerTrigger.TriggerEvent<InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.RINGING, phrase)); } break; case tsip_invite_event_type_t.tsip_i_request: case tsip_invite_event_type_t.tsip_o_ect_ok: case tsip_invite_event_type_t.tsip_o_ect_nok: case tsip_invite_event_type_t.tsip_i_ect: { break; } case tsip_invite_event_type_t.tsip_m_early_media: { EventHandlerTrigger.TriggerEvent<InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.EARLY_MEDIA, phrase)); break; } case tsip_invite_event_type_t.tsip_m_local_hold_ok: { EventHandlerTrigger.TriggerEvent<InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.LOCAL_HOLD_OK, phrase)); break; } case tsip_invite_event_type_t.tsip_m_local_hold_nok: { EventHandlerTrigger.TriggerEvent<InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.LOCAL_HOLD_NOK, phrase)); break; } case tsip_invite_event_type_t.tsip_m_local_resume_ok: { EventHandlerTrigger.TriggerEvent<InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.LOCAL_RESUME_OK, phrase)); break; } case tsip_invite_event_type_t.tsip_m_local_resume_nok: { EventHandlerTrigger.TriggerEvent<InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.LOCAL_RESUME_NOK, phrase)); break; } case tsip_invite_event_type_t.tsip_m_remote_hold: { EventHandlerTrigger.TriggerEvent<InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.REMOTE_HOLD, phrase)); break; } case tsip_invite_event_type_t.tsip_m_remote_resume: { EventHandlerTrigger.TriggerEvent<InviteEventArgs>(this.sipService.onInviteEvent, this.sipService, new InviteEventArgs(session.getId(), InviteEventTypes.REMOTE_RESUME, phrase)); break; } } return 0; }
public override int OnInviteEvent(InviteEvent e) { tsip_invite_event_type_t type = e.getType(); InviteSession session = e.getSession(); SipMessage message = e.getSipMessage(); switch(type){ case tsip_invite_event_type_t.tsip_i_newcall: SdpMessage sdp = message.getSdpMessage(); if (session != null){ Console.WriteLine("ERRRRRRRRRRRORRRR"); return 0; } else{ switch(e.getMediaType()){ case twrap_media_type_t.twrap_media_audio: case twrap_media_type_t.twrap_media_video: case twrap_media_type_t.twrap_media_audiovideo: session = e.takeCallSessionOwnership(); break; case twrap_media_type_t.twrap_media_msrp: if ((session = e.takeMsrpSessionOwnership()) != null){ (session as MsrpSession).setCallback(Program.msrpCallback); } break; } if(session != null){ ActionConfig actionConfig = new ActionConfig(); session.accept(actionConfig); actionConfig.Dispose(); } } /*else if ((session = e.takeSessionOwnership()) != null) { SdpMessage sdp = message.getSdpMessage(); if (sdp != null) { String fileSelector = sdp.getSdpHeaderAValue("message", "file-selector"); Console.WriteLine("file-selector={0}", fileSelector); } ActionConfig actionConfig = new ActionConfig(); //actionConfig.setMediaInt(twrap_media_type_t.twrap_media_audiovideo, "bandwidth-level", (int)tmedia_bandwidth_level_t.tmedia_bl_low); actionConfig.setMediaString(twrap_media_type_t.twrap_media_file, "file-path", "C:\\tmp\\myfile"); session.accept(actionConfig); actionConfig.Dispose(); }*/ break; case tsip_invite_event_type_t.tsip_i_request: break; case tsip_invite_event_type_t.tsip_ao_request: break; case tsip_invite_event_type_t.tsip_o_ect_ok: break; case tsip_invite_event_type_t.tsip_o_ect_nok: break; case tsip_invite_event_type_t.tsip_i_ect: break; case tsip_invite_event_type_t.tsip_m_local_hold_ok: Console.WriteLine("Local Hold OK"); break; case tsip_invite_event_type_t.tsip_m_local_hold_nok: Console.WriteLine("Local Hold NOK"); break; case tsip_invite_event_type_t.tsip_m_local_resume_ok: Console.WriteLine("Local Resume OK"); break; case tsip_invite_event_type_t.tsip_m_local_resume_nok: Console.WriteLine("Local Resume NOK"); break; case tsip_invite_event_type_t.tsip_m_remote_hold: Console.WriteLine("Remote Hold"); break; case tsip_invite_event_type_t.tsip_m_remote_resume: Console.WriteLine("Remote Resume"); break; } return 0; }