Skip to content

Commit

Permalink
feat: 增加 postmessage 截流
Browse files Browse the repository at this point in the history
  • Loading branch information
lyxuncle committed Oct 9, 2019
1 parent ea3f1b4 commit 16a26fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
4 changes: 2 additions & 2 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<meta name="format-detection" content="telephone=no">
<title>demo</title>

<link href="//storage.jd.com/ambient/styles-sina_wave.css?31785997639419673932" rel="stylesheet"></head>
<link href="//storage.jd.com/ambient/styles-sina_wave.css?1819f62b860864bfcae0" rel="stylesheet"></head>
<body>
<!-- S 主体内容 -->
<div class="o2team_ambient_main">
<canvas id="sinewaves"></canvas>
</div>
<!-- E 主体内容 -->

<script type="text/javascript" src="//storage.jd.com/ambient/control-sina_wave.js?31785997639419673932"></script><script type="text/javascript" src="//storage.jd.com/ambient/bundle-sina_wave.js?31785997639419673932"></script><script type="text/javascript" src="//storage.jd.com/ambient/config-sina_wave.js?31785997639419673932"></script></body>
<script type="text/javascript" src="//storage.jd.com/ambient/control-sina_wave.js?1819f62b860864bfcae0"></script><script type="text/javascript" src="//storage.jd.com/ambient/bundle-sina_wave.js?1819f62b860864bfcae0"></script><script type="text/javascript" src="//storage.jd.com/ambient/config-sina_wave.js?1819f62b860864bfcae0"></script></body>
</html>
4 changes: 2 additions & 2 deletions dist/index_demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<script type="text/javascript" src="//storage.jd.com/ambient-global/ambient-autoStop-head.js"></script>

<link href="//storage.jd.com/ambient/styles-sina_wave.css?31785997639419673932" rel="stylesheet"></head>
<link href="//storage.jd.com/ambient/styles-sina_wave.css?1819f62b860864bfcae0" rel="stylesheet"></head>
<body>
<!-- S 主体内容 -->
<div class="o2team_ambient_main">
Expand All @@ -18,5 +18,5 @@

<script type="text/javascript" src="//storage.jd.com/ambient-global/ambient-autoStop-body.js"></script>

<script type="text/javascript" src="//storage.jd.com/ambient/control-sina_wave.js?31785997639419673932"></script><script type="text/javascript" src="//storage.jd.com/ambient/bundle-sina_wave.js?31785997639419673932"></script><script type="text/javascript" src="//storage.jd.com/ambient/config-sina_wave.js?31785997639419673932"></script></body>
<script type="text/javascript" src="//storage.jd.com/ambient/control-sina_wave.js?1819f62b860864bfcae0"></script><script type="text/javascript" src="//storage.jd.com/ambient/bundle-sina_wave.js?1819f62b860864bfcae0"></script><script type="text/javascript" src="//storage.jd.com/ambient/config-sina_wave.js?1819f62b860864bfcae0"></script></body>
</html>
6 changes: 3 additions & 3 deletions info.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"title": "sina_wave",
"ambName": "波浪",
"github": "https://github.com/o2team-ambient/sina_wave",
"demoSnippet": "<link href=\"//storage.jd.com/ambient/styles-sina_wave.css?t=1570617458000\" rel=\"stylesheet\"></link><!-- S 主体内容 -->\n <div class=\"o2team_ambient_main\">\n <canvas id=\"sinewaves\"></canvas>\n </div>\n <!-- E 主体内容 --><script src=\"//storage.jd.com/ambient/bundle-sina_wave.js?t=1570617458000\"></script>",
"controlUrl": "//storage.jd.com/ambient/control-sina_wave.js?t=1570617458000",
"configUrl": "//storage.jd.com/ambient/config-sina_wave.js?t=1570617458000",
"demoSnippet": "<link href=\"//storage.jd.com/ambient/styles-sina_wave.css?t=1570617669000\" rel=\"stylesheet\"></link><!-- S 主体内容 -->\n <div class=\"o2team_ambient_main\">\n <canvas id=\"sinewaves\"></canvas>\n </div>\n <!-- E 主体内容 --><script src=\"//storage.jd.com/ambient/bundle-sina_wave.js?t=1570617669000\"></script>",
"controlUrl": "//storage.jd.com/ambient/control-sina_wave.js?t=1570617669000",
"configUrl": "//storage.jd.com/ambient/config-sina_wave.js?t=1570617669000",
"placeholderImg": "//storage.jd.com/ambient/sina_wave_placeholder.png?t=1554260508000",
"gifImg": "//storage.jd.com/ambient/sina_wave_motion.gif?t=1553781489000",
"spriteImg": "//storage.jd.com/ambient/sina_wave_sprite.png?t=1554260508000"
Expand Down
27 changes: 16 additions & 11 deletions src/js/utils/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const isAmbientPlat = getParameterByName('platform') === '1' // 是否平台环
class Controller {
ts
msgTs
transMsgTs

constructor () {
this.config = window[O2_AMBIENT_CONFIG] || {}
Expand Down Expand Up @@ -74,17 +75,21 @@ class Controller {

// 传送数据
transMsg (dom) {
let transWin = dom.contentWindow
window[O2_AMBIENT_CONFIG].waves = window[O2_AMBIENT_CONFIG].waves.map(item => {
return {
...item,
random: null
}
})
transWin.postMessage({
type: 'reset',
data: window[O2_AMBIENT_CONFIG]
}, `${window.location.protocol}${dom.getAttribute('src')}`)
if (this.transMsgTs) return
this.transMsgTs = setTimeout(() => {
this.transMsgTs = null
let transWin = dom.contentWindow
window[O2_AMBIENT_CONFIG].waves = window[O2_AMBIENT_CONFIG].waves.map(item => {
return {
...item,
random: null
}
})
transWin.postMessage({
type: 'reset',
data: window[O2_AMBIENT_CONFIG]
}, `${window.location.protocol}${dom.getAttribute('src')}`)
}, 200)
}

// iframe dom
Expand Down

0 comments on commit 16a26fa

Please sign in to comment.