You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jsync_demo.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. function html_info(){
  2. var get_room_name = window.get_room_name || glob_u.fns.get_room_name
  3. window?.rldi?.setint?.(400)
  4. var domain_prefix = location.hostname.split(".").slice(0,-2).join(".")
  5. var root_div= document.querySelector("#root_div")
  6. root_div.innerHTML=""
  7. var n =document.createElement("SPAN",{})
  8. n.innerHTML = `<div>${domain_prefix}</div><div>room name: ${get_room_name()}</div>
  9. <div><span>jsyncdb:</span><span id="jsyncdb_state">uninitialized</span></div>
  10. `
  11. root_div.append(n)
  12. }
  13. function ds_test2(){
  14. // clog("ds_test2!")
  15. // window.ds_test ?ds_test():glob_u.fns.ds_test()
  16. jsyncdb_init_helper()
  17. // glob_u.fns.ds_test
  18. // ds_test()
  19. }
  20. //
  21. function jsyncdb_init_helper(){
  22. // clog("WS_HELPER")
  23. var fns = window.glob_u.ws.fns
  24. var room_name=glob_u.fns.get_room_name()
  25. // z2="z"
  26. let ws_protocol = "wss:"
  27. location.protocol == "https:" ? "was already set to wss:" : ws_protocol = "ws:"
  28. // location.protocol ?
  29. var o = {
  30. include_participants_data:1,
  31. include_ws_channel_data:1, // required for participants_data to work
  32. // msto.participants and msto.ws_channels will be defined in either case so we don't need to handle cases where some users enable this and some don't
  33. AutoReconnect:false,
  34. // the following options attributes
  35. url:'wss://' + window.location.hostname +`/djc_srv/ws/chat/${room_name}`,
  36. url: `wss://${location.hostname}:5000/echo_c1${location.search}`,
  37. url: `${ws_protocol}//${location.hostname}:5000/echo_c1${location.search}`,
  38. // o.url =
  39. socket_name:"ws1",
  40. ord:glob_u.cb.ws,
  41. methods:{
  42. onmessage:fns.onmessage,
  43. onclose:fns.onclose,
  44. onerror:fns.onerror,
  45. onopen:fns.onopen,
  46. },
  47. fns:{
  48. },
  49. }
  50. var socket = window.glob_u.fns.connect_ws(o)
  51. // clog({socket})
  52. }
  53. // if
  54. window.dev_flag = 1
  55. addEventListener("load",html_info)
  56. addEventListener("load",ds_test2)
  57. function update_ui(o,scope,info){
  58. var clog =console.log
  59. clog("update_ui",{o,scope,info})
  60. // hard coding stuff that will probably change here
  61. switch(info.hkey) {
  62. case "WS_OPEN:":
  63. $("#jsyncdb_state").text("connecting...")
  64. break;
  65. case "WS_CLOSE:":
  66. $("#jsyncdb_state").text("disconnected")
  67. break;
  68. case "WS_MSTO_INITED":
  69. $("#jsyncdb_state").text("connected")
  70. break;
  71. default:
  72. }
  73. }
  74. // function get_room_name() {
  75. // // return "room/name"
  76. // return "room_name"
  77. // }
  78. glob_u.cb.ws.reg_cb(update_ui,"WS_OPEN:","update_ui")
  79. glob_u.cb.ws.reg_cb(update_ui,"WS_CLOSE:","update_ui")
  80. glob_u.cb.ws.reg_cb(update_ui,"WS_MSTO_INITED","update_ui")
  81. // addEventListener("load",db_display)
  82. // msto.example = {key:"val",z:"undefined"}
  83. // clog("??")