Getting the average color should be pretty simple using a raster object.
Create the raster object.
var raster = new Raster('/images/mona.jpg');
raster.fitBounds(view.bounds, true);
Get the average color
raster.getAverageColor(view.bounds);
You can set the average color to a variable and then use that color how you would like.
var newAverageColor = raster.getAverageColor(view.bounds);