stream-cut.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package http
  2. import (
  3. "fmt"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. "go-common/library/net/metadata"
  7. "strconv"
  8. )
  9. // cutStream 切流, 内部调用
  10. func cutStream(c *bm.Context) {
  11. // roomid 必须
  12. params := c.Request.URL.Query()
  13. room := params.Get("room_id")
  14. cutTime := params.Get("cut_time")
  15. c.Set("input_params", params)
  16. // 验证传参数
  17. roomID, err := strconv.ParseInt(room, 10, 64)
  18. if err != nil || roomID <= 0 {
  19. c.Set("output_data", "roomid is not right")
  20. c.JSONMap(map[string]interface{}{"message": "roomid is not right"}, ecode.RequestErr)
  21. c.Abort()
  22. return
  23. }
  24. // 默认切流时间为1s,可以传入-1
  25. ct, err := strconv.ParseInt(cutTime, 10, 64)
  26. if err != nil || ct == 0 {
  27. ct = 1
  28. }
  29. srv.StreamCut(c, roomID, ct, 0)
  30. c.Set("output_data", "ok")
  31. c.JSONMap(map[string]interface{}{"data": map[string]int{}}, nil)
  32. }
  33. // cutStreamByExt 外部调用
  34. func cutStreamByMobile(c *bm.Context) {
  35. // roomid 必须
  36. params := c.Request.URL.Query()
  37. room := params.Get("room_id")
  38. cutTime := params.Get("cut_time")
  39. c.Set("input_params", params)
  40. // 验证传参数
  41. roomID, err := strconv.ParseInt(room, 10, 64)
  42. if err != nil || roomID <= 0 {
  43. c.Set("output_data", "roomid is not right")
  44. c.JSONMap(map[string]interface{}{"message": "roomid is not right"}, ecode.RequestErr)
  45. c.Abort()
  46. return
  47. }
  48. // 默认切流时间为1s,可以传入-1
  49. ct, err := strconv.ParseInt(cutTime, 10, 64)
  50. if err != nil || ct == 0 {
  51. ct = 1
  52. }
  53. uid, ok := metadata.Value(c, metadata.Mid).(int64)
  54. //uid = 19148701
  55. //ok = true
  56. if !ok {
  57. c.Set("output_data", "未登陆")
  58. c.JSONMap(map[string]interface{}{"message": fmt.Sprintf("未登陆")}, ecode.RequestErr)
  59. c.Abort()
  60. return
  61. }
  62. err = srv.StreamCut(c, roomID, ct, uid)
  63. if err != nil {
  64. c.Set("output_data", err.Error())
  65. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  66. c.Abort()
  67. return
  68. }
  69. c.Set("output_data", "ok")
  70. c.JSONMap(map[string]interface{}{"data": map[string]int{}}, nil)
  71. }