fuliqi
2024-10-28 c2a1c68a2a398e6d0f2f5854c65127efbff306b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<template>
  <div>
    <div style="display: flex; flex-direction: row;">
      <div id="meet" ref="meet" style="flex-grow: 1;">
      </div>
      <div style="padding-top: 5px; padding-left: 5px;right: 15px">
        <el-button type="success" size="small" @click="hiddenStudent">{{ getShowText() }}</el-button>
        <el-row v-show="showStudent">
          <el-row :gutter="5">
            <el-col :span="12">
              <el-input placeholder="搜索学员" size="small" clearable @input="getStudentList" @clear="getStudentList"
                        v-model="searchForm.keyword"/>
            </el-col>
            <el-col :span="2">
              <el-button type="primary" size="small" @click="getStudentList">搜索</el-button>
            </el-col>
          </el-row>
          <el-tabs v-model="searchForm.onlineStatus" @tab-click="handleTabChange" style="margin-left: 3px">
            <el-tab-pane label="在线学员" name="1"></el-tab-pane>
            <el-tab-pane label="离线学员" name="0"></el-tab-pane>
          </el-tabs>
          <el-table :data="showStudentList" style="width: 100%">
            <el-table-column prop="realName" label="学员姓名"></el-table-column>
            <el-table-column prop="id" label="操作" width="80px;">
              <template slot-scope="scope">
                <el-dropdown trigger="click" @command="handleCommand">
                  <i class="el-icon-more-outline" id="more"></i>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item :command="{ command: 'openCamera', id: scope.row.id }">打开/关闭摄像头</el-dropdown-item>
                    <el-dropdown-item :command="{ command: 'mute', id: scope.row.id }">静音/取消静音</el-dropdown-item>
                    <el-dropdown-item :command="{ command: 'kickOut', id: scope.row.id }">踢出</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </el-table-column>
            <el-table-column prop="onlineStatus" label="状态" width="80px;">
              <template slot-scope="scope">
                <div :class="{ online: scope.row.onlineStatus === 1, outline: scope.row.onlineStatus === 0 }">
                  {{ getStatus(scope.row.onlineStatus) }}
                </div>
              </template>
            </el-table-column>
          </el-table>
          <el-button class="link-left" type="primary" size="small" @click="muteEveryone">全体静音</el-button>
          <el-button class="link-left" type="primary" size="small" @click="videoEveryone">全体关闭摄像头</el-button>
        </el-row>
      </div>
    </div>
  </div>
</template>
 
<script>
import { getStudentList } from '@/api/meet'
import Cookies from 'js-cookie'
 
