odc.xiaohui
2023-06-13 a12559e8c816633977358fd21c60c621e5b96645
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
<template>
<!--  <div ref="jitsiContainer" style="height: 100vh; width: 100%;"></div>-->
  <div>
    <div id="meet"></div>
<!--    <el-button @click="Connect">加入</el-button>-->
  </div>
 
</template>
 
<script>
import { JitsiMeet } from "@/utils/jitsi_meet";
import $ from 'jquery';
window.$ = $;
export default {
  // props: {
  //   domain: {
  //     type: String,
  //     default: '124.222.18.104:8443'
  //   },
  //   options: {
  //     type: Object,
  //     default: () => ({}),
  //   },
  // },
  data () {
    return {
      jitsiApi: null,
      userName:'张三',
      roomName:'房间名',
      meet: {
        clients: [],
      },
    };
  },
  mounted () {
    // JitsiMeetJS.init();
    // const options = {
    //   serviceUrl:'https://124.222.18.104:8443/http-bind',
    //   hosts: {
    //     domain: 'https://124.222.18.104:8443/',
    //     muc: 'conference.meet.jit.si',
    //   },
    //   bosh: 'https://124.222.18.104:8443/http-bind',
    //   useStunTurn: true
    // }
    const domain = '124.222.18.104:8443';
    const options = {
      roomName: this.roomName,
      width: 1200,
      height: 800,
      parentNode: document.querySelector('#meet'),
      configOverwrite: {
        disableSsl: true
      },
      userInfo: {displayName: this.userName}
    };
    // const connection = new JitsiMeetJS.JitsiConnection('123', null, options);
 
    const api = new JitsiMeetExternalAPI(domain, options);
 
    // this.meet = new JitsiMeet(
    //   //这里是服务端的XMPP地址
    //   "https://124.222.18.104:8443/http-bind",
    //   this.name
    // );
    api.addEventListeners({
      participantJoined: handleParticipantJoined,
      participantLeft: handleParticipantLeft
    });
 
    function handleParticipantJoined(event) {
      console.log(`Participant joined: ${event.id}`);
      console.log(event)
    }
 
    function handleParticipantLeft(event) {
      console.log(`Participant left: ${event.id}`);
      console.log(event)
    }
 
    // function onConnectionSuccess() {
    //   console.log("onConnectionSuccess", arguments);
    // }
    // function onConnectionFailed() {
    //   console.log("onConnectionFailed", arguments);
    // }
    // function disconnect() {
    //   console.log("disconnect", arguments);
    // }
    //
    // connection.addEventListener(JitsiMeetJS.events.connection.CONNECTION_ESTABLISHED, onConnectionSuccess);
    // connection.addEventListener(JitsiMeetJS.events.connection.CONNECTION_FAILED, onConnectionFailed);
    // connection.addEventListener(JitsiMeetJS.events.connection.CONNECTION_DISCONNECTED, disconnect);
    //
    // connection.connect(undefined);
 
 
    // this.loadScript(`https://${this.domain}/external_api.js`, () => {
    //   if (!window.JitsiMeetExternalAPI) throw new Error('Jitsi Meet External API not loaded');
    //   this.embedJitsiWidget();
    // });
  },
  beforeDestroy () {
    // this.Disconnect()
    this.removeJitsiWidget();
 
  },
  methods: {
    Connect() {
      // 加入名称为xxx的房间(这一步会创建连接与房间对象)
      this.meet.joinRoom("xxxx");
      // this.beInRoom = true;
    },
    // Disconnect() {
    //   // 离开房间(这一步会断开连接)
    //   this.meet.leveRoom();
    //   // this.beInRoom = false;
    // },
    loadScript (src, cb) {
      const scriptEl = document.createElement('script');
      scriptEl.src = src;
      scriptEl.async = 1;
      document.querySelector('head').appendChild(scriptEl);
      scriptEl.addEventListener('load', cb);
    },
    embedJitsiWidget () {
      const options = {
        ...this.options,
        parentNode: this.$refs.jitsiContainer,
      };
      this.jitsiApi = new window.JitsiMeetExternalAPI(this.domain, options);
    },
    executeCommand (command, ...value) {
      this.jitsiApi.executeCommand(command, ...value);
    },
    addEventListener (event, fn) {
      this.jitsiApi.on(event, fn);
    },
    // Misc
    removeJitsiWidget () {
      if (this.jitsiApi) this.jitsiApi.dispose();
    },
  }
};
</script>