Files: 261718c426b0d5a333dfa4acc00aacf92c5fe394 / message / html / render / audio.js
821 bytesRaw
1 | const nest = require('depnest') |
2 | const extend = require('xtend') |
3 | const { h } = require('mutant') |
4 | const { isAudio } = require('ssb-audio-schema') |
5 | |
6 | exports.gives = nest('message.html.render') |
7 | |
8 | exports.needs = nest({ |
9 | 'blob.sync.url': 'first', |
10 | 'message.html': { |
11 | decorate: 'reduce', |
12 | layout: 'first' |
13 | } |
14 | }) |
15 | |
16 | exports.create = function (api) { |
17 | return nest('message.html.render', audio) |
18 | |
19 | function audio (msg, opts) { |
20 | if (!isAudio(msg)) return |
21 | |
22 | const element = api.message.html.layout(msg, extend({ |
23 | content: renderContent(msg), |
24 | layout: 'default' |
25 | }, opts)) |
26 | |
27 | return api.message.html.decorate(element, { msg }) |
28 | } |
29 | |
30 | function renderContent (msg) { |
31 | const { blob } = msg.value.content |
32 | |
33 | return h('div', [ |
34 | h('audio', { src: api.blob.sync.url(blob), controls: true }) |
35 | ]) |
36 | } |
37 | } |
38 |
Built with git-ssb-web