meeting-en.html 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8"/>
  5. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no,user-scalable=no"/>
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
  7. <meta name="theme-color" content="#000000"/>
  8. <meta name="x5-fullscreen" content="true">
  9. <meta name="mobile-web-app-capable" content="yes">
  10. <meta http-equiv="Pragma" content="no-cache">
  11. <meta http-equiv="Cache-control" content="no-cache">
  12. <title>My Meeting</title>
  13. <style>
  14. .select-text {
  15. -webkit-user-select: text;
  16. -moz-user-select: text;
  17. -ms-user-select: text;
  18. user-select: text;
  19. }
  20. .box {
  21. display: flex;
  22. flex-wrap: wrap;
  23. flex-direction: row;
  24. justify-content: space-around;
  25. background: center / contain repeat url(https://www.huaweicloud.com/content/dam/cloudbu-site/archive/china/zh-cn/product/cloud_communications/meeting/image/image-%E5%B8%AE%E5%8A%A9%E6%96%87%E6%A1%A3-2.png);
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <div class="box" style="display: flex; display: -webkit-flex; ">
  31. <div class="title is-2" style="text-align: center; width: 100%;">Huawei Cloud Web SDK Demo</div>
  32. <div style="width: 50%;">
  33. <div>
  34. <button id="get-sdk-version-button" class="button is-link" onclick=getSdkVersion()
  35. style="padding-left:15px;">Obtain SDK Version
  36. </button>
  37. <button id="browser-check-button" class="button is-success" onclick=checkBrowserSupport()
  38. style="padding-left:15px;">Check Browser Compatibility
  39. </button>
  40. </div>
  41. <div>
  42. <input id="lang" autocomplete="off" class="input is-rounded" placeholder="en-US | zh-CN " type="text"
  43. style="width: 160px;" value = 'en-US'>
  44. <button id='setLangButton' type="submit" onclick = setLang() class="button is-link">Set Language</button>
  45. </div>
  46. <div style="width: 100%; margin-top: 8px;">
  47. <input id="token" autocomplete="off" class="input is-rounded" type="text" placeholder="Token (optional, used for joining a meeting after login)"
  48. style="width: 220px;">
  49. <input id="confId" autocomplete="off" class="input is-rounded" placeholder="Meeting ID" type="text"
  50. style="width: 140px;" value="">
  51. <input id="pwd" autocomplete="off" class="input is-rounded" placeholder="Meeting password" type="text"
  52. style="width: 150px;" value="">
  53. <input id="nickName" autocomplete="off" class="input is-rounded" placeholder="Name" type="text"
  54. style="width: 130px;" value="">
  55. <button type="submit" onclick=validateForm() class="button is-link">Join Meeting</button>
  56. <button class="button is-danger" onclick=clickLeaveConf() style="padding-left:15px;">Leave Meeting</button>
  57. </div>
  58. <div id="leaveConfModal" class="modal">
  59. <div class="modal-background"></div>
  60. <div class="modal-card">
  61. <header class="modal-card-head">
  62. <p class="modal-card-title">Information</p>
  63. <button class="delete" aria-label="close" onclick=closeModals()></button>
  64. </header>
  65. <section class="modal-card-body">
  66. <div class="control">
  67. <label class="radio">
  68. <input type="radio" name="leaveConfConfirm" value="leave" checked>
  69. Leave meeting
  70. </label>
  71. <label class="radio">
  72. <input type="radio" name="leaveConfConfirm" value="end">
  73. End meeting
  74. </label>
  75. </div>
  76. </section>
  77. <footer class="modal-card-foot">
  78. <button class="button is-success" onclick=handleLeaveConfirm()>OK</button>
  79. <button class="button" onclick=closeModals()>Cancel</button>
  80. </footer>
  81. </div>
  82. </div>
  83. <div style="margin-top: 8px;">
  84. <button id="handup-button" class="button is-primary" onclick=handleHand()>Raise Hand</button>
  85. <button id="chat-button" class="button is-info" onclick=handleChatVisible() style="padding-left:15px;">Show Chat
  86. </button>
  87. <button id="attendee-button" class="button is-link" onclick=handleAttendeeListVisible()
  88. style="padding-left:15px;">Show Participant
  89. </button>
  90. <button id="control-button" class="button is-info" onclick=handleControlBarVisible()
  91. style="padding-left:15px;">Show Control Bar
  92. </button>
  93. <button id="title-button" class="button is-success" onclick=handleTitleVisible() style="padding-left:15px;">
  94. Hide Title
  95. </button>
  96. <button id="bullet-button" class="button is-success" onclick=handleBulletScreenVisible()
  97. style="padding-left:15px;">Hide On-Screen Comments
  98. </button>
  99. <button id="share-button" class="button is-info" onclick=handleShareScreen()>Share Screen</button>
  100. <button id="video-button" class="button is-warning" onclick=handleVideoMute() style="padding-left:15px;">
  101. Enable Camera
  102. </button>
  103. <button id="audio-button" class="button is-primary" onclick=handleMuteAudio() style="padding-left:15px;">
  104. Unmute
  105. </button>
  106. <button id="speaker-button" class="button is-danger" onclick=handleMuteSpeaker() style="padding-left:15px;">
  107. Disable Speaker
  108. </button>
  109. </div>
  110. <div style="margin-top: 8px;">
  111. <input id='volumeInput' value class="input is-primary is-rounded" type="number" min="0" max="100" placeholder="Volume "
  112. onchange=volumeChange(value) style="width:136px;padding-left:15px;"></input>
  113. <button id="conf-staus-button" class="button is-success" onclick=handleSetVolume()
  114. style="padding-left:15px;">
  115. Set Volume
  116. </button>
  117. <input id='changeNameInput' value class="input is-link is-rounded" type="text" placeholder="Name " onchange=changingName(value)
  118. style="width:184px;padding-left:15px;"></input>
  119. <button id="chat-button" class="button is-info" onclick=handleChangeName() style="padding-left:15px;">Rename
  120. </button>
  121. <input id='changeWidthInput' value=1280 class="input is-link is-rounded" type="number" min="300" max="2000" placeholder="Width "
  122. onchange=changingWith(value) style="width:100px;padding-left:15px;"></input>
  123. <input id='changeHeightInput' value=720 class="input is-link is-rounded" type="number" min="300" max="1000" placeholder="Height "
  124. onchange=changingHeight(value) style="width:100px;padding-left:15px;"></input>
  125. <button id="chat-button" class="button is-info" onclick=handleChangeSize() style="padding-left:15px;">Change Resolution
  126. </button>
  127. </div>
  128. <div style="margin-top: 8px;">
  129. <span id="guest-url">
  130. <input value class="confViewInput input is-warning is-rounded" autocomplete="off" type="text" placeholder="Link "
  131. onchange=changingGuestUrl(value) style="width:700px;padding-left:15px;"></input>
  132. <button id="chat-button" class="button is-warning" onclick=handleGuestSharingUrl()
  133. style="padding-left:15px;">Set Panelist Link</button>
  134. </span>
  135. </div>
  136. <div style="margin-top: 8px;">
  137. <span id="audience-url">
  138. <input value class="confViewInput input is-success is-rounded" autocomplete="off" type="text" placeholder="Link"
  139. onchange=changingAudienceUrl(value) style="width:700px;padding-left:15px;"></input>
  140. <button id="chat-button" class="button is-success" onclick=handleAudienceSharingUrl()
  141. style="padding-left:15px;">Set Attendee Link</button>
  142. </span>
  143. </div>
  144. <div style="margin-top: 8px;">
  145. <span id="leave-url">
  146. <input value class="confViewInput input is-success is-rounded" autocomplete="off" type="text" placeholder="Link "
  147. onchange=changingLeaveUrl(value) style="width:700px;padding-left:15px;"></input>
  148. <button id="chat-button" class="button is-success" onclick=handleLeaveUrl()
  149. style="padding-left:15px;">Set Leave Url</button>
  150. </span>
  151. </div>
  152. <div style="margin-top: 8px;">
  153. <span id="record-content">
  154. <textarea name="record-content" rows="4" cols="80" value class=" confViewInput is-success is-rounded" autocomplete="off" type="text" placeholder="请输入内容: "
  155. onchange=changingStopRecordTip(value) style="width:700px;padding-left:15px;"></textarea>
  156. <button id="chat-button" class="button is-success" onclick=handleStopRecordTip()
  157. style="padding-left:15px;">Set Stop Record Content</button>
  158. </span>
  159. </div>
  160. <div style="margin-top: 8px;">
  161. <div id="mode-select" class="select is-link">
  162. <select id='changeModeSelect' onchange=selectMode(value)>
  163. <option value="">Select a view.</option>
  164. <option value="speaking">Presenter</option>
  165. <option value="gallery">Gallery</option>
  166. <option value="single">Single screen</option>
  167. </select>
  168. </div>
  169. <div class="select is-primary">
  170. <select id='getViewSelect' onchange=getViewStatus(value)>
  171. <option value="">View element status.</option>
  172. <option value="titleVisible">Title</option>
  173. <option value="bulletScreenVisible">On-screen comment</option>
  174. <option value="attendeeListVisible">Show Participant</option>
  175. <option value="chatVisible">Show Chat</option>
  176. <option value="viewMode">Video view</option>
  177. <option value="controlBarVisible">Show Control Bar</option>
  178. <option value="guestSharingUrl">Panelist link</option>
  179. <option value="audienceSharingUrl">Attendee link</option>
  180. <option value="stopRecordTip">Stop Record Content</option>
  181. <option value="leaveUrl">Redirection link after leaving meeting</option>
  182. </select>
  183. </div>
  184. <div class="select is-danger">
  185. <select id='getConfStatusSelect' onchange=getConfStatus(value)>
  186. <option value="">View meeting control status.</option>
  187. <option value="audioMute">Microphone</option>
  188. <option value="videoMute">Camera</option>
  189. <option value="speakerMute">Speaker</option>
  190. <option value="volume">Volume</option>
  191. <option value="handUp">Hand-raising</option>
  192. <option value="shareScreen">Sharing</option>
  193. <option value="userName">Name</option>
  194. <option value="role">Role info</option>
  195. </select>
  196. </div>
  197. </div>
  198. <div style="margin-top: 8px;">
  199. <textarea id="meeting-config" name="meeting-config" rows="8" cols="80" placeholder="Enter custom config parameters (JSON type)."
  200. onchange=changingCustomConfig(value)></textarea>
  201. <div>
  202. <button id="formatConfig" class="button is-success" onclick=formatConfig() style="padding-left:15px;">
  203. Format Parameter
  204. </button>
  205. <button id="setServerConfigButton" class="button is-warning" onclick=invokeSetServerConfig()
  206. style="padding-left:15px;">setServerConfig
  207. </button>
  208. <button id="joinConfButton" class="button is-info" onclick=invokeJoinConf() style="padding-left:15px;">
  209. joinConf
  210. </button>
  211. <button id="leaveConfButton" class="button is-info" onclick=invokeLeaveConf()
  212. style="padding-left:15px;">leaveConf
  213. </button>
  214. <button id="setViewConfigButton" class="button is-success" onclick=invokeSetViewConfig()
  215. style="padding-left:15px;">setViewConfig
  216. </button>
  217. <button id="setConfConfigButton" class="button is-info" onclick=invokeSetConfConfig()
  218. style="padding-left:15px;">setConfConfig
  219. </button>
  220. </div>
  221. </div>
  222. </div>
  223. <article class="message is-danger" style="width: 40%;">
  224. <div class="message-header">
  225. <p>Event Listening</p>
  226. <button class="button is-success is-small" onclick=clearMessagePanel()
  227. style="padding-left:15px;background-color: #c33a55;">Clear
  228. </button>
  229. <!-- <button class="delete" aria-label="delete"></button> -->
  230. </div>
  231. <div id="message-body" class="message-body" style="height: 500px; overflow-y: auto; user-select: text;">
  232. </div>
  233. </article>
  234. </div>
  235. <div id="root" style="position: absolute; width: 1280px; height: 720px; margin: 2% 5%">
  236. </div>
  237. <div id="stream-pools" style="display: none"></div>
  238. </body>
  239. <script src="./react.development.js" crossorigin></script>
  240. <script src="./react-dom.development.js" crossorigin></script>
  241. <script src="./moment.min.js" crossorigin></script>
  242. <!-- SDK -->
  243. <script src='./HWMeeting.js'></script>
  244. <link rel="stylesheet" href="./bulma.min.css">
  245. <script>
  246. /**
  247. * 设置会议服务器地址, 不设置时默认使用中国站
  248. * 中国站: host: 'meeting.huaweicloud.com', port: '443'
  249. * 国际站: host: 'intl.meeting.huaweicloud.com', port: '443'
  250. * */
  251. HWMeeting.setServerConfig({
  252. host: 'meeting.huaweicloud.com',
  253. port: '443'
  254. });
  255. let listener;
  256. let role;
  257. function createListener() {
  258. listener = HWMeeting.createEventListener();
  259. HWMeeting.getEventList().forEach(event => {
  260. listener.on(event, (eventData) => {
  261. handleListeningEvents(event, JSON.stringify(eventData));
  262. if (event === "leave_conf_result") {
  263. handleConfLeaveEvent(eventData);
  264. }
  265. if (event === "conf_config_changed") {
  266. handleConfChangeEvent(eventData);
  267. }
  268. if (event === "view_config_changed") {
  269. handleViewChangeEvent(eventData);
  270. }
  271. if (event === "join_conf_result" && eventData?.retCode === "0") {
  272. // 同步按钮状态
  273. syncConfConfig();
  274. syncViewConfig();
  275. }
  276. });
  277. });
  278. }
  279. // 可视化事件结果
  280. function handleListeningEvents(event, eventDataJson) {
  281. let msgBody = document.getElementById("message-body");
  282. let newContent = document.createElement("div");
  283. newContent.textContent = `[Event callback] | ${moment().format("YYYY-MM-DD HH:mm:ss")} | Event: [${event}]: ${eventDataJson}`;
  284. newContent.class = 'select-text';
  285. newContent.style = " white-space: pre-wrap; word-wrap:break-word";
  286. // 添加文本节点 到这个新的 div 元素
  287. msgBody.appendChild(newContent);
  288. msgBody.scrollTop = msgBody.scrollHeight;
  289. console.warn("事件监听:", event, eventDataJson)
  290. }
  291. function clearMessagePanel() {
  292. let msgBody = document.getElementById("message-body");
  293. msgBody.innerHTML = '';
  294. }
  295. </script>
  296. <!-- 会控控制 -->
  297. <script>
  298. let width = 1280;
  299. let height = 720;
  300. let customConfig;
  301. const SUCCESS = true;
  302. const FAIL = false;
  303. const confConfig = {
  304. audioMute: {
  305. name: 'audioMute',
  306. value: true,
  307. },
  308. videoMute: {
  309. name: 'videoMute',
  310. value: true,
  311. },
  312. speakerMute: {
  313. name: 'speakerMute',
  314. value: false,
  315. },
  316. volume: {
  317. name: 'volume',
  318. value: 50,
  319. },
  320. handUp: {
  321. name: 'handUp',
  322. value: false,
  323. },
  324. shareScreen: {
  325. name: 'shareScreen',
  326. value: false,
  327. },
  328. userName: {
  329. name: 'userName',
  330. value: null,
  331. },
  332. role: {
  333. name: 'role',
  334. value: null,
  335. },
  336. }
  337. const buttonMap = {
  338. [confConfig.audioMute.name]: {
  339. element: document.getElementById("audio-button"),
  340. value: {
  341. true: "Unmute",
  342. false: "Mute"
  343. }
  344. },
  345. [confConfig.videoMute.name]: {
  346. element: document.getElementById("video-button"),
  347. value: {
  348. true: "Enable Camera",
  349. false: "Disable Camera"
  350. }
  351. },
  352. [confConfig.speakerMute.name]: {
  353. element: document.getElementById("speaker-button"),
  354. value: {
  355. true: "Enable Speaker",
  356. false: "Disable Speaker"
  357. }
  358. },
  359. [confConfig.handUp.name]:
  360. {
  361. element: document.getElementById("handup-button"),
  362. value: {
  363. true: "Lower Hand",
  364. false: "Raise Hand"
  365. }
  366. },
  367. [confConfig.shareScreen.name]:
  368. {
  369. element: document.getElementById("share-button"),
  370. value: {
  371. true: "Cancel Sharing",
  372. false: "Share Screen"
  373. }
  374. },
  375. }
  376. function syncConfConfig() {
  377. Object.keys(confConfig).forEach((key => {
  378. HWMeeting.getConfConfig(key).then((result) => {
  379. if (Object.prototype.hasOwnProperty.call(buttonMap, key)) {
  380. buttonMap[key].element.textContent = buttonMap[key].value[result.data[key]];
  381. confConfig[key].value = result.data[key];
  382. }
  383. }).catch((e) => {
  384. console.error('mark syncConfConfig', e)
  385. });
  386. }));
  387. }
  388. function handleConfLeaveEvent() {
  389. Array.from(document.querySelectorAll('.confViewInput')).forEach(node => {
  390. node.value = '';
  391. })
  392. }
  393. function handleConfChangeEvent(eventData) {
  394. const { configName, previousValue, currentValue } = eventData;
  395. if (Object.prototype.hasOwnProperty.call(buttonMap, configName)) {
  396. buttonMap[configName].element.textContent = buttonMap[configName].value[currentValue];
  397. confConfig[configName].value = currentValue;
  398. }
  399. }
  400. function handleShareScreen() {
  401. let params = { shareScreen: !confConfig.shareScreen.value };
  402. HWMeeting.setConfConfig(params).then((result) => {
  403. // 显示结果
  404. showPromiseResult("setConfConfig", params, SUCCESS, result);
  405. }).catch((e) => {
  406. // 显示结果
  407. showPromiseResult("setConfConfig", params, FAIL, e);
  408. });
  409. }
  410. function handleMuteAudio() {
  411. let params = { audioMute: !confConfig.audioMute.value };
  412. HWMeeting.setConfConfig(params).then((result) => {
  413. // 显示结果
  414. showPromiseResult("setConfConfig", params, SUCCESS, result);
  415. }).catch((e) => {
  416. // 显示结果
  417. showPromiseResult("setConfConfig", params, FAIL, e);
  418. });
  419. }
  420. function handleVideoMute() {
  421. let params = { videoMute: !confConfig.videoMute.value };
  422. HWMeeting.setConfConfig(params).then((result) => {
  423. // 显示结果
  424. showPromiseResult("setConfConfig", params, SUCCESS, result);
  425. }).catch((e) => {
  426. // 显示结果
  427. showPromiseResult("setConfConfig", params, FAIL, e);
  428. });
  429. }
  430. function handleMuteSpeaker() {
  431. let params = { speakerMute: !confConfig.speakerMute.value }
  432. HWMeeting.setConfConfig(params).then((result) => {
  433. // 显示结果
  434. showPromiseResult("setConfConfig", params, SUCCESS, result);
  435. }).catch((e) => {
  436. // 显示结果
  437. showPromiseResult("setConfConfig", params, FAIL, e);
  438. });
  439. }
  440. function handleHand() {
  441. let params = { handUp: !confConfig.handUp.value };
  442. HWMeeting.setConfConfig(params).then((result) => {
  443. // 显示结果
  444. showPromiseResult("setConfConfig", params, SUCCESS, result);
  445. }).catch((e) => {
  446. // 显示结果
  447. showPromiseResult("setConfConfig", params, FAIL, e);
  448. });
  449. }
  450. function getConfStatus(value) {
  451. if (value === "") {
  452. return;
  453. }
  454. HWMeeting.getConfConfig(value).then((data) => {
  455. // 显示结果
  456. showPromiseResult("getConfConfig", value, SUCCESS, data);
  457. }).catch((e) => {
  458. // 显示结果
  459. showPromiseResult("getConfConfig", value, FAIL, e);
  460. });
  461. }
  462. function getViewStatus(value) {
  463. if (value === "") {
  464. return;
  465. }
  466. HWMeeting.getViewConfig(value).then((data) => {
  467. // 显示结果
  468. showPromiseResult("getViewConfig", value, SUCCESS, data);
  469. }).catch((e) => {
  470. // 显示结果
  471. showPromiseResult("getViewConfig", value, FAIL, e);
  472. });
  473. }
  474. function handleSetVolume() {
  475. let params = { 'volume': Number(confConfig.volume.value) }
  476. HWMeeting.setConfConfig(params).then((result) => {
  477. // 显示结果
  478. showPromiseResult("setConfConfig", params, SUCCESS, result);
  479. }).catch((e) => {
  480. // 显示结果
  481. showPromiseResult("setConfConfig", params, FAIL, e);
  482. });
  483. }
  484. function handleChangeName() {
  485. let params = { userName: confConfig.userName.value }
  486. HWMeeting.setConfConfig(params).then((result) => {
  487. // 显示结果
  488. showPromiseResult("setConfConfig", params, SUCCESS, result);
  489. }).catch((e) => {
  490. // 显示结果
  491. showPromiseResult("setConfConfig", params, FAIL, e);
  492. });
  493. }
  494. function handleGetToken() {
  495. getToken();
  496. }
  497. function changingWith(e) {
  498. width = e;
  499. }
  500. function changingHeight(e) {
  501. height = e;
  502. }
  503. // confConfig
  504. function changingName(e) {
  505. confConfig.userName.value = e;
  506. }
  507. function volumeChange(e) {
  508. confConfig.volume.value = e;
  509. }
  510. // viewConfig
  511. function changingGuestUrl(e) {
  512. viewConfig.guestSharingUrl.value = e;
  513. }
  514. function changingAudienceUrl(e) {
  515. viewConfig.audienceSharingUrl.value = e;
  516. }
  517. function changingLeaveUrl(e) {
  518. viewConfig.leaveUrl.value = e;
  519. }
  520. function changingStopRecordTip(e) {
  521. viewConfig.stopRecordTip.value = e;
  522. }
  523. // 自定义参数
  524. function changingCustomConfig(value) {
  525. customConfig = value;
  526. }
  527. function parseConfJson(config) {
  528. if (typeof config === 'undefined' || config === null) {
  529. return config;
  530. }
  531. if (config === '') {
  532. return undefined;
  533. }
  534. try {
  535. return JSON.parse(config);
  536. } catch (err) {
  537. console.error(err);
  538. alert('Incorrect JSON format.' + JSON.stringify(err))
  539. }
  540. }
  541. function formatConfig() {
  542. const customConfigJson = parseConfJson(customConfig);
  543. if (customConfigJson) {
  544. document.getElementById("meeting-config").value = JSON.stringify(customConfigJson, null, 4);
  545. }
  546. }
  547. </script>
  548. <!-- UI控制: -->
  549. <script>
  550. const viewConfig = {
  551. titleVisible: {
  552. name: 'titleVisible',
  553. value: false
  554. },
  555. attendeeListVisible: {
  556. name: 'attendeeListVisible',
  557. value: false
  558. },
  559. chatVisible: {
  560. name: 'chatVisible',
  561. value: false
  562. },
  563. bulletScreenVisible: {
  564. name: 'bulletScreenVisible',
  565. value: false
  566. },
  567. controlBarVisible: {
  568. name: 'controlBarVisible',
  569. value: false
  570. },
  571. viewMode: {
  572. name: 'viewMode',
  573. value: null
  574. },
  575. guestSharingUrl: {
  576. name: 'guestSharingUrl',
  577. value: null
  578. },
  579. audienceSharingUrl: {
  580. name: 'audienceSharingUrl',
  581. value: null
  582. },
  583. stopRecordTip: {
  584. name: 'stopRecordTip',
  585. value: null
  586. },
  587. leaveUrl: {
  588. name: 'leaveUrl',
  589. value: null
  590. },
  591. }
  592. const viewButtonMap = {
  593. [viewConfig.titleVisible.name]: {
  594. element: document.getElementById("title-button"),
  595. value: {
  596. true: "Hide Title",
  597. false: "Title"
  598. }
  599. },
  600. [viewConfig.attendeeListVisible.name]: {
  601. element: document.getElementById("attendee-button"),
  602. value: {
  603. true: "Hide Participant",
  604. false: "Show Participant"
  605. }
  606. },
  607. [viewConfig.chatVisible.name]: {
  608. element: document.getElementById("chat-button"),
  609. value: {
  610. true: "Hide Chat",
  611. false: "Show Chat"
  612. }
  613. },
  614. [viewConfig.bulletScreenVisible.name]: {
  615. element: document.getElementById("bullet-button"),
  616. value: {
  617. true: "Hide On-Screen Comments",
  618. false: "On-screen comment"
  619. }
  620. },
  621. [viewConfig.controlBarVisible.name]: {
  622. element: document.getElementById("control-button"),
  623. value: {
  624. true: "Hide Control Bar",
  625. false: "Show Control Bar"
  626. }
  627. },
  628. }
  629. function syncViewConfig() {
  630. Object.keys(viewConfig).forEach((key => {
  631. HWMeeting.getViewConfig(key).then((result) => {
  632. if (Object.prototype.hasOwnProperty.call(viewButtonMap, key)) {
  633. viewButtonMap[key].element.textContent = viewButtonMap[key].value[result.data[key]];
  634. viewConfig[key].value = result.data[key];
  635. }
  636. }).catch((e) => {
  637. console.error('syncViewConfig', key, e)
  638. });
  639. }));
  640. }
  641. function handleViewChangeEvent(eventData) {
  642. const { configName, previousValue, currentValue } = eventData;
  643. if (Object.prototype.hasOwnProperty.call(viewButtonMap, configName)) {
  644. viewButtonMap[configName].element.textContent = viewButtonMap[configName].value[currentValue];
  645. }
  646. viewConfig[configName].value = currentValue;
  647. }
  648. function clickLeaveConf() {
  649. const value = "role"
  650. HWMeeting.getConfConfig(value).then((data) => {
  651. // 显示结果
  652. showPromiseResult("getConfConfig", value, SUCCESS, data);
  653. if (data?.data?.role === "host") {
  654. openModals();
  655. } else {
  656. handleLeave({ isEndConf: false });
  657. }
  658. }).catch((e) => {
  659. // 显示结果
  660. showPromiseResult("getConfConfig", value, FAIL, e);
  661. });
  662. }
  663. function handleLeaveConfirm() {
  664. closeModals();
  665. const radioValue = document.querySelector('[name=leaveConfConfirm]:checked').value;
  666. const params = { isEndConf: radioValue === "end" };
  667. handleLeave(params);
  668. }
  669. function handleLeave(params) {
  670. HWMeeting.leaveConf(params).then((result) => {
  671. // 显示结果
  672. showPromiseResult("leaveConf", params, SUCCESS, result);
  673. }).catch((e) => {
  674. // 显示结果
  675. showPromiseResult("leaveConf", params, FAIL, e);
  676. })
  677. }
  678. function openModals() {
  679. document.getElementById("leaveConfModal").classList.add('is-active');
  680. }
  681. function closeModals() {
  682. document.getElementById("leaveConfModal").classList.remove('is-active')
  683. }
  684. function handleChatVisible() {
  685. let params = { chatVisible: !viewConfig.chatVisible.value };
  686. HWMeeting.setViewConfig(params).then((result) => {
  687. // 显示结果
  688. showPromiseResult("setViewConfig", params, SUCCESS, result);
  689. }).catch((e) => {
  690. // 显示结果
  691. showPromiseResult("setViewConfig", params, FAIL, e);
  692. });
  693. }
  694. function handleAttendeeListVisible() {
  695. let params = { attendeeListVisible: !viewConfig.attendeeListVisible.value };
  696. HWMeeting.setViewConfig(params).then((result) => {
  697. // 显示结果
  698. showPromiseResult("setViewConfig", params, SUCCESS, result);
  699. }).catch((e) => {
  700. // 显示结果
  701. showPromiseResult("setViewConfig", params, FAIL, e);
  702. });
  703. }
  704. function handleControlBarVisible() {
  705. let params = { controlBarVisible: !viewConfig.controlBarVisible.value };
  706. HWMeeting.setViewConfig(params).then((result) => {
  707. // 显示结果
  708. showPromiseResult("setViewConfig", params, SUCCESS, result);
  709. }).catch((e) => {
  710. // 显示结果
  711. showPromiseResult("setViewConfig", params, FAIL, e);
  712. });
  713. }
  714. function handleTitleVisible() {
  715. let params = { titleVisible: !viewConfig.titleVisible.value };
  716. HWMeeting.setViewConfig(params).then((result) => {
  717. // 显示结果
  718. showPromiseResult("setViewConfig", params, SUCCESS, result);
  719. }).catch((e) => {
  720. // 显示结果
  721. showPromiseResult("setViewConfig", params, FAIL, e);
  722. });
  723. }
  724. function handleBulletScreenVisible() {
  725. let params = { bulletScreenVisible: !viewConfig.bulletScreenVisible.value };
  726. HWMeeting.setViewConfig(params).then((result) => {
  727. // 显示结果
  728. showPromiseResult("setViewConfig", params, SUCCESS, result);
  729. }).catch((e) => {
  730. // 显示结果
  731. showPromiseResult("setViewConfig", params, FAIL, e);
  732. });
  733. }
  734. function selectMode(value) {
  735. if (value === "") {
  736. return;
  737. }
  738. let params = { viewMode: value };
  739. HWMeeting.setViewConfig(params).then((result) => {
  740. // 显示结果
  741. showPromiseResult("setViewConfig", params, SUCCESS, result);
  742. }).catch((e) => {
  743. // 显示结果
  744. showPromiseResult("setViewConfig", params, FAIL, e);
  745. })
  746. }
  747. // 修改sdk渲染框大小
  748. function handleChangeSize() {
  749. let sdkRoot = document.getElementById("root");
  750. width = Math.max(Math.min(width, 2000), 300);
  751. height = Math.max(Math.min(height, 1000), 300);
  752. sdkRoot.style.width = width + "px";
  753. sdkRoot.style.height = height + "px";
  754. }
  755. function handleGuestSharingUrl() {
  756. let params = { guestSharingUrl: viewConfig.guestSharingUrl.value }
  757. HWMeeting.setViewConfig(params).then((result) => {
  758. // 显示结果
  759. showPromiseResult("setViewConfig", params, SUCCESS, result);
  760. }).catch((e) => {
  761. // 显示结果
  762. showPromiseResult("setViewConfig", params, FAIL, e);
  763. });
  764. }
  765. function handleAudienceSharingUrl() {
  766. let params = { audienceSharingUrl: viewConfig.audienceSharingUrl.value };
  767. HWMeeting.setViewConfig(params).then((result) => {
  768. // 显示结果
  769. showPromiseResult("setViewConfig", params, SUCCESS, result);
  770. }).catch((e) => {
  771. // 显示结果
  772. showPromiseResult("setViewConfig", params, FAIL, e);
  773. });
  774. }
  775. function handleLeaveUrl() {
  776. let params = { leaveUrl: viewConfig.leaveUrl.value };
  777. HWMeeting.setViewConfig(params).then((result) => {
  778. // 显示结果
  779. showPromiseResult("setViewConfig", params, SUCCESS, result);
  780. }).catch((e) => {
  781. // 显示结果
  782. showPromiseResult("setViewConfig", params, FAIL, e);
  783. });
  784. }
  785. function handleStopRecordTip() {
  786. let params = { stopRecordTip: viewConfig.stopRecordTip.value };
  787. HWMeeting.setViewConfig(params).then((result) => {
  788. // 显示结果
  789. showPromiseResult("setViewConfig", params, SUCCESS, result);
  790. }).catch((e) => {
  791. // 显示结果
  792. showPromiseResult("setViewConfig", params, FAIL, e);
  793. });
  794. }
  795. function invokeSetConfConfig() {
  796. const customConfigObj = parseConfJson(customConfig);
  797. HWMeeting.setConfConfig(customConfigObj).then((result) => {
  798. // 显示结果
  799. showPromiseResult("setConfConfig", customConfigObj, SUCCESS, result);
  800. }).catch((e) => {
  801. // 显示结果
  802. showPromiseResult("setConfConfig", customConfigObj, FAIL, e);
  803. })
  804. }
  805. function invokeSetViewConfig() {
  806. const customConfigObj = parseConfJson(customConfig);
  807. HWMeeting.setViewConfig(customConfigObj).then((result) => {
  808. // 显示结果
  809. showPromiseResult("setViewConfig", customConfigObj, SUCCESS, result);
  810. }).catch((e) => {
  811. // 显示结果
  812. showPromiseResult("setViewConfig", customConfigObj, FAIL, e);
  813. })
  814. }
  815. function invokeJoinConf() {
  816. const customConfigObj = parseConfJson(customConfig);
  817. HWMeeting.joinConf(customConfigObj).then((result) => {
  818. // 显示结果
  819. showPromiseResult("joinConf", customConfigObj, SUCCESS, result);
  820. setLang()
  821. }).catch((e) => {
  822. // 显示结果
  823. showPromiseResult("joinConf", customConfigObj, FAIL, e);
  824. })
  825. }
  826. function invokeLeaveConf() {
  827. const customConfigObj = parseConfJson(customConfig);
  828. HWMeeting.leaveConf(customConfigObj).then((result) => {
  829. // 显示结果
  830. showPromiseResult("leaveConf", customConfigObj, SUCCESS, result);
  831. }).catch((e) => {
  832. // 显示结果
  833. showPromiseResult("leaveConf", customConfigObj, FAIL, e);
  834. })
  835. }
  836. function invokeSetServerConfig() {
  837. const customConfigObj = parseConfJson(customConfig);
  838. try {
  839. HWMeeting.setServerConfig(customConfigObj);
  840. // 显示结果
  841. showPromiseResult("setServerConfig", customConfigObj, SUCCESS);
  842. } catch (e) {
  843. // 显示结果
  844. showPromiseResult("setServerConfig", customConfigObj, FAIL, e);
  845. }
  846. }
  847. </script>
  848. <script>
  849. function validateForm() {
  850. let nickName = document.getElementById("nickName").value;
  851. let pwd = document.getElementById("pwd").value;
  852. let confId = document.getElementById("confId").value;
  853. let token = document.getElementById("token").value;
  854. console.warn(confId, pwd, nickName, token);
  855. HWMeeting.joinConf({ confId, pwd, nickName, token }).then((result) => {
  856. // 显示结果
  857. showPromiseResult("joinConf", { confId, pwd, nickName, token }, SUCCESS, result);
  858. setLang()
  859. }).catch((e) => {
  860. // 显示结果
  861. showPromiseResult("joinConf", { confId, pwd, nickName, token }, FAIL, e);
  862. })
  863. }
  864. function setLang() {
  865. let lang = document.getElementById('lang').value;
  866. if (lang == undefined || lang === null || lang === '') {
  867. return;
  868. }
  869. try {
  870. HWMeeting.setLang(lang);
  871. showPromiseResult("setLang", lang, SUCCESS);
  872. } catch (e) {
  873. showPromiseResult("setLang", lang, FAIL, e);
  874. }
  875. }
  876. // 可视化事件结果
  877. function showPromiseResult(event, params, isSuccess, result) {
  878. let msgBody = document.getElementById("message-body");
  879. let newContent = document.createElement("div");
  880. newContent.textContent = `[API calling] | ${moment().format("YYYY-MM-DD HH:mm:ss")} | ${isSuccess ? 'SUCCESS' : 'FAIL'} | [api]: ${event} | [api-params]: ${JSON.stringify(params)} | [api-result]: ${JSON.stringify(result)}`
  881. newContent.class = 'select-text';
  882. newContent.style = " white-space: pre-wrap;";
  883. // 添加文本节点 到这个新的 div 元素
  884. msgBody.appendChild(newContent);
  885. msgBody.scrollTop = msgBody.scrollHeight;
  886. }
  887. function checkBrowserSupport() {
  888. const result = HWMeeting.checkSystemRequirements().then((result) => {
  889. // 显示结果
  890. showPromiseResult("checkSystemRequirements", null, SUCCESS, result);
  891. }).catch((e) => {
  892. // 显示结果
  893. showPromiseResult("checkSystemRequirements", null, FAIL, e);
  894. })
  895. }
  896. function getSdkVersion() {
  897. const result = HWMeeting.getVersion();
  898. // 显示结果
  899. showPromiseResult("getSdkVersion", null, SUCCESS, result);
  900. }
  901. </script>
  902. <script>
  903. createListener();
  904. </script>
  905. </html>