123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665 |
-
- var mhndlr_opt_null = {
- from: undefined,
- handler: "onAll",
- id: null,
- name: null,
- // "http://jitsi.org/jitmeet"
- ns: null,
- options: {matchBareFromJid: false, ignoreNamespaceFragment: false},
- type: null,
- user: true,
- cstr:"test"
- };
- var mhndlr_opt_x = {
- cstr:"cmx",
- ns:"corner_mx",
- handler:mhndlr,
-
- }
- var dlog = nop
- // var dlog = nop
- // dlog = clog
- function attr_info(n){
- var k,v
- var ret ={}
- for ([k,v] of Object.entries(n.attributes)){
- ret[v.name]= v.value
- }
- return ret
-
-
- }
-
-
-
-
- function remove_handlers_cmx(_stropheConn) {
- // var state = window.glob_vhook.fns.getState()
- // var conference_0 = state["features/base/conference"]
- // var conference = conference_0.conference
- var k,v
- for (v of _stropheConn.handlers){
- if (v.cstr == "cmx"){
- _stropheConn.removeHandlers.push(v)
- }
-
- }
-
- // var _stropheConn = conference.xmpp.connection._stropheConn
- }
- function add_handler_m(handler) {
- // clog("add_handler_m...")
- // var state = window.glob_vhook.fns.getState()
- var state = APP.store.getState()
- var conference_0 = state["features/base/conference"]
- var conference = conference_0.conference
-
- var _stropheConn = conference.xmpp.connection._stropheConn
-
- var phx = _stropheConn.handlers[0].__proto__;
-
- var hxa=Object.create(phx)
- Object.assign(hxa,mhndlr_opt_null,handler)
- remove_handlers_cmx(_stropheConn)
- _stropheConn.addHandlers.push(hxa)
- return hxa
- }
-
- function mhndlr_rld_dflt(a0,a1,a2,a3,a4){
- clog("mhndlr... dflt")
- return true
- }
-
- function mhndlr(a0,a1,a2,a3,a4){
- setTimeout(window.mhndlr_rld.bind({a:"fake_that"},this,a0,a1,a2,a3,a4),1)
- return true
- }
-
-
- function init_mxu(){
- add_handler_m(mhndlr_opt_x)
- }
-
-
- function mhndlr_rld(that,m){
- try {
- var n = m.querySelector(`code`)
- if (!n){return}
- var parsed = JSON.parse(n.innerHTML)
- var ai = attr_info(m)
-
- var id = ai.from.split("/").pop()
- var o = parsed.payload
-
- if (window.mhndlr_rld_dbg){
- mhndlr_rld_dbg({m,that,n,parsed,ai,o,arguments})
- }
-
- // clog("mhndlr_rld:",parsed.type)
-
-
-
-
-
- switch (parsed.type){
- case "set_msg":
- pf._set_recv(o.path,o.key,o.val,id)
- glob_u.fns.msto_evh ? glob_u.fns.msto_evh(o,parsed,ai,id) : 0
- // glob_u.fns.msto_evh()
- break;
- case "event":
- dlog("~event~",parsed)
- if (window.dispatch_events){
- dispatch_events({parsed,ai,m,that})
- }
- break;
- case "msg_test":
- dlog("msg_test",parsed)
- break;
- case "db_sync_request":
- // tmsgx3({type:"db_sync_response",payload:pf.root})
- tmsgx3({type:"db_sync_response",payload:pf.root},{to:ai.from})
-
- // dlog("db_sync_request",parsed)
- clog("db_sync_request",parsed)
- break;
- case "db_sync_response":
- if (id == glob_u.data.local_id){
- dlog( "db_sync_response ...")
- break
-
- }
- if (glob_u.prom.init_db_resolve){
- glob_u.prom.init_db_resolve({aaa:"dsr",pl:parsed.payload})
-
- }
-
- clog("db_sync_response",ai.from == glob_u.data.local_id,ai.from,parsed)
- break;
-
- }
-
-
-
-
- } catch (err) {
- clog("mhndlr err:",err)
- }
- }
-
-
-
-
- function tmsgx3(data,opt_arg={},attrs={}){
- // return
- // clog("tmsgx3",{data,opt_arg,attrs})
- var dflt_opt = {
- tag:"code",
- // type:"chat",
- to:window.APP.conference._room.room.roomjid,
- }
- var opt = Object.assign({},dflt_opt,opt_arg)
- // clog("T:",data,opt,opt.type)
- if (!opt.type){
- // clog("NO TYPE")
- opt.to == dflt_opt.to ? opt.type = "groupchat" : opt.type = "chat"
- }
- // clog("T:",data,opt,opt.type)
-
- var ns = {xmlns:"corner_mx"}
- var msg = $build("message",{ to: opt.to,
- type: opt.type,
- // from: "nnnx@conference.jfidev.com/3db7bf15",
- // xtra: "nnnx@conference.jfidev.com/3db7bf15",
- });
- var payload
- if (typeof(data) == "string"){
- payload=data
-
- } else {
- payload=JSON.stringify(data)
-
- }
-
- Object.assign({},ns,attrs)
-
- msg.c(opt.tag, payload,Object.assign({},ns,attrs)).up();
- // console.log("zzzz")
- APP.conference._room.room.connection.send(msg)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- isProxy = Symbol("isProxy")
-
-
- tlu = {
- object:"",
- string:true,
- number:true,
- undefined:true,
- boolean:true,
- }
-
-
- function match(mx,m,o){
- var k,v,k2,v2
- var r = 0
-
- for ([k,v] of Object.entries(m || {})){
- v2 = o[k]
-
- if (typeof(v) == "string" && typeof(v2) == "string") {
- r += !(v==v2)
- } else if (Array.isArray(v) && Array.isArray(v2)){
- r += !(isSubset_arr(v,v2))
- } else if (Array.isArray(v) && typeof(v2) == "string"){
- // r += !(isSubset_arr(v2,v))
- r += !v.includes(v2)
-
- } else if (Array.isArray(v2) && typeof(v) == "string"){
- r += !(v2.includes(v))
- }
- if (r){
- return !r
- }
- }
- return !r
- }
-
-
- function isSubset(subset,superset){
- for (var elem of subset) {
- if (!superset.includes(elem)) {
- return false;
- }
- }
- return true;
- }
-
- function isSubset_arr(subset,superset){
- for (var elem of subset) {
- if (Array.isArray(elem)){
-
- if (!new Set(elem).intersection(superset).size){
- return false
- }
- } else if (!superset.includes(elem)) {
- return false;
- }
- }
- return true;
- }
-
-
-
-
-
-
-
-
- function type_info(o){
- try {
-
- var t
- var flags = {
- leaf:false,
- deep_not_prx:false,
- prx:false,
- isObj:false,
- isArr:false,
- els:false,
- }
- t = typeof(o)
- flags.t=t
- // window?.glob_mx?.flags?.type_info_dbg ? clog("type_info") : 0
- if (!(o === null)){
- flags.isArr = Array.isArray(o)
- flags.isObj = Object.prototype == o.__proto__
- }
-
- if (tlu[t] === true || o === null){
- flags.leaf = true
- } else if (t == "object" && o.__prx){
- flags.prx = true
- } else if (t == "object" && (flags.isArr || flags.isObj)){
- flags.prx = false
- flags.deep_not_prx = true
- } else {
- clog("ELSE")
- flags.els = true
- }
-
- return flags
-
- // !window?.glob_mx?.flags?.type_info_dbg ? clog("type_info") : 0
- } catch (err){
- clog("type_info err:",err,{flags,o})
- }
- // clog(t,flags)
- }
-
-
-
-
-
- function deep_prop_v0(o,p){
- try {
- var arr = jc(p)
- var ret = o
-
- while (arr.length){
- // clog("deep_prop",arr,ret)
- ret = ret[arr.shift()]
- }
- // clog("deep_prop ret",ret)
- return ret
- } catch(err){console.error("DEEP_PROP ERR:",err)}
- }
-
-
-
-
-
-
-
-
-
-
-
-
- delete Proxy_Factory
- {
-
- // TODO:JFI remove fn
- function init_participant(path,key,val){
- //
- // is this a real function
- // console.log("init_db_local _set_pub?",path)
- var path_join = path.join(".") + "." + key
- clog("_set_pub_log",path_join,{path,key,val})
- // console.trace("_set_pub_trv",path_join)
- if (path == "participants" && path.length == 1){
- // console.trace("init_db_local _set_pub")
- // console.log("init_db_local _set_pub")
-
- }
- }
-
- class Proxy_Factory {
- constructor(o,n="dflt"){
- this.db = o
- this.n = n
- this.hidden_props = ["add_proxy","_set","walker","walker_start","prxy","_sett","_sett2"]
- this._pub_cb =[]
- this.__prx = true
- this.SymPrx = Symbol("SymPrx")
- // clog("pfx",{o,n,that:this})
- }
- init(o){
- this.root = o
- }
- sync(o){
- this.root = jc(o.root)
- o._pub_cb.push(this._set_recv.bind(this))
- }
- get prxy(){
- return this
- }
-
- _set(o,k,v,prx,a0){
- this.obj[k]=prx
- }
-
- _sett(o,k,v,prx,a0){
- dlog("_SETT",this,arguments)
- }
- _sett2(o,k,v,prx,a0){
- dlog("_SETT2",this,arguments)
- }
-
- set_pub(obj, prop, val,receiver){
- this._set_pub(obj.__path_arr, prop, jx(val))
-
- }
- _set_pub(path,key,val){
- var k,v
- // init_participant(path,key,val)
- var arg = {
- "type":"set_msg",
- "payload":{path,key,val},}
-
- tmsgx3(arg,
- // {},
- )
- for (v of this._pub_cb){
- v(path,key,val)
-
- }
- }
-
- _set_recv(path,prop,val,id){
- // return
- /*
- if (id == glob_u.data.local_id){
- clog("_set_recv:local_id",{path,prop,val,id})
- return
- }
- */
- var p = path
- var nprop = deep_prop_v0(this.root,p)
- var dpth = nprop.__dpth
- if (tlu[typeof(val)]){
- nprop._set(nprop,prop,val,val)
- } else {
- nprop._set(nprop,prop,val,new Proxy(val,this))
- nprop[prop].add_proxy(nprop,prop,val,dpth+1)
- }
- // var tf = {}
- // this.walker(nprop[prop],tf,dpth+2)
- this.walker(nprop[prop],{},dpth+2)
- }
-
- set(obj, prop, val,receiver){
- // dlog("prx_db set ",this,obj, prop, val,receiver,val.__prx)
- // clog("prx_db set ",{that:this,obj, prop, val,receiver},val.__prx)
- // clog("prx_db set ",obj.__path_arr)
- if (obj[prop] === val){
- return Reflect.set(...arguments)
- }
-
- this.set_pub(obj, prop, val,receiver)
- this.event_proc("set")
-
- if ("__prx" == prop){
- this.__prx=val
- return this.__prx
- }
-
- if (typeof(val) === "object" && val != null && !(val.__prx)){
- var ret = Reflect.set(...arguments)
- this.set_obj(obj, prop, val,receiver)
- return ret
- }
-
- return Reflect.set(...arguments)
- }
- get(obj, prop,receiver){
- // dlog("prx_db get ...",prop==isProxy,this,obj, prop,receiver)
- if (this.hidden_props.includes(prop)){
- switch (prop){
- case "add_proxy":
- return this.add_proxy.bind(this)
- break;
- case "prxy":
- return this
- case "_set":
- return this._set.bind({that:this,obj, prop,receiver})
- case "_sett":
- return this._sett.bind({that:this,obj, prop,receiver})
- case "_sett2":
- return this._sett2.bind({that:this})
- case "walker_start":
- return this.walker_start
- case "walker":
- return this.walker
- break;
- }
- }
-
- if (isProxy == prop){ return true }
- if ("__prx" == prop){ return this.__prx }
-
- return Reflect.get(...arguments)
- }
- add_proxy(o,k,v,dpth){
- // clog("~add_proxy~",o,k,v,dpth)
- // clog("~add_proxy~",o.__prx,o,k,v,dpth,xpath)
- var xpath = o.__path
- var apath = o.__path_arr
- this.event_proc("add_proxy")
- if (!apath){
- apath=[]
- }
-
- if (!xpath){
- xpath="ROOT!"
- }
-
- Object.defineProperty(v,"__path_arr",Object.assign({value:apath.concat(k),},this.baseProp))
- Object.defineProperty(v,"__path",Object.assign({value:xpath+":"+k,},this.baseProp))
- Object.defineProperty(v,"__dpth",Object.assign({value:dpth,},this.baseProp))
- // Object.defineProperty(v,"__dbg",Object.assign({value:{},},this.baseProp))
-
- }
- set_obj(obj, prop, val,receiver){
- var dpth = obj.__dpth
- var tf = {}
- this.walker(receiver,tf,dpth)
- }
-
- walker(o,tfo,dpth=0){
- if (dpth > 7){
- console.error("MAX DEPTH")
- return
- }
- var k,v
- var tf
- for ([k,v] of Object.entries(o)){
- tf = type_info(v)
- if (tf.deep_not_prx){
- o._set(o,k,v,new Proxy(v,this.prxy))
- o[k].add_proxy(o,k,v,dpth)
- this.walker(o[k],tf,dpth+1)
- }
- }
- }
- walker_start(o,dpth){
- var tf = type_info(o)
- o.add_proxy({},[],o,-1)
- this.walker(o,tf,0)
- }
- event_proc(e){}
- }
- window.Proxy_Factory = Proxy_Factory
-
- Proxy_Factory.prototype.baseProp={
- writable: true,
- // enumerable: true,
- enumerable: false,
- configurable: true,
- }
- }
-
-
-
-
- function arr_match(m,o){
- var k,v
- var r = 0
- for ([k,v] of Object.entries(m || {})){
- if (o[k] != v.valueOf()){
- r += 1
- return !r
- }
-
- // for ([k,v] in m){
- // case
- // dlog(k,v)
- }
- return !r
- }
-
- permissions_def = {
- participants:{
- m:["participants"],
- fn(set_scope,match){
-
-
- // clog("FN....",match.fp,match.fp[1] == window.glob_mx.local_id)
- // if (match.fp[1] != window.glob_u.data.local_id)
- if (match.fp[1] != window.glob_u.data.local_id && 0)
- throw "permission err"
- return
- },
- }
- }
- //
- // msto.my_data.prxy.__proto__.__proto__.set.call(msto.my_data.prxy,msto.participants,"abc2",{})
- permissions_def__set = {
- participants:{
- m:["participants"],
- fn(set_scope,match){
-
-
- dlog("FN....",match.fp,match.fp[1] == window.glob_u.data.local_id)
- if (match.fp[1] != window.glob_u.data.local_id)
- // throw "permission err"
- return
- },
- }
- }
-
-
-
-
- {
- class Proxy_Permissions extends Proxy_Factory {
- constructor(a,a1){
- super(...arguments)
- }
- set(obj, prop, val,receiver){
- // clog("PRX_PERM",obj.__path_arr,prop)
- // clog("PRX_PERM",{obj, prop, val,receiver})
- var k,v
- var r
- var matched
- var fp = obj.__path_arr.concat(prop)
- for ([k,v] of Object.entries(permissions_def)){
- matched = arr_match(v.m,fp)
- if (matched){
- r = v.fn({that:this,obj, prop, val,receiver},{fp,k,v}) || {}
- }
- // if (r.return)
- }
- // case
- // if (obj.__path_arr && obj.__path_arr.length){}
- return super.set(obj, prop, val,receiver)
- }
- _set(){
- // clog("Proxy_Permissions _set")
- super._set(...arguments)
- }
- }
- window.Proxy_Permissions = Proxy_Permissions
- }
-
-
-
-
-
-
-
|