您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ws0.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // window.roomName = window.location.pathname.split("/").pop()
  2. /*
  3. */
  4. window.ws_path = `/ws/jsto/`
  5. window.ws_path2 = `/ws/jsto2/`
  6. function roomNameIndex(){
  7. clog("RNI!")
  8. if (window.roomName.includes(".") | !window.roomName){
  9. window.roomName = "aroomlist"
  10. }
  11. }
  12. function msto_conf_info(){
  13. var ret = "init_val"
  14. try {
  15. if (msto.conference.href_const){
  16. ret = msto.conference.href_const
  17. } else {
  18. msto.conference.href_const = window.location.href
  19. ret = msto.conference.href_const
  20. }
  21. } catch (err){
  22. ret = "err"
  23. }
  24. return ret
  25. }
  26. function get_conf_info(){
  27. var href_const = msto_conf_info()
  28. var state = APP.store.getState()
  29. var app_conference = state["features/base/conference"]
  30. var ret = jc({
  31. href:msto_conf_info(),
  32. locked:app_conference.locked ? true : false,
  33. name:app_conference.name,
  34. num_participants:state["features/base/participants"].length,
  35. hosts:state["features/base/config"].hosts,
  36. })
  37. return ret
  38. }
  39. function connect_ws(ws_path = window.ws_path){
  40. if(!window.roomName){
  41. // return
  42. }
  43. if (window.chatSocket && window.chatSocket.readyState < 2) {
  44. clog("WSS ALLREADY CONNECTED!")
  45. return
  46. }
  47. clog("WSS CONTECTING")
  48. var chatSocket = new WebSocket(
  49. 'wss://' + window.location.host + ":8943" +
  50. // '/ws/chat/' + window.roomName + `/?room=${window.roomName}`);
  51. ws_path + window.roomName + `/?room=${window.roomName}`);
  52. window.chatSocket =chatSocket
  53. chatSocket.onmessage = wsfn.onmessage
  54. chatSocket.onclose = wsfn.onclose
  55. // window.chatSocket=chatSocket
  56. }
  57. wsfn = {}
  58. wsfn.onmessage = function(e) {
  59. var data = JSON.parse(e.data);
  60. // clog("WS ONMSG",data)
  61. if (data.message != undefined){
  62. wsfn.on_chat_message(data)
  63. }
  64. if (data.type != undefined && wsfn[data.type]){
  65. wsfn[data.type](data,e)
  66. }
  67. // chatSocket.onmessage = onmessage
  68. // onclose
  69. // clog(data)
  70. // clog("~",e)
  71. // var message = data['message'];
  72. // document.querySelector('#chat-log').value += (message + '\n');
  73. };
  74. wsfn.pre_config = function(data,e){
  75. window.pre_config=data
  76. clog("PRE_CONFIG",data,e)
  77. if (data.config && data.config.password_enabled){
  78. setPasswordHelper(data.config.password)
  79. }
  80. }
  81. wsfn.pingpong = function(data) {
  82. clog(">< pingpong")
  83. // if (window.prt && prt.getLocalParticipant(APP.store).role == "moderator"){
  84. /*
  85. if (0){
  86. try {
  87. wsfn.s({pop:get_conf_info()})
  88. } catch (err){
  89. clog("rx4_err:",err)
  90. }
  91. }
  92. if (0 && window.iammod){
  93. var state = APP.store.getState()
  94. // locked
  95. // clog("IS MOD TRU")
  96. wsfn.s({
  97. pop:state["features/base/participants"].length,
  98. locked:state["features/base/conference"].locked ? true : false,
  99. // pop:`state["features/base/participants"].length`,
  100. // locked:`state["features/base/conference"].locked ? true : false`,
  101. // locked:{a: + ""},
  102. pop:{href:window.location.href,num_participants:state["features/base/participants"].length},
  103. abc:"a",
  104. test:"a",
  105. })
  106. } else
  107. if (!window.prt) {
  108. clog("window.prt")
  109. }
  110. */
  111. }
  112. wsfn.on_chat_message = function(data) {
  113. // var data = JSON.parse(e.data);
  114. var message = data['message'];
  115. // document.querySelector('#chat-log').value += (message + '\n');
  116. };
  117. wsfn.onclose = function(e) {
  118. console.error('Chat socket closed unexpectedly');
  119. if (window.location.pathname.length > 2 && window.location.pathname[1] == "f"){
  120. clog("WSS NO CONN")
  121. } else {
  122. setTimeout(connect_ws,1400)
  123. }
  124. clog("window.location.pathname[1]",window.location.pathname[1])
  125. };
  126. wsfn.s= function(o){
  127. chatSocket.send(JSON.stringify(o));
  128. }
  129. function e(o){
  130. chatSocket.send(JSON.stringify({"dbg":o}));
  131. }
  132. function itx(o){
  133. ret = ""
  134. for (var [k,v] of Object.entries(o)){
  135. ret += k +":" + v.pop + " ~"+ v.t+ "\n"
  136. // clog(k,v)
  137. }
  138. return ret
  139. }
  140. //
  141. /*
  142. roomNameIndex()
  143. if (window.location.pathname.length > 2 && window.location.pathname[1] == "f"){
  144. // clog("WSS NO CONN")
  145. } else {
  146. }
  147. */
  148. // if
  149. // connect_ws()
  150. // clog("zzzzzz")