export default {
  data () {
    return {
      ws: null,
      jitsiApi: null,
      width: 0,
      height: 0,
      showStudent: true,
      intervalId: null,
      meetId: null,
      roomName: '',
      joinList: [],
      searchForm: {
        keyword: '',
        // 0 未在线、 1 在线
        onlineStatus: 0
      },
      studentList: [],
      showStudentList: []
    }
  },
  beforeDestroy () {
    if (this.ws) {
      this.ws.close()
    }
  },
  methods: {
    muteEveryone () {
      this.jitsiApi.executeCommand('muteEveryone', 'audio')
      const h = this.$createElement;
 
      this.$notify({
        title: '提示',
        message: h('i', { style: 'color: teal'}, '已全体禁音')
      });
    },
    videoEveryone () {
      this.jitsiApi.executeCommand('muteEveryone', 'video')
      const h = this.$createElement;
 
      this.$notify({
        title: '提示',
        message: h('i', { style: 'color: teal'}, '已关闭全体视频')
      });
    },
    handleCommand (command) {
      this.sendMessage(JSON.stringify(command))
    },
    initWebSocket () {
      this.ws = new WebSocket('wss://www.kgmeet.com:18080/websocket/' + JSON.parse(Cookies.get('adminUserInfo')).id)
      let ws = this.ws
      ws.onopen = () => {
        console.log('WebSocket 连接成功')
        // 发送心跳数据
        ws.send('ping')
      }
      ws.onmessage = (event) => {
        console.log('收到服务器消息:', event.data)
        // 处理服务器发来的消息
      }
      ws.onerror = (error) => {
        console.error('WebSocket 连接出错:', error)
      }
      ws.onclose = () => {
        console.log('WebSocket 连接已关闭')
        // 可以在这里尝试重新连接
      }
 
      // 组件销毁时断开 WebSocket 连接
      this.$once('hook:beforeDestroy', () => {
        ws.close()
      })
    },
    sendMessage (message) {
      if (this.ws.readyState === WebSocket.OPEN) {
        this.ws.send(message)
      } else {
        console.error('WebSocket 连接未打开')
      }
    },
    hiddenStudent () {
      this.showStudent = !this.showStudent
    },
    changeJitsiWindowSize (width, height) {
      this.jitsiApi.resizeLargeVideo(width, height)
    },
    getShowText () {
      if (this.showStudent) {
        return '隐藏'
      } else {
        return '显示'
      }
    },
    getStatus (status) {
      if (status === 1) {
        return '在线'
      } else if (status === 0) {
        return '离线'
      }
    },
    handleTabChange (tab) {
      let status = parseInt(tab.name)
      this.showStudentList = this.studentList.filter(student => {
        return student.onlineStatus === status
      })
    },
    getStudentList () {
      let params = {
        keyword: this.searchForm.keyword
      }
      getStudentList(this.meetId, params).then(res => {
        this.studentList = res.data.data
        this.showStudentList = this.studentList.filter(student => {
          return student.onlineStatus === this.searchForm.onlineStatus
        })
      })
    },
    getRoomInfo () {
      this.jitsiApi.getRoomsInfo().then(rooms => {
        rooms.rooms.forEach(room => {
          // 房间的id是一个子域名,且@符前的会议名称是经过URL编码的
          let encodedPart = room.id.split('@')[0]
          let decodedPart = decodeURIComponent(encodedPart)
          if (this.roomName === decodedPart) {
            room.participants.forEach(user => {
              // 使用'_'作为分隔符分割字符串,获取到userId
              const parts = user.displayName.split('_')
              let userId = null
              if (parts.length > 1) {
                userId = parseInt(parts[1])
                // 设置学员状态为在线
                this.studentList.forEach(student => {
                  console.log(student.id === userId)
                  if (student.id === userId) {
                    student.onlineStatus = 1
                  }
                })
              }
            })
          }
        })
        this.showStudentList = this.studentList.filter(student => {
          return student.onlineStatus === parseInt(this.searchForm.onlineStatus)
        })
      })
    }
  },
  mounted () {
    this.height = window.innerHeight
    this.meetId = this.$route.query.meetId
    this.getStudentList()
    const domain = this.$route.query.domain
    const roomName = this.$route.query.roomName
    this.roomName = roomName
    const userInfoStr = this.$route.query.userInfoStr
    const userInfo = userInfoStr ? JSON.parse(userInfoStr) : null
    const options = {
      roomName: roomName,
      height: this.height,
      parentNode: this.$refs.meet,
      lang: 'zh_CN',
      userInfo: userInfo,
      configOverwrite: {
        prejoinConfig: {
          enabled: false
        },
        // 禁用邀请
        disableInviteFunctions: true,
        // 禁用邮箱
        gravatar: {
          disabled: true
        },
        // 禁用改名
        readOnlyName: true,
        // 自定义按钮
        toolbarButtons: [
          // 摄像头
          'camera',
          // 聊天
          'chat',
          // 共享
          'desktop',
          'download',
          'fullscreen',
          'hangup',
          // 'help',
          'highlight',
          // 'invite',
          'linktosalesforce',
          'livestreaming',
          'microphone',
          'noisesuppression',
          'recording',
          'select-background',
          'settings',
          'shareaudio',
          'sharedvideo',
          'shortcuts',
          'stats',
          'tileview',
          'toggle-camera',
          'whiteboard',
 
          // 'closedcaptions',
          // 'embedmeeting',
          // 'etherpad',
          // 'feedback',
          // 'filmstrip',
          'participants-pane',
          // 'profile',
          'raisehand',
          // 'security',
          'videoquality',
        ],
        whiteboard: {
          enabled: true
        }
      }
    }
 
    this.jitsiApi = new window.JitsiMeetExternalAPI(domain, options)
 
    this.jitsiApi.addListener('readyToClose', () => {
      window.close()
    })
    // 初始化
    this.initWebSocket()
    // 每三秒更学员在线状态
    this.intervalId = setInterval(() => {
      this.getRoomInfo()
      // 发送心跳数据
      this.ws.send('ping')
    }, 2500)
 
  },
  beforeDestroy () {
    // 清除定时器,避免内存泄漏
    if (this.intervalId) {
      clearInterval(this.intervalId)
      this.intervalId = null
    }
  }
}
 
</script>
 
<style lang="scss" scoped>
/deep/ thead {
  display: none;
}
 
#more:hover {
  cursor: pointer;
}
 
#meet {
  height: 100%;
}
 
.online {
  color: #42b983;
}
 
.outline {
  color: #aa1111;
}
 
.studentWarp {
  display: flex;
  flex-direction: row;
}
 
.student-row {
  margin-top: 8px;
  padding-left: 3px;
  color: #565b5e;
}
</style>