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(); if (session == null || session.getId() != this.session.Id) { LOG.Error("Invalid session"); return -1; } switch (type) { case tmsrp_event_type_t.tmsrp_event_type_connected: { MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.CONNECTED); eargs.AddExtra(MsrpEventArgs.EXTRA_SESSION, this.session); EventHandlerTrigger.TriggerEvent<MsrpEventArgs>(this.session.onMsrpEvent, this.session, eargs); if (this.session.pendingMessages != null && this.session.pendingMessages.Count > 0) { if (this.session.IsConnected) { foreach (PendingMessage pendingMsg in this.session.pendingMessages) { LOG.Info("Sending pending message..."); this.session.SendMessage(pendingMsg.Message, pendingMsg.ContentType, pendingMsg.WContentType); } this.session.pendingMessages.Clear(); } else { LOG.Warn("There are pending messages but we are not connected"); } } break; } case tmsrp_event_type_t.tmsrp_event_type_disconnected: { if (this.session.outFileStream != null) { lock (this.session.outFileStream) { if (this.session.outFileStream != null) { this.session.outFileStream.Close(); this.session.outFileStream = null; } } } MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.DISCONNECTED); eargs.AddExtra(MsrpEventArgs.EXTRA_SESSION, this.session); EventHandlerTrigger.TriggerEvent<MsrpEventArgs>(this.session.onMsrpEvent, this.session, eargs); break; } case tmsrp_event_type_t.tmsrp_event_type_message: { MsrpMessage message = e.getMessage(); if (message == null) { LOG.Error("Invalid MSRP content"); return -1; } if (message.isRequest()) { this.ProcessRequest(message); } else { this.ProcessResponse(message); } break; } default: break; } return 0; }