videoComp.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div></div>
  3. </template>
  4. <script>
  5. let WebIM = require("../../../../../utils/WebIM")["default"];
  6. let msgType = require("../../../msgtype");
  7. let msgStorage = require("../../../msgstorage");
  8. let disp = require("../../../../../utils/broadcast");
  9. export default {
  10. data() {
  11. return {};
  12. },
  13. components: {},
  14. props: {
  15. username: {
  16. type: Object,
  17. default: () => ({}),
  18. },
  19. chatType: {
  20. type: String,
  21. default: msgType.chatType.SINGLE_CHAT,
  22. },
  23. },
  24. methods: {
  25. isGroupChat() {
  26. return this.chatType == msgType.chatType.CHAT_ROOM;
  27. },
  28. getSendToParam() {
  29. return this.isGroupChat() ? this.username.groupId : this.username.your;
  30. },
  31. // 未启用
  32. sendVideo() {
  33. var me = this;
  34. var token = WebIM.conn.context.accessToken;
  35. uni.chooseVideo({
  36. sourceType: ["album", "camera"],
  37. maxDuration: 60,
  38. camera: "back",
  39. success(res) {
  40. var tempFilePaths = res.tempFilePath;
  41. var str = WebIM.config.appkey.split("#");
  42. uni.uploadFile({
  43. url:
  44. "https://a1.easemob.com/" + str[0] + "/" + str[1] + "/chatfiles",
  45. filePath: tempFilePaths,
  46. name: "file",
  47. header: {
  48. "Content-Type": "multipart/form-data",
  49. Authorization: "Bearer " + token,
  50. },
  51. success(res) {
  52. var data = res.data;
  53. var dataObj = JSON.parse(data);
  54. var id = WebIM.conn.getUniqueId(); // 生成本地消息id
  55. var msg = new WebIM.message(msgType.VIDEO, id);
  56. msg.set({
  57. apiUrl: WebIM.config.apiURL,
  58. accessToken: token,
  59. body: {
  60. type: msgType.VIDEO,
  61. url: dataObj.uri + "/" + dataObj.entities[0].uuid,
  62. filetype: "mp4",
  63. filename: tempFilePaths,
  64. accessToken: token,
  65. },
  66. from: me.username.myName,
  67. to: me.getSendToParam(),
  68. roomType: false,
  69. chatType: me.chatType,
  70. success: function (argument) {
  71. disp.fire('em.chat.sendSuccess', id);
  72. }
  73. });
  74. if (me.isGroupChat()) {
  75. msg.setGroup("groupchat");
  76. }
  77. WebIM.conn.send(msg.body);
  78. let obj = {
  79. msg: msg,
  80. type: msgType.VIDEO,
  81. };
  82. me.saveSendMsg(obj);
  83. },
  84. });
  85. },
  86. });
  87. },
  88. saveSendMsg(evt) {
  89. msgStorage.saveMsg(evt.msg, evt.type);
  90. },
  91. },
  92. // lifetimes
  93. created() {},
  94. beforeMount() {},
  95. moved() {},
  96. destroyed() {},
  97. mounted() {},
  98. };
  99. </script>