fix: gifs and videos on the message feed now pause when offscreen, conserving cpu usage

This commit is contained in:
Paul Frazee
2015-09-30 12:39:39 -05:00
parent dfddc05330
commit f929c75311
3 changed files with 21 additions and 14 deletions

View File

@@ -3,10 +3,12 @@ var h = require('hyperscript')
var mlib = require('ssb-msgs')
var pull = require('pull-stream')
var multicb = require('multicb')
var pauser = require('pause-offscreen')
var app = require('../app')
var com = require('../com')
var u = require('../util')
module.exports = function (opts) {
opts = opts || {}
var botcursor
@@ -36,6 +38,10 @@ module.exports = function (opts) {
fetchBottom(function (n) {
if (opts.onempty && n === 0)
opts.onempty(feedEl)
// add offscreen pausing
var unlistenPauser = pauser(containerEl)
ui.onTeardown(unlistenPauser)
})
function fetchBottom (cb) {

View File

@@ -72,7 +72,7 @@ renderer.image = function (href, title, text) {
href = href.replace(/^&/, '&')
if (ssbref.isLink(href)) {
if ((''+text).indexOf('.webm') >= 0) {
var out = '<video autoplay=1 loop=1 muted=1 src="http://localhost:7777/' + href + '?fallback=video" alt="' + text + '"'
var out = '<video loop=1 muted=1 src="http://localhost:7777/' + href + '?fallback=video" alt="' + text + '"'
if (title) {
out += ' title="' + title + '"'
}