Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Load Balancer module CORS header

  1. #1

    Default Load Balancer module CORS header

    Hello
    We are writing a player in javascript and need to hit the load balancer to get the least loaded server to play from. However we get the CORS restriction No 'Access-Control-Allow-Origin' header is present on the requested resource.
    Is there a way to add this into the loadbalancer without having to add it in the source of the module ?
    Ideally it would be great if we could enable it somewhere in a vanilla wowza install without having to write any custom module.

    Thank you
    Arpan

  2. #2
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    Hi Arpan,

    How is this all setup? You are using the XMLHTTPRequest api?

    Richard

  3. #3

    Default

    Hi Richard

    we are using a simple jquery $.get for it.
    the setup is on aws. we are using the load balancer module in wowza to get the least loaded server - we have an app that needs to do logic before it starts playing HLS, so we are doing a $.get('loadbalancer') to get the least loaded server and then create the path to the file based on that.

    But hitting the load balancer is what is throwing the access control origin issue - this is what we want to enable globally without doing a custom module or a proxy.
    Is that possible ?

                           $.ajax({
    					url: "http://wowzaip/loadbalancer",
    					dataType: "text",
    					type: "GET",
    					success: function(data) { 
    						var ip = data.split('=')[1];
    						console.log('playing from: ' + ip);
    					}
    				});
    			}

  4. #4
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    Oh, sorry, don't know how I missed this

    Looks like what you need.

    Richard

  5. #5

    Default

    Hi Richard

    I saw that one, thats for the playlist though, we dont have a problem with the m3u8 files, the initial hit to the loadbalancer before we get the m3u8 is the problem.
    So I dont really have an application to put that in since the loadbalancer module is in teh server.xml
    is there a property just like that for the loadbalancer module ?

  6. #6
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    Does the solution offered in this post help?

    Otherwise, I will have to ask around about this. It's not come up before that I can remember, I would suppose that others are querying the load balancer this way, though I would think the usual way is in an application server (php load() for example) to avoid the clients with javascript turned off.

    Richard

  7. #7

    Default

    Hi Richard
    That won't work as its related to htaccess and we are hitting wowza directly via javascript. Its basically the code below

    $.ajax({
    					url: "http://wowzaloadbalancerip/loadbalancer",
    					dataType: "text",
    					type: "GET",
    					success: function(data) { 
    						var ip = data.split('=')[1];
    						console.log('playing from: ' + ip);
    					}
    				});
    this generates a CORS error. to circumvent this we can do a proxy through another script that calls the load balancer script directly but that means we have to maintain an application stack, we are trying to avoid this just for a proxy

    Thank you
    Arpan

  8. #8
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    Hi Arpan,

    I can replicate the problem, and am seeing what can be done to fix it. I don't think there is a configurable way to add the Access-Control-Allow-Origin header, but there is a work-around. I will check further for configurable option and make a request if necessary to add that. Meanwhile, the work-around is a simple HTTPProvider (You have to import wms-plugin-loadbalancer.jar from the Load Balancer package):

    package com.wowza.wms.example.module;
    
    import com.wowza.wms.http.*;
    import com.wowza.wms.vhost.*;
    
    import com.wowza.wms.plugin.loadbalancer.HTTPLoadBalancerRedirector;
    
    public class HTTPLeastLoaded extends HTTPLoadBalancerRedirector {
    
    	public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {
    		if (!doHTTPAuthentication(vhost, req, resp))
    			return;
    
    		resp.setHeader("Access-Control-Allow-Origin", "*");
    		super.onHTTPRequest(vhost, req, resp);
    	}
    }
    Add the project .jar file to your Wowza /lib folder, then change the BaseClass of the HTTPProvider of the Load Balancer Listener

    <HTTPProvider>
            <BaseClass>com.wowza.wms.example.module.HTTPLeastLoaded</BaseClass>
            <RequestFilters>*loadbalancer</RequestFilters>
            <AuthenticationMethod>none</AuthenticationMethod>
            <Properties>
                    <Property>
                            <Name>enableServerInfoXML</Name>
                            <Value>true</Value>
                            <Type>Boolean</Type>
                    </Property>
            </Properties>
    </HTTPProvider>
    Then re-start Wowza.

    I tested with this (from here):

    <html>
    <head><title>LB test</title></head>
    <body>
    <span id='leastloaded'>least loaded server</span>
    <script>
    function sendRequest(url,callback,postData) {
    	var req = createXMLHTTPObject();
    	if (!req) return;
    	var method = (postData) ? 'POST' : 'GET';
    	req.open(method,url,true);
    	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
    	if (postData)
    		req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    	req.onreadystatechange = function () {
    		if (req.readyState != 4) return;
    		if (req.status != 200 && req.status != 304) {
    			alert('HTTP error ' + req.status);
    			return;
    		}
    		callback(req);
    	}
    	if (req.readyState == 4) return;
    	req.send(postData);
    }
    var XMLHttpFactories = [
    	function () {return new XMLHttpRequest()},
    	function () {return new ActiveXObject('Msxml2.XMLHTTP')},
    	function () {return new ActiveXObject('Msxml3.XMLHTTP')},
    	function () {return new ActiveXObject('Microsoft.XMLHTTP')}
    ];
    function createXMLHTTPObject() {
    	var xmlhttp = false;
    	for (var i=0;i<XMLHttpFactories.length;i++) {
    		try {
    			xmlhttp = XMLHttpFactories[i]();
    		}
    		catch (e) {
    			continue;
    		}
    		break;
    	}
    	return xmlhttp;
    }
    function handleRequest(req) {
    	document.getElementById('leastloaded').innerHTML = req.responseText;
    }
    sendRequest('http://[wowza-address]:1935/loadbalancer',handleRequest);
    </script>
    </body>
    </html>
    Richard
    Last edited by rrlanham; 04-22-2014 at 01:18 PM.

  9. #9

    Default

    ill try this out thanks richard

  10. #10
    Join Date
    Apr 2016
    Posts
    4

    Default

    Quote Originally Posted by rrlanham View Post
    Hi Arpan,

    I can replicate the problem, and am seeing what can be done to fix it. I don't think there is a configurable way to add the Access-Control-Allow-Origin header, but there is a work-around. I will check further for configurable option and make a request if necessary to add that. Meanwhile, the work-around is a simple HTTPProvider (You have to import wms-plugin-loadbalancer.jar from the Load Balancer package):

    package com.wowza.wms.example.module;
    
    import com.wowza.wms.http.*;
    import com.wowza.wms.vhost.*;
    
    import com.wowza.wms.plugin.loadbalancer.HTTPLoadBalancerRedirector;
    
    public class HTTPLeastLoaded extends HTTPLoadBalancerRedirector {
    
    	public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {
    		if (!doHTTPAuthentication(vhost, req, resp))
    			return;
    
    		resp.setHeader("Access-Control-Allow-Origin", "*");
    		super.onHTTPRequest(vhost, req, resp);
    	}
    }
    Add the project .jar file to your Wowza /lib folder, then change the BaseClass of the HTTPProvider of the Load Balancer Listener

    <HTTPProvider>
            <BaseClass>com.wowza.wms.example.module.HTTPLeastLoaded</BaseClass>
            <RequestFilters>*loadbalancer</RequestFilters>
            <AuthenticationMethod>none</AuthenticationMethod>
            <Properties>
                    <Property>
                            <Name>enableServerInfoXML</Name>
                            <Value>true</Value>
                            <Type>Boolean</Type>
                    </Property>
            </Properties>
    </HTTPProvider>
    Then re-start Wowza.

    I tested with this (from here):

    <html>
    <head><title>LB test</title></head>
    <body>
    <span id='leastloaded'>least loaded server</span>
    <script>
    function sendRequest(url,callback,postData) {
    	var req = createXMLHTTPObject();
    	if (!req) return;
    	var method = (postData) ? 'POST' : 'GET';
    	req.open(method,url,true);
    	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
    	if (postData)
    		req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    	req.onreadystatechange = function () {
    		if (req.readyState != 4) return;
    		if (req.status != 200 && req.status != 304) {
    			alert('HTTP error ' + req.status);
    			return;
    		}
    		callback(req);
    	}
    	if (req.readyState == 4) return;
    	req.send(postData);
    }
    var XMLHttpFactories = [
    	function () {return new XMLHttpRequest()},
    	function () {return new ActiveXObject('Msxml2.XMLHTTP')},
    	function () {return new ActiveXObject('Msxml3.XMLHTTP')},
    	function () {return new ActiveXObject('Microsoft.XMLHTTP')}
    ];
    function createXMLHTTPObject() {
    	var xmlhttp = false;
    	for (var i=0;i<XMLHttpFactories.length;i++) {
    		try {
    			xmlhttp = XMLHttpFactories[i]();
    		}
    		catch (e) {
    			continue;
    		}
    		break;
    	}
    	return xmlhttp;
    }
    function handleRequest(req) {
    	document.getElementById('leastloaded').innerHTML = req.responseText;
    }
    sendRequest('http://[wowza-address]:1935/loadbalancer',handleRequest);
    </script>
    </body>
    </html>
    Richard
    I am running into this same issue, and it appears that this solution no longer works with the updated WowzaLoadBalancer 4.0 Module. Is there any way to achieve this same result with the new library?

Page 1 of 2 12 LastLast

Similar Threads

  1. How load balancer works? Unbalanced load situation
    By gavram in forum Wowza Streaming Server Java API
    Replies: 2
    Last Post: 06-25-2014, 06:49 AM
  2. WowzaStreamingEngine needs CORS header sent on playlist.m3u8
    By chillininvt in forum Live Streaming and Encoders
    Replies: 5
    Last Post: 04-16-2014, 08:43 AM
  3. Using ec2 load balancer vs wowza load balancer and the best instances for me.
    By cham24 in forum Wowza Media Server 3 for Amazon EC2 Discussion
    Replies: 4
    Last Post: 11-04-2013, 02:18 PM
  4. Get Addresses from Load Balancer Module
    By odrilon in forum Server-side Modules and Code Samples Discussion
    Replies: 2
    Last Post: 03-26-2012, 08:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •