wiki-plugin-mech 0.1.22 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/mech.js +56 -3
- package/package.json +1 -1
package/client/mech.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
(function() {
|
|
3
|
-
|
|
3
|
+
"use strict"
|
|
4
4
|
const uniq = (value, index, self) => self.indexOf(value) === index
|
|
5
5
|
|
|
6
6
|
function expand(text) {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
const unique = Math.floor(Math.random()*1000000)
|
|
38
38
|
const block = (more,path) => {
|
|
39
39
|
const html = []
|
|
40
|
-
for (part of more) {
|
|
40
|
+
for (const part of more) {
|
|
41
41
|
const key = `${unique}.${path.join('.')}`
|
|
42
42
|
part.key = key
|
|
43
43
|
if('command' in part)
|
|
@@ -615,6 +615,57 @@
|
|
|
615
615
|
state.items = items
|
|
616
616
|
}
|
|
617
617
|
|
|
618
|
+
function listen_emit({elem,command,args,state}) {
|
|
619
|
+
if (args.length < 1) return trouble(elem,`LISTEN expects argument, an action.`)
|
|
620
|
+
const topic = args[0]
|
|
621
|
+
let recent = Date.now()
|
|
622
|
+
let count = 0
|
|
623
|
+
const handler=listen
|
|
624
|
+
handler.action = 'publishSourceData'
|
|
625
|
+
handler.id = elem.id
|
|
626
|
+
window.addEventListener("message", listen)
|
|
627
|
+
$(".main").on('thumb', (evt, thumb) => console.log('jquery',{evt, thumb}))
|
|
628
|
+
elem.innerHTML = command + ` ⇒ ready`
|
|
629
|
+
|
|
630
|
+
// window.listeners = (action=null) => {
|
|
631
|
+
// return getEventListeners(window).message
|
|
632
|
+
// .map(t => t.listener)
|
|
633
|
+
// .filter(f => f.name == 'listen')
|
|
634
|
+
// .map(f => ({action:f.action,elem:document.getElementById(f.id),count:f.count}))
|
|
635
|
+
// }
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
function listen(event) {
|
|
640
|
+
console.log({event})
|
|
641
|
+
const {data} = event
|
|
642
|
+
if (data.action == 'publishSourceData' && (data.name == topic || data.topic == topic)) {
|
|
643
|
+
count++
|
|
644
|
+
handler.count = count
|
|
645
|
+
if(state.debug) console.log({count,data})
|
|
646
|
+
if(count<=100){
|
|
647
|
+
const now = Date.now()
|
|
648
|
+
const elapsed = now-recent
|
|
649
|
+
recent = now
|
|
650
|
+
elem.innerHTML = command + ` ⇒ ${count} events, ${elapsed} ms`
|
|
651
|
+
} else {
|
|
652
|
+
window.removeEventListener("message", listen)
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function message_emit({elem,command,args,state}) {
|
|
659
|
+
if (args.length < 1) return trouble(elem,`MESSAGE expects argument, an action.`)
|
|
660
|
+
const topic = args[0]
|
|
661
|
+
const message = {
|
|
662
|
+
action: "publishSourceData",
|
|
663
|
+
topic,
|
|
664
|
+
name: topic,}
|
|
665
|
+
window.postMessage(message,"*")
|
|
666
|
+
elem.innerHTML = command + ` ⇒ sent`
|
|
667
|
+
}
|
|
668
|
+
|
|
618
669
|
|
|
619
670
|
// C A T A L O G
|
|
620
671
|
|
|
@@ -641,7 +692,9 @@
|
|
|
641
692
|
GET: {emit:get_emit},
|
|
642
693
|
DELTA: {emit:delta_emit},
|
|
643
694
|
ROSTER: {emit:roster_emit},
|
|
644
|
-
LINEUP: {emit:lineup_emit}
|
|
695
|
+
LINEUP: {emit:lineup_emit},
|
|
696
|
+
LISTEN: {emit:listen_emit},
|
|
697
|
+
MESSAGE: {emit:message_emit}
|
|
645
698
|
}
|
|
646
699
|
|
|
647
700
|
|