public static MyMsrpSession TakeIncomingSession(MySipStack sipStack, MsrpSession session, SipMessage message) { MyMsrpSession msrpSession = null; MediaType mediaType; SdpMessage sdp = message.getSdpMessage(); String fromUri = message.getSipHeaderValue("f"); if(String.IsNullOrEmpty(fromUri)){ LOG.Error("Invalid fromUri"); return null; } if(sdp == null){ LOG.Error("Invalid Sdp content"); return null; } String fileSelector = sdp.getSdpHeaderAValue("message", "file-selector"); mediaType = String.IsNullOrEmpty(fileSelector) ? MediaType.Chat : MediaType.FileTransfer; if (mediaType == MediaType.Chat) { msrpSession = MyMsrpSession.CreateIncomingSession(sipStack, session, mediaType, fromUri); } else { String name = null; String type = null; String[] attributes = fileSelector.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (String attribute in attributes) { String[] avp = attribute.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (avp.Length >= 2) { if (String.Equals(avp[0], "name", StringComparison.InvariantCultureIgnoreCase) && avp[1] != null) { name = avp[1].Replace("\"", String.Empty); } if (String.Equals(avp[0], "type", StringComparison.InvariantCultureIgnoreCase) && avp[1] != null) { type = avp[1]; } } } if (name == null) { LOG.Error("Invalid file name"); return null; } msrpSession = MyMsrpSession.CreateIncomingSession(sipStack, session, mediaType, fromUri); msrpSession.filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), String.Format("{0}/{1}", MyMsrpSession.DESTINATION_FOLDER, name)); msrpSession.fileType = type; } return msrpSession; }
public static MyAVSession TakeIncomingSession(MySipStack sipStack, CallSession session, twrap_media_type_t mediaType, SipMessage sipMessage) { MediaType media; lock (MyAVSession.sessions) { switch (mediaType) { case twrap_media_type_t.twrap_media_audio: media = MediaType.Audio; break; case twrap_media_type_t.twrap_media_video: media = MediaType.Video; break; case twrap_media_type_t.twrap_media_audiovideo: media = MediaType.AudioVideo; break; default: return null; } MyAVSession avSession = new MyAVSession(sipStack, session, media, InviteState.INCOMING); if (sipMessage != null) { avSession.RemotePartyUri = sipMessage.getSipHeaderValue("f"); } MyAVSession.sessions.Add(avSession.Id, avSession); return avSession; } }