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.

nt.js 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. window._APP = {}
  2. var APP = window._APP
  3. // FILE:m_req
  4. window.ifn_obj = window.ifn_obj || { init_conf_join:[],iammod:[] }
  5. function get_mod(participants){
  6. if (!participants){
  7. participants = get_participants()
  8. }
  9. var k,v
  10. for (v of participants){
  11. if (v.role == "moderator"){
  12. clog("cui_mod_cd",[v],v.corner_data)
  13. return v
  14. }
  15. }
  16. }
  17. function get_participants(){
  18. return APP.store.getState()["features/base/participants"]
  19. }
  20. function get_local(participants){
  21. if (!participants){
  22. participants = get_participants()
  23. }
  24. var k,v
  25. for (v of participants){
  26. if (v.local){
  27. return v
  28. }
  29. }
  30. return APP.store.getState()["features/base/participants"]
  31. }
  32. function amimod() {
  33. try {
  34. return get_local().role == "moderator"
  35. } catch (e) {
  36. console.error("AM I MOD ERR: is evrything inited?",e)
  37. // clog("AM I MOD ERR: is evrything inited?",e)
  38. }
  39. }
  40. function Someone_Left_Handler(o){
  41. delete msto.participants[o.action.participant.id]
  42. }
  43. // reflow all your filmstrips
  44. function Someone_Left_or_Joined_Handler(o){
  45. try {
  46. APP.store.dispatch(window.glob_react.video_layout.setTileView(false))
  47. APP.store.dispatch(window.glob_react.rf_filmstrip.setFilmstripVisible(false))
  48. if (! $("#vspace_filmstrip_template").length){
  49. init_api6()
  50. }
  51. refresh_toolbars()
  52. mod_sort()
  53. new_move()
  54. dispatch_resize()
  55. } catch(err) {
  56. console.error("Someone_Left_or_Joined_Handler err:", err)
  57. }
  58. }
  59. // dispay moderator toolbar if you become moderator
  60. window.iammod = window.iammod || false
  61. function amimodnow(){
  62. var iammod = amimod()
  63. window.iammod = iammod
  64. if (iammod){
  65. run_ifn_cbs("iammod")
  66. refresh_toolbars()
  67. }
  68. }
  69. // run init callbacks after CONFERENCE_JOINED
  70. function cji(){
  71. if (window.init_m){
  72. // setTimeout(window.init_m())
  73. }
  74. if (ifn_obj && ifn_obj.init_conf_join){
  75. var k,v
  76. for ([k,v] of Object.entries(ifn_obj.init_conf_join)){
  77. v()
  78. }
  79. }
  80. }
  81. function run_ifn_cbs(cb_name,args){
  82. jlog("RCB","run_ifn_cbs")
  83. try {
  84. if (ifn_obj && ifn_obj[cb_name]){
  85. var k,v
  86. for ([k,v] of Object.entries(ifn_obj[cb_name])){
  87. v()
  88. }
  89. } else {}
  90. } catch (err) {
  91. clog("ifn_obj not glob_mx_cbs_err:",err)
  92. }
  93. }
  94. // safe to remove
  95. function stv(o,ta){
  96. clog(o,ta)
  97. }
  98. function SET_TOOLBOX_info(o,that){
  99. // clog("SET_TOOLBOX_info",o,that)
  100. clog("ti",o.action.type,o.action)
  101. }
  102. function share_vid_info(o,that,m = true){
  103. clog("svi",m,o.action.type,o)
  104. }
  105. qxi_match = {
  106. share_vid:{
  107. startsWith:"",
  108. includes:"SHARE",
  109. endsWith:"",
  110. // arr:["SET_TOOLBAR_HOVERED"],
  111. // arr:[],
  112. // arr_or:["PARTICIPANT_UPDATED","SET_LOADABLE_AVATAR_URL"],
  113. arr_or:["PARTICIPANT_JOINED","PARTICIPANT_LEFT"],
  114. },
  115. }
  116. // 2m_req.js?c=023?v=39:163 QXI PARTICIPANT_UPDATED
  117. // 2m_req.js?c=023?v=39:163 QXI SET_LOADABLE_AVATAR_URL
  118. function qxi_jnk_match(o,that,m,fn){
  119. var flag = "~"
  120. var flag0 = 0
  121. var rf = []
  122. rf.push(flag0)
  123. m.startsWith ? flag0 =!o.action.type.startsWith(m.startsWith) || flag0 : 0
  124. rf.push(flag0)
  125. m.includes ? flag0 = !o.action.type.includes(m.includes) || flag0 : 0
  126. rf.push(flag0)
  127. m.endsWith ? flag0 = !o.action.type.endsWith(m.endsWith) || flag0 : 0
  128. rf.push(flag0)
  129. m.arr ? flag0 = !m.arr.includes(o.action.type) || flag0 : 0
  130. m.arr_or ? flag0 = !m.arr_or.includes(o.action.type) && flag0 : 0
  131. rf.push(flag0)
  132. if (!flag0){
  133. fn(o,that)
  134. } else {
  135. // fn(o,that,!!0)
  136. }
  137. // clog("qxi_jnk_match",o.action.type,flag0,rf,m)
  138. }
  139. qxi_skip = [
  140. "SET_TOOLBAR_HOVERED",
  141. "SET_TOOLBOX_TIMEOUT",
  142. "SET_TOOLBOX_TIMEOUT_MS",
  143. "CLEAR_TOOLBOX_TIMEOUT",
  144. "SET_TOOLBOX_VISIBLE",
  145. "_ADD_AUDIO_ELEMENT",
  146. "REGISTER_SOUND",
  147. "SET_LOADABLE_AVATAR_URL",
  148. ]
  149. qxi_skip0 = [
  150. "SET_TOOLBAR_HOVERED",
  151. ]
  152. function run_qxi_cbs(key,o){
  153. jlog("RCB","run_qxi_cbs")
  154. var k,v
  155. // clog("RUN_HOOK_CB??",key,glob_mx.hook_cb[key])
  156. try {
  157. } catch (err) {
  158. clog("qxi_cb glob_mx_cbs_err:",err)
  159. }
  160. for ([k,v] of Object.entries(glob_mx.qxi_cb[key]|| {}) ) {
  161. // clog("RUN_HOOK_CB:",k,v)
  162. v(o)
  163. }
  164. }
  165. function qxi2(o){
  166. var k = o.action.type
  167. clog("qxi2",k,o)
  168. return
  169. var k = o.action.type
  170. glob_dbg.qxi_map.setD(k,0)
  171. // var k,v
  172. glob_dbg.qxi_map.set(k,glob_dbg.qxi_map.get(k) + 1)
  173. if (qxi_skip.includes(k)){
  174. return
  175. }
  176. clog("qxi2",k,o)
  177. }
  178. function qxi_event(o){
  179. var cb
  180. /*
  181. if (o.action.type == "CONFERENCE_JOINED"){
  182. clog("conf_joined x")
  183. }
  184. */
  185. run_qxi_cbs(o.action.type,o)
  186. /*
  187. cb = glob_mx.qxi_test[o.action.type]
  188. if (cb){
  189. cb(o)
  190. // SET_OVERFLOW_MENU_VISIBLE
  191. }
  192. */
  193. // glob_mx.qxi_test
  194. }
  195. function reg_qxi(action_type,cb){
  196. glob_mx.qxi_test[action_type] = cb
  197. }
  198. // window.glob_dbg.qxi_map = window.glob_dbg.qxi_map || new Map()
  199. // this is called with setTimeout so we can throw errors without wrecking everything
  200. function dev_middleware_listner(o) {
  201. if (!o.action.type){
  202. return
  203. }
  204. // /*
  205. if (o.action.type != "ENDPOINT_MESSAGE_RECEIVED"){
  206. // CONFERENCE_JOINED
  207. qxi2(o)
  208. qxi_event(o)
  209. // if (o.action.type.startsWith("SET_TOOLBOX_" || o.action.type == "TOGGLE_TOOLBOX_VISIBLE")){
  210. // SET_TOOLBOX_info(o,this)
  211. // }
  212. // if ()
  213. // qxi_jnk_match(o,this,qxi_match.share_vid,share_vid_info)
  214. // clog("QXI",o.action.type)
  215. }
  216. // */
  217. switch(o.action.type){
  218. case "PARTICIPANT_UPDATED":
  219. window.iammod ? 0 : amimodnow()
  220. break;
  221. case "PARTICIPANT_LEFT":
  222. setTimeout(Someone_Left_Handler,1,o)
  223. // setTimeout(Someone_Left_Handler,1000,o)
  224. case "PARTICIPANT_JOINED":
  225. setTimeout(Someone_Left_or_Joined_Handler,1,o)
  226. // setTimeout(Someone_Left_or_Joined_Handler,300,o)
  227. break;
  228. // case "SET_TILE_VIEW":
  229. // stv(o,[this,arguments])
  230. break;
  231. case "CONFERENCE_JOINED":
  232. setTimeout(cji,1)
  233. break;
  234. }
  235. }
  236. // SET_TOOLBOX_ENABLED
  237. // SET_TOOLBOX_
  238. // FILE:_m_utils
  239. if (!window.glob_mx){
  240. // window.glob_mx={}
  241. }
  242. function disp(o){
  243. APP.store.dispatch(o)
  244. }
  245. // default event handler this should match all events
  246. mhndlr_opt_null = {
  247. from: undefined,
  248. handler: "onAll",
  249. id: null,
  250. name: null,
  251. // "http://jitsi.org/jitmeet"
  252. ns: null,
  253. options: {matchBareFromJid: false, ignoreNamespaceFragment: false},
  254. type: null,
  255. user: true,
  256. cstr:"test"
  257. };
  258. mhndlr_opt_x = {
  259. cstr:"?",
  260. ns:"corner_mx",
  261. handler:mhndlr,
  262. }
  263. function add_handler_m(handler) {
  264. var phx = APP.connection.xmpp.connection._stropheConn.handlers[0].__proto__;
  265. var hxa=Object.create(phx)
  266. Object.assign(hxa,mhndlr_opt_null,handler)
  267. APP.connection.xmpp.connection._stropheConn.addHandlers.push(hxa)
  268. }
  269. function tmsgx(data,tag="div",attrs={}){
  270. // return
  271. var ns = {xmlns:"corner_mx"}
  272. var msg = $build("message",{ to: window.APP.conference._room.room.roomjid,
  273. type: 'groupchat',
  274. });
  275. var payload=JSON.stringify(data)
  276. Object.assign({},ns,attrs)
  277. msg.c(tag, payload,Object.assign({},ns,attrs)).up();
  278. // console.log("zzzz")
  279. APP.conference._room.room.connection.send(msg)
  280. }
  281. function tmsgx2(data,opt_arg={},attrs={}){
  282. // return
  283. dflt_opt = {
  284. tag:"code",
  285. type:"chat",
  286. to:window.APP.conference._room.room.roomjid,
  287. }
  288. var opt = Object.assign({},dflt_opt,opt_arg)
  289. var ns = {xmlns:"corner_mx"}
  290. var msg = $build("message",{ to: opt.to,
  291. type: opt.type,
  292. });
  293. var payload=JSON.stringify(data)
  294. Object.assign({},ns,attrs)
  295. msg.c(opt.tag, payload,Object.assign({},ns,attrs)).up();
  296. // console.log("zzzz")
  297. APP.conference._room.room.connection.send(msg)
  298. }
  299. function tmsgx3(data,opt_arg={},attrs={}){
  300. // return
  301. dflt_opt = {
  302. tag:"code",
  303. // type:"chat",
  304. to:window.APP.conference._room.room.roomjid,
  305. }
  306. var opt = Object.assign({},dflt_opt,opt_arg)
  307. clog("T:",data,opt,opt.type)
  308. if (!opt.type){
  309. clog("NO TYPE")
  310. opt.to == dflt_opt.to ? opt.type = "groupchat" : opt.type = "chat"
  311. }
  312. clog("T:",data,opt,opt.type)
  313. var ns = {xmlns:"corner_mx"}
  314. var msg = $build("message",{ to: opt.to,
  315. type: opt.type,
  316. // from: "nnnx@conference.jfidev.com/3db7bf15",
  317. // xtra: "nnnx@conference.jfidev.com/3db7bf15",
  318. });
  319. var payload
  320. if (typeof(data) == "string"){
  321. payload=data
  322. } else {
  323. payload=JSON.stringify(data)
  324. }
  325. Object.assign({},ns,attrs)
  326. msg.c(opt.tag, payload,Object.assign({},ns,attrs)).up();
  327. // console.log("zzzz")
  328. APP.conference._room.room.connection.send(msg)
  329. }
  330. function mhndlr_rld_dflt(a0,a1,a2,a3,a4){
  331. clog("mhndlr... dflt")
  332. return true
  333. }
  334. if (!window.mhndlr_rld){
  335. window.mhndlr_rld = mhndlr_rld_dflt
  336. }
  337. function mhndlr(a0,a1,a2,a3,a4){
  338. // clog("MH!")
  339. setTimeout(window.mhndlr_rld,1,this,a0,a1,a2,a3,a4)
  340. return true
  341. }
  342. function init_mx(){
  343. clog("INITMX")
  344. add_handler_m(mhndlr_opt_x)
  345. // add_handler_m(mhndlr_opt_x_all)
  346. }
  347. // init_mx will be called once we join th confrence
  348. ifn_obj.init_conf_join.push(init_mx)
  349. // FILE:m_utils
  350. // This file creates and syncs msto
  351. // msto is a recursive proxy that synchronizes itself between all meeting participants
  352. // you can get a clone of the object by typing jc(msto) into your dev console
  353. if (!window.glob_mx ){
  354. window.glob_mx={}
  355. glob_mx.prom = {}
  356. glob_mx.event_handlers = {}
  357. glob_mx.ws_event_handlers = {}
  358. glob_mx.flags = {}
  359. glob_mx.cb = {
  360. init_db:{}
  361. }
  362. glob_mx.hook_cb = {
  363. }
  364. glob_mx.qxi_cb = {}
  365. glob_mx.qxi_test = {
  366. }
  367. glob_mx.filmstrip_handlers = {}
  368. //glob_mx.filmstrip_handlers = glob_mx.filmstrip_handlers || {}
  369. }
  370. dlog = nop
  371. function match(mx,m,o){
  372. var k,v,k2,v2
  373. var r = 0
  374. for ([k,v] of Object.entries(m || {})){
  375. v2 = o[k]
  376. if (typeof(v) == "string" && typeof(v2) == "string") {
  377. r += !(v==v2)
  378. } else if (Array.isArray(v) && Array.isArray(v2)){
  379. r += !(isSubset_arr(v,v2))
  380. } else if (Array.isArray(v) && typeof(v2) == "string"){
  381. // r += !(isSubset_arr(v2,v))
  382. r += !v.includes(v2)
  383. } else if (Array.isArray(v2) && typeof(v) == "string"){
  384. r += !(v2.includes(v))
  385. }
  386. if (r){
  387. return !r
  388. }
  389. }
  390. return !r
  391. }
  392. function isSubset(subset,superset){
  393. for (var elem of subset) {
  394. if (!superset.includes(elem)) {
  395. return false;
  396. }
  397. }
  398. return true;
  399. }
  400. function isSubset_arr(subset,superset){
  401. for (var elem of subset) {
  402. if (Array.isArray(elem)){
  403. if (!new Set(elem).intersection(superset).size){
  404. return false
  405. }
  406. } else if (!superset.includes(elem)) {
  407. return false;
  408. }
  409. }
  410. return true;
  411. }
  412. function dispatch_ws_events3(e,key){
  413. var k,v
  414. // let dlog =clog
  415. clog("dispatch_ws_events3",e,{that:this,e,key})
  416. // return
  417. // e.payload.etype ? 1 : e.payload.etype = "null"
  418. e.parsed.etype ? 1 : e.parsed.etype = "null"
  419. var mflag =0
  420. dlog("dispatch_events??",e,key)
  421. for ([k,v] of Object.entries(glob_mx.ws_event_handlers || {}) ) {
  422. dlog("dispatch_events:",k)
  423. if (v.m){
  424. // mflag = match({},v.m,e.payload)
  425. mflag = match({},v.m,e.parsed)
  426. mflag ? v.fn(e,key) : 1
  427. }
  428. }
  429. }
  430. function dispatch_ws_events(e,key){
  431. var k,v
  432. // let dlog =clog
  433. clog("dispatch_ws_events",{that:this,e,key})
  434. // return
  435. // e.payload.etype ? 1 : e.payload.etype = "null"
  436. e.parsed.etype ? 1 : e.parsed.etype = "null"
  437. var mflag =0
  438. dlog("dispatch_events??",e,key)
  439. for ([k,v] of Object.entries(glob_mx.ws_event_handlers || {}) ) {
  440. dlog("dispatch_events:",k)
  441. if (v.m){
  442. // mflag = match({},v.m,e.payload)
  443. mflag = match({},v.m,e.parsed)
  444. mflag ? v.fn(e,key) : 1
  445. }
  446. }
  447. }
  448. function dispatch_events(e,key){
  449. var k,v
  450. clog("dispatch_events_z",{that:this,e,key})
  451. e.parsed.etype ? 1 : e.parsed.etype = "null"
  452. var mflag =0
  453. dlog("dispatch_events??",e,key)
  454. for ([k,v] of Object.entries(glob_mx.event_handlers || {}) ) {
  455. dlog("dispatch_events:",k)
  456. if (v.m){
  457. mflag = match({},v.m,e.parsed)
  458. mflag ? v.fn(e) : 1
  459. }
  460. }
  461. }
  462. function run_cbs(key){
  463. jlog("RCB","run_cbs")
  464. var k,v
  465. dlog("RUN_CB??",key,glob_mx.cb[key])
  466. for ([k,v] of Object.entries(glob_mx.cb[key]|| {}) ) {
  467. dlog("RUN_CB:",k)
  468. v()
  469. }
  470. }
  471. function run_hook_cbs(key,o){
  472. jlog("RCB","run_hook_cbs")
  473. var k,v
  474. // dlog("RUN_HOOK_CB??",key,glob_mx.hook_cb[key])
  475. for ([k,v] of Object.entries(glob_mx.hook_cb[key]|| {}) ) {
  476. // dlog("RUN_HOOK_CB:",k)
  477. v(o)
  478. }
  479. }
  480. function wait(ms) {
  481. return new Promise(r => setTimeout(r, ms));
  482. }
  483. function attr_info(n){
  484. var k,v
  485. var ret ={}
  486. // clog(".")
  487. for (k in n.attributes){
  488. // clog(k)
  489. }
  490. // clog("~")
  491. for (k of n.attributes){
  492. // for (k of n.attributes){
  493. // clog(k)
  494. }
  495. // clog("--")
  496. for ([k,v] of Object.entries(n.attributes)){
  497. // clog(k,v,v+"+")
  498. // clog("+",[k,v],v)
  499. ret[v.name]= v.value
  500. // clog(typeof(k),typeof(v))
  501. }
  502. return ret
  503. }
  504. // ai.from.split((a0,a1,a2,a3)=>{clog({a0,a1,a2,a3});return "z"})
  505. // tmsgx3({type:"db_sync_request"})
  506. function mhndlr_rld(that,m){
  507. try {
  508. window.mx=m
  509. var n = m.querySelector(`code`)
  510. if (!n){return}
  511. var parsed = JSON.parse(n.innerHTML)
  512. var ai = attr_info(m)
  513. window.ai=ai
  514. // clog("FROM",ai.from == glob_mx.all_jids[0])
  515. // var id = ai.from.split().slice(-1)[0]
  516. var id = ai.from.split("/").pop()
  517. dlog("mhndlr_rld2",m,parsed,n,n.dataset)
  518. var o = parsed.payload
  519. switch (parsed.type){
  520. case "set_msg":
  521. pf._set_recv(o.path,o.key,o.val)
  522. window._set_recv_cb ? window._set_recv_cb({that:this,m,n,o,ai,id}): 0
  523. // window?._set_recv_cb?.({that:this,m,n,o,ai,id}) opt_chain
  524. break;
  525. case "event":
  526. dlog("~event~",parsed)
  527. dispatch_events({parsed,ai,m,that})
  528. break;
  529. case "msg_test":
  530. dlog("msg_test",parsed)
  531. break;
  532. case "db_sync_request":
  533. // tmsgx3({type:"db_sync_response",payload:pf.root})
  534. tmsgx3({type:"db_sync_response",payload:pf.root},{to:ai.from})
  535. dlog("db_sync_request",parsed)
  536. break;
  537. case "db_sync_response":
  538. if (id == glob_mx.local_id){
  539. dlog( "db_sync_response ...")
  540. break
  541. }
  542. if (glob_mx.prom.init_db_resolve){
  543. glob_mx.prom.init_db_resolve({aaa:"dsr",pl:parsed.payload})
  544. }
  545. dlog("db_sync_response",ai.from == glob_mx.local_id,ai.from,parsed)
  546. break;
  547. }
  548. /*
  549. if (parsed.type == "set_msg"){
  550. var o = parsed.payload
  551. pf._set_recv(o.path,o.key,o.val)
  552. }
  553. if (parsed.type == "msg_test"){
  554. clog("msg_test",parsed)
  555. }
  556. */
  557. } catch (err) {
  558. clog("mhndlr err:",err)
  559. }
  560. return true
  561. }
  562. isProxy = Symbol("isProxy")
  563. tlu = {
  564. object:"",
  565. string:true,
  566. number:true,
  567. undefined:true,
  568. boolean:true,
  569. }
  570. function type_info(o){
  571. var t
  572. var flags = {
  573. leaf:false,
  574. deep_not_prx:false,
  575. prx:false,
  576. isObj:false,
  577. isArr:false,
  578. els:false,
  579. }
  580. t = typeof(o)
  581. flags.t=t
  582. if (!(o === null)){
  583. flags.isArr = Array.isArray(o)
  584. flags.isObj = Object.prototype == o.__proto__
  585. }
  586. if (tlu[t] === true || o === null){
  587. flags.leaf = true
  588. } else if (t == "object" && o.__prx){
  589. flags.prx = true
  590. } else if (t == "object" && (flags.isArr || flags.isObj)){
  591. flags.prx = false
  592. flags.deep_not_prx = true
  593. } else {
  594. clog("ELSE")
  595. flags.els = true
  596. }
  597. return flags
  598. clog(t,flags)
  599. }
  600. function deep_prop_v0(o,p){
  601. try {
  602. var arr = jc(p)
  603. var ret = o
  604. while (arr.length){
  605. // clog("deep_prop",arr,ret)
  606. ret = ret[arr.shift()]
  607. }
  608. // clog("deep_prop ret",ret)
  609. return ret
  610. } catch(err){console.error("DEEP_PROP ERR:",err)}
  611. }
  612. delete Proxy_Factory
  613. {
  614. class Proxy_Factory {
  615. constructor(o,n="dflt"){
  616. this.db = o
  617. this.n = n
  618. this.hidden_props = ["add_proxy","_set","walker","walker_start","prxy","_sett","_sett2"]
  619. this._pub_cb =[]
  620. this.__prx = true
  621. this.SymPrx = Symbol("SymPrx")
  622. }
  623. init(o){
  624. // dlog("BP",this,this.baseProp,this.__proto__.baseProp,window.baseProp)
  625. this.root = o
  626. }
  627. sync(o){
  628. this.root = jc(o.root)
  629. o._pub_cb.push(this._set_recv.bind(this))
  630. }
  631. get prxy(){
  632. return this
  633. }
  634. _set(o,k,v,prx,a0){
  635. this.obj[k]=prx
  636. }
  637. _sett(o,k,v,prx,a0){
  638. dlog("_SETT",this,arguments)
  639. }
  640. _sett2(o,k,v,prx,a0){
  641. dlog("_SETT2",this,arguments)
  642. }
  643. set_pub(obj, prop, val,receiver){
  644. // dlog("qia_pub",obj, prop, val,receiver)
  645. // dlog("qia_pub2",this.n,obj.__path_arr, prop, jx(val))
  646. this._set_pub(obj.__path_arr, prop, jx(val))
  647. }
  648. _set_pub(path,key,val){
  649. var k,v
  650. // /*
  651. tmsgx({
  652. "type":"set_msg",
  653. "payload":{path,key,val},
  654. },"code")
  655. // */
  656. for (v of this._pub_cb){
  657. v(path,key,val)
  658. }
  659. }
  660. _set_recv(path,prop,val){
  661. // return
  662. var p = path
  663. var nprop = deep_prop_v0(this.root,p)
  664. var dpth = nprop.__dpth
  665. if (tlu[typeof(val)]){
  666. nprop._set(nprop,prop,val,val)
  667. } else {
  668. nprop._set(nprop,prop,val,new Proxy(val,this))
  669. nprop[prop].add_proxy(nprop,prop,val,dpth+1)
  670. }
  671. // var tf = {}
  672. // this.walker(nprop[prop],tf,dpth+2)
  673. this.walker(nprop[prop],{},dpth+2)
  674. }
  675. set(obj, prop, val,receiver){
  676. // dlog("prx_db set ",this,obj, prop, val,receiver,val.__prx)
  677. // clog("prx_db set ",{that:this,obj, prop, val,receiver},val.__prx)
  678. // clog("prx_db set ",obj.__path_arr)
  679. if (obj[prop] === val){
  680. return Reflect.set(...arguments)
  681. }
  682. this.set_pub(obj, prop, val,receiver)
  683. this.event_proc("set")
  684. if ("__prx" == prop){
  685. this.__prx=val
  686. return this.__prx
  687. }
  688. if (typeof(val) === "object" && val != null && !(val.__prx)){
  689. var ret = Reflect.set(...arguments)
  690. this.set_obj(obj, prop, val,receiver)
  691. return ret
  692. }
  693. return Reflect.set(...arguments)
  694. }
  695. get(obj, prop,receiver){
  696. // dlog("prx_db get ...",prop==isProxy,this,obj, prop,receiver)
  697. if (this.hidden_props.includes(prop)){
  698. switch (prop){
  699. case "add_proxy":
  700. return this.add_proxy.bind(this)
  701. break;
  702. case "prxy":
  703. return this
  704. case "_set":
  705. // dlog("_SET")
  706. // return this._set.bind({this})
  707. return this._set.bind({that:this,obj, prop,receiver})
  708. case "_sett":
  709. return this._sett.bind({that:this,obj, prop,receiver})
  710. case "_sett2":
  711. return this._sett2.bind({that:this})
  712. case "walker_start":
  713. return this.walker_start
  714. case "walker":
  715. return this.walker
  716. break;
  717. }
  718. }
  719. if (isProxy == prop){ return true }
  720. if ("__prx" == prop){ return this.__prx }
  721. return Reflect.get(...arguments)
  722. }
  723. add_proxy(o,k,v,dpth){
  724. // clog("~add_proxy~",o,k,v,dpth)
  725. // clog("~add_proxy~",o.__prx,o,k,v,dpth,xpath)
  726. var xpath = o.__path
  727. var apath = o.__path_arr
  728. this.event_proc("add_proxy")
  729. if (!apath){
  730. apath=[]
  731. }
  732. if (!xpath){
  733. xpath="ROOT!"
  734. }
  735. Object.defineProperty(v,"__path_arr",Object.assign({value:apath.concat(k),},this.baseProp))
  736. Object.defineProperty(v,"__path",Object.assign({value:xpath+":"+k,},this.baseProp))
  737. Object.defineProperty(v,"__dpth",Object.assign({value:dpth,},this.baseProp))
  738. // Object.defineProperty(v,"__dbg",Object.assign({value:{},},this.baseProp))
  739. }
  740. set_obj(obj, prop, val,receiver){
  741. var dpth = obj.__dpth
  742. var tf = {}
  743. this.walker(receiver,tf,dpth)
  744. }
  745. walker(o,tfo,dpth=0){
  746. // dlog("qia WALK",this)
  747. if (dpth > 7){
  748. console.error("MAX DEPTH")
  749. return
  750. }
  751. var k,v
  752. var tf
  753. for ([k,v] of Object.entries(o)){
  754. tf = type_info(v)
  755. if (tf.deep_not_prx){
  756. o._set(o,k,v,new Proxy(v,this.prxy))
  757. o[k].add_proxy(o,k,v,dpth)
  758. this.walker(o[k],tf,dpth+1)
  759. }
  760. }
  761. }
  762. walker_start(o,dpth){
  763. var tf = type_info(o)
  764. o.add_proxy({},[],o,-1)
  765. this.walker(o,tf,0)
  766. }
  767. event_proc(e){}
  768. }
  769. window.Proxy_Factory = Proxy_Factory
  770. Proxy_Factory.prototype.baseProp={
  771. writable: true,
  772. // enumerable: true,
  773. enumerable: false,
  774. configurable: true,
  775. }
  776. }
  777. function arr_match(m,o){
  778. var k,v
  779. var r = 0
  780. for ([k,v] of Object.entries(m || {})){
  781. if (o[k] != v.valueOf()){
  782. r += 1
  783. return !r
  784. }
  785. // for ([k,v] in m){
  786. // case
  787. // dlog(k,v)
  788. }
  789. return !r
  790. }
  791. permissions_def = {
  792. participants:{
  793. m:["participants"],
  794. fn(set_scope,match){
  795. // clog("FN....",match.fp,match.fp[1] == window.glob_mx.local_id)
  796. if (match.fp[1] != window.glob_mx.local_id)
  797. throw "permission err"
  798. return
  799. },
  800. }
  801. }
  802. //
  803. // msto.my_data.prxy.__proto__.__proto__.set.call(msto.my_data.prxy,msto.participants,"abc2",{})
  804. permissions_def__set = {
  805. participants:{
  806. m:["participants"],
  807. fn(set_scope,match){
  808. dlog("FN....",match.fp,match.fp[1] == window.glob_mx.local_id)
  809. if (match.fp[1] != window.glob_mx.local_id)
  810. // throw "permission err"
  811. return
  812. },
  813. }
  814. }
  815. {
  816. class Proxy_Permissions extends Proxy_Factory {
  817. constructor(a,a1){
  818. super(...arguments)
  819. }
  820. set(obj, prop, val,receiver){
  821. // clog("PRX_PERM",obj.__path_arr,prop)
  822. var k,v
  823. var r
  824. var matched
  825. var fp = obj.__path_arr.concat(prop)
  826. for ([k,v] of Object.entries(permissions_def)){
  827. matched = arr_match(v.m,fp)
  828. if (matched){
  829. r = v.fn({that:this,obj, prop, val,receiver},{fp,k,v}) || {}
  830. }
  831. // if (r.return)
  832. }
  833. // case
  834. // if (obj.__path_arr && obj.__path_arr.length){}
  835. return super.set(obj, prop, val,receiver)
  836. }
  837. _set(){
  838. // clog("Proxy_Permissions _set")
  839. super._set(...arguments)
  840. }
  841. }
  842. window.Proxy_Permissions = Proxy_Permissions
  843. }
  844. msto_z = {
  845. // private_local:{},
  846. // participant_local:{},
  847. conference:{},
  848. participants:{
  849. },
  850. }
  851. function pfnf(o){
  852. return function(resolve, reject){
  853. o.resolve=resolve
  854. o.reject=reject
  855. // clog(arguments)
  856. }
  857. }
  858. function init_db_cb(){
  859. }
  860. function init_sync_participant(){
  861. }
  862. function init_db(objx){
  863. var obj
  864. if (objx.participants){
  865. obj = objx
  866. } else {
  867. obj = objx.pl
  868. }
  869. // var obj = obj.pl
  870. clog("INIT DB...",objx,obj)
  871. pf = new Proxy_Permissions({},"pf")
  872. msto_prx = new Proxy(obj,pf)
  873. window.msto_prx0 =msto_prx
  874. // msto_prx = new Proxy(msto_z,pf)
  875. pf.init(msto_prx)
  876. msto_prx.walker_start(msto_prx)
  877. pf.root.participants[glob_mx.local_id] = {}
  878. glob_mx.flags.init_db = true
  879. window.msto= {
  880. participants:pf.root.participants,
  881. conference:pf.root.conference,
  882. my_data:pf.root.participants[glob_mx.local_id],
  883. private_local:{},
  884. set_listeners:{
  885. },
  886. }
  887. // var k,v
  888. clog("RUN_CB...")
  889. run_cbs("init_db")
  890. }
  891. function init_mu(persistent_mods){
  892. // .role == "moderator"
  893. // clog(">>>>>>>>>>>>>>>>>>>.. RUN_CB")
  894. var participants = get_participants()
  895. // clog(participants)
  896. var local = get_local(participants)
  897. if (window.glob_mx.local_id && persistent_mods && local.role=="moderator"){
  898. // if window.glob_mx.local_id
  899. // clog("no RUN_CB")
  900. return
  901. }
  902. window.glob_mx.local_id = local.id
  903. var k,v
  904. window.glob_mx.all_ids = []
  905. window.glob_mx.all_jids = []
  906. for (v of participants){
  907. window.glob_mx.all_ids.push(v.id)
  908. window.glob_mx.all_jids.push(`nnnx@conference.jfidev.com/${v.id}`)
  909. }
  910. var rr = {}
  911. var prom1 = new Promise(pfnf(rr));
  912. prom1.then(init_db)
  913. // setTimeout(rr.reject,2000,"RESP DB Timeout")
  914. // setTimeout(rr.resolve,4000,"RESP DB Timeout")
  915. // setTimeout(rr.resolve,4000,msto_z)
  916. // setTimeout(rr.resolve,4000,{aaa:"timedout",pl:msto_z})
  917. setTimeout(rr.resolve,5000,{aaa:"timedout",pl:msto_z})
  918. if (participants.length > 1){
  919. glob_mx.prom.init_db_resolve = rr.resolve
  920. tmsgx3({type:"db_sync_request"})
  921. } else {
  922. // glob_mx.prom.init_db_resolve(msto_z)
  923. rr.resolve(msto_z)
  924. // init_db()
  925. }
  926. }
  927. function create_db(){
  928. }
  929. function isident(){
  930. return JSON.stringify(pf.root) == JSON.stringify(pf2.root)
  931. }
  932. function init_mu_runner(){
  933. if (window.glob_mx.conf_joined){
  934. init_mu(...arguments)
  935. }
  936. }
  937. function init_mx2(){
  938. clog("INITMX3")
  939. window.glob_mx.conf_joined =1
  940. init_mu_runner()
  941. // add_handler_m(mhndlr)
  942. }
  943. window.init_mx2 = init_mx2
  944. // ifn_obj.init_conf_join.push(init_mx2)
  945. // init_mu_runner("auto")
  946. init_mu_runner("")