You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

37 lines
1.6 KiB

  1. using DotNetty.Buffers;
  2. using DotNetty.Codecs.Http;
  3. using DotNetty.Codecs.Http.WebSockets;
  4. using DotNetty.Common.Utilities;
  5. using JT1078.Gateway.Metadata;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Text;
  9. namespace JT1078.Gateway.Extensions
  10. {
  11. public static class JT1078HttpSessionExtensions
  12. {
  13. private static readonly AsciiString ServerName = AsciiString.Cached("JT1078Netty");
  14. private static readonly AsciiString DateEntity = HttpHeaderNames.Date;
  15. private static readonly AsciiString ServerEntity = HttpHeaderNames.Server;
  16. public static void SendBinaryWebSocketAsync(this JT1078HttpSession session,byte[] data)
  17. {
  18. session.Channel.WriteAndFlushAsync(new BinaryWebSocketFrame(Unpooled.WrappedBuffer(data)));
  19. }
  20. public static void SendHttpFirstChunkAsync(this JT1078HttpSession session, byte[] data)
  21. {
  22. DefaultHttpResponse firstRes = new DefaultHttpResponse(HttpVersion.Http11, HttpResponseStatus.OK);
  23. firstRes.Headers.Set(ServerEntity, ServerName);
  24. firstRes.Headers.Set(DateEntity, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
  25. firstRes.Headers.Set(HttpHeaderNames.ContentType, (AsciiString)"video/x-flv");
  26. HttpUtil.SetTransferEncodingChunked(firstRes, true);
  27. session.Channel.WriteAsync(firstRes);
  28. session.Channel.WriteAndFlushAsync(Unpooled.CopiedBuffer(data));
  29. }
  30. public static void SendHttpOtherChunkAsync(this JT1078HttpSession session, byte[] data)
  31. {
  32. session.Channel.WriteAndFlushAsync(Unpooled.CopiedBuffer(data));
  33. }
  34. }
  35. }