peerStore.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { defineStore } from 'pinia'
  2. export interface IState {
  3. peerId: string | undefined
  4. isBusy: boolean
  5. isClose: boolean
  6. isAccept:boolean
  7. callId: string | undefined
  8. offer: string | undefined
  9. answer: string | undefined
  10. candidate: string | undefined
  11. users: string | undefined
  12. }
  13. export const usePeerStore = defineStore({
  14. id: 'peer_store',
  15. state(): IState {
  16. return {
  17. /**
  18. * 自己的peerid
  19. */
  20. peerId: undefined,
  21. /**
  22. * 是否已经在通话
  23. */
  24. isBusy: false,
  25. /**
  26. * 是否接受邀请
  27. */
  28. isAccept: false,
  29. /**
  30. * 是否收到关闭通话的消息
  31. */
  32. isClose: false,
  33. /**
  34. * 被呼叫的id
  35. */
  36. callId: undefined,
  37. /**
  38. * offer数据
  39. */
  40. offer:undefined,
  41. /**
  42. * answer数据
  43. */
  44. answer:undefined,
  45. /**
  46. * candidate数据
  47. */
  48. candidate:undefined,
  49. /**
  50. * users数据 通话用户列表[1,2,3,4]
  51. */
  52. users:undefined
  53. }
  54. },
  55. getters: {
  56. getIsClose(): boolean {
  57. return this.isClose
  58. }
  59. },
  60. actions: {
  61. setPeerId(peerId: string) {
  62. this.peerId = peerId
  63. },
  64. setIsAccept(isAccept: boolean) {
  65. // console.log('setIsAccept',this.isAccept,isAccept);
  66. this.isAccept = isAccept
  67. },
  68. setCallId(callId: string|undefined) {
  69. this.callId = callId
  70. },
  71. setOffer(offer: string|undefined) {
  72. this.offer = offer
  73. },
  74. setAnswer(answer: string|undefined) {
  75. this.answer = answer
  76. },
  77. setCandidate(candidate: string|undefined) {
  78. this.candidate = candidate
  79. },
  80. setUsers(users: string|undefined) {
  81. this.users = users
  82. },
  83. updateBusyStatus(isBusy: boolean) {
  84. this.isBusy = isBusy
  85. },
  86. updateCloseStatus(isClose: boolean) {
  87. if (isClose) {
  88. this.isBusy = false;
  89. }
  90. this.isClose = isClose
  91. },
  92. closeAll() {
  93. this.updateBusyStatus(false)
  94. }
  95. }
  96. })