Temasys / AdapterJS

AdapterJS Javascript Polyfill and Tools for WebRTC - Skylink WebRTC
http://skylink.io/web
Other
429 stars 100 forks source link

TWP-328 Forward all properties of video element to the plugin object #175

Closed johache closed 8 years ago

johache commented 8 years ago

Rebased and corrected Seb's branch

How to test:

oooookk7 commented 8 years ago

muted and autoplay does not get reflected in the new element.

johache commented 8 years ago

The following fixes the issue on Safari, but breaks IE. I think think this is needed for this release, I suggest we get back to it later

    AdapterJS.forwardAttributesAndEvents = function (destElem, srcElem, prototype) {
      for (var property in srcElem) {
        if (srcElem.hasOwnProperty(property)) {
          destElem[property] = srcElem[property];
        }
      }

      properties = Object.getOwnPropertyNames( prototype );
      for(var prop in properties) {
        if (prop) {
          propName = properties[prop];

          if (typeof(propName.slice) === 'function') {
            if (propName.slice(0,2) === 'on' && srcElem[propName] !== null) {
              AdapterJS.addEvent(destElem, propName.slice(2), srcElem[propName]);
            } else {
              try {
                destElem[propName] = srcElem[propName];
              } catch(e) {
                // Some properties are readonly and will throw errors when set
                continue;
              }
            }
          }
        }
      }
      var subPrototype = Object.getPrototypeOf(prototype);
      if(!!subPrototype) {
        AdapterJS.forwardAttributesAndEvents(destElem, srcElem, subPrototype);
      }
    };