Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

control over SOAP #3

Open
KensakuKOMATSU opened this issue Aug 3, 2012 · 0 comments
Open

control over SOAP #3

KensakuKOMATSU opened this issue Aug 3, 2012 · 0 comments

Comments

@KensakuKOMATSU
Copy link
Owner

after implementing whitelist-xhr, trying to control over SOAP will be necessary.

Opera's sample code is helpful.
http://people.opera.com/richt/release/specs/discovery/Overview.html

 function successCallback( services ) {

  // Listen for service push messages

    services[0].addEventListener('message', function ( msg ) {
         debug.innerHTML += "<br>" + services[0].name + " event received: ";
         debug.textContent += msg.data;
    }, false);

 // Send a control signal to mute the service audio

    var svcXhr = new XMLHttpRequest();
    svcXhr.open("POST", services[0].url); // services[0].url and its
                                          // subresources have been whitelisted for
                                          // cross-site XHR use in this current
                                          // browsing context.

    svcXhr.setRequestHeader('SOAPAction', 'urn:schemas-upnp-org:service:RenderingControl:1#SetMute');
    svcXhr.setRequestHeader('Content-Type', 'text/xml; charset="utf-8";');

    svcXhr.onreadystatechange = function ( response ) {
      if( response.readyState != 4 || response.status != 200 )
        return;
      debug.innerHTML += "<br>" + services[0].name + " response received: ";
      debug.textContent += response.responseXML;
    }

    // Service messaging to mute the provided service
    var svcMsg = '<?xml version="1.0" encoding="utf-8"?>' +
                 '<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" ' +
                   'xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">' +
                   '<s:Body>' +
                     '<u:SetMute xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1">' +
                       '<InstanceID>0</InstanceID>' +
                       '<Channel>Master</Channel>' +
                       '<DesiredMute>true</DesiredMute>' +
                     '</u:SetMute>' +
                   '</s:Body>' +
                 '</s:Envelope>';

    svcXhr.send(svcMsg);
    debug.innerHTML += "<br>" + services[0].name + " request sent: ";
    debug.textContent += svcMsg;
  }

  function errorCallback( error ) {
    debug.innerHTML += "<br>An error occurred: " + error.code;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant