public override int OnEvent(MsrpEvent e) { MsrpSession session = e.getSipSession(); MsrpMessage message = e.getMessage(); if (session != null && message != null) { uint id = session.getId(); //Console.WriteLine("Msrp Event {0} {1}", id, message.getMsrpHeaderValue("Byte-Range")); long start, end, total; //message.getByteRange(out start, out end, out total); //Console.WriteLine("Byte-Range {0}-{1}/{2}", start, end, total); //if (message.isRequest()) // { // uint size = message.getMsrpContentLength(); // byte[] bytes = new byte[(int)size]; // message.getMsrpContent(bytes, (uint)bytes.Length); // } if (!message.isRequest() && message.getCode() == 200) { if (message.isLastChunck()) { session.hangup(); } } } return(0); }
public override int OnEvent(MsrpEvent e) { tmsrp_event_type_t type = e.getType(); SipSession session = e.getSipSession(); int result; if (session == null || (ulong)session.getId() != (ulong)this.session.Id) { MyMsrpSession.LOG.Error("Invalid session"); result = -1; } else { switch (type) { case tmsrp_event_type_t.tmsrp_event_type_connected: { MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.CONNECTED); eargs.AddExtra("session", this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.mOnMsrpEvent, this.session, eargs); if (this.session.mPendingMessages != null && this.session.mPendingMessages.Count > 0) { if (this.session.IsConnected) { foreach (MyMsrpSession.PendingMessage pendingMsg in this.session.mPendingMessages) { MyMsrpSession.LOG.Info("Sending pending message..."); this.session.SendMessage(pendingMsg.Message, pendingMsg.ContentType, pendingMsg.WContentType); } this.session.mPendingMessages.Clear(); } else { MyMsrpSession.LOG.Warn("There are pending messages but we are not connected"); } } break; } case tmsrp_event_type_t.tmsrp_event_type_disconnected: { if (this.session.mOutFileStream != null) { lock (this.session.mOutFileStream) { if (this.session.mOutFileStream != null) { this.session.mOutFileStream.Close(); this.session.mOutFileStream = null; } } } MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.DISCONNECTED); eargs.AddExtra("session", this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.mOnMsrpEvent, this.session, eargs); break; } case tmsrp_event_type_t.tmsrp_event_type_message: { MsrpMessage message = e.getMessage(); if (message == null) { MyMsrpSession.LOG.Error("Invalid MSRP content"); result = -1; return(result); } if (message.isRequest()) { this.ProcessRequest(message); } else { this.ProcessResponse(message); } break; } } result = 0; } return(result); }