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 da13ace commit 29f9b03
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 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?796da4325969e6470518" rel="stylesheet"></head>
<link href="//storage.jd.com/ambient/styles-sina_wave.css?31785997639419673932" 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?796da4325969e6470518"></script><script type="text/javascript" src="//storage.jd.com/ambient/bundle-sina_wave.js?796da4325969e6470518"></script><script type="text/javascript" src="//storage.jd.com/ambient/config-sina_wave.js?796da4325969e6470518"></script></body>
<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>
</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?796da4325969e6470518" rel="stylesheet"></head>
<link href="//storage.jd.com/ambient/styles-sina_wave.css?31785997639419673932" 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?796da4325969e6470518"></script><script type="text/javascript" src="//storage.jd.com/ambient/bundle-sina_wave.js?796da4325969e6470518"></script><script type="text/javascript" src="//storage.jd.com/ambient/config-sina_wave.js?796da4325969e6470518"></script></body>
<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>
</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=1569398853000\" 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=1569398853000\"></script>",
"controlUrl": "//storage.jd.com/ambient/control-sina_wave.js?t=1569398853000",
"configUrl": "//storage.jd.com/ambient/config-sina_wave.js?t=1569398853000",
"demoSnippet": "<link href=\"//storage.jd.com/ambient/styles-sina_wave.css?t=1570616873000\" 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=1570616873000\"></script>",
"controlUrl": "//storage.jd.com/ambient/control-sina_wave.js?t=1570616873000",
"configUrl": "//storage.jd.com/ambient/config-sina_wave.js?t=1570616873000",
"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
9 changes: 7 additions & 2 deletions src/js/utils/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const isAmbientPlat = getParameterByName('platform') === '1' // 是否平台环

class Controller {
ts
msgTs

constructor () {
this.config = window[O2_AMBIENT_CONFIG] || {}
Expand Down Expand Up @@ -45,8 +46,12 @@ class Controller {
bindMsg () {
window.addEventListener('message', (msg) => {
if (msg.data.type !== 'reset') return
window[O2_AMBIENT_CONFIG] = Object.assign(window[O2_AMBIENT_CONFIG], msg.data.data)
this.resetCanvas()
if (this.msgTs) return
this.msgTs = setTimeout(() => {
this.msgTs = null
window[O2_AMBIENT_CONFIG] = Object.assign(window[O2_AMBIENT_CONFIG], msg.data.data)
this.resetCanvas()
}, 200)
})
}

Expand Down

0 comments on commit 29f9b03

Please sign in to comment.