StreamHub proxy

10 views
Skip to first unread message

Mike Rojas

unread,
Jan 6, 2010, 11:05:12 AM1/6/10
to StreamHub Comet Server Community
We have a requirement to route StreamHub requests through a proxy to a
master site to get around the browser cross-domain restriction. We
want our end-users to use a standard "widget" (some HTML and
Javascript code) on their local web sites but receive news feeds from
a master site.

Has anyone done this before? We are looking for an example page
(preferably in PHP) that demonstrates how to do this.

I see in the documentation that someone has done it:

// Example - Using a cross-domain proxy
var hub = new StreamHub();
hub.connect("http://www.server.com/proxy.php?request=");

So apparently I am missing the proxy.php code.

In the meanwhile, I will try to make one and post it when I am done.

Thanks!

StreamHub Team

unread,
Jan 6, 2010, 2:30:44 PM1/6/10
to StreamHub Comet Server Community
Hi Mike,

We have an old proxy.php script below that used curl. The API has
changed slightly, so you may need to adapt it, but here it is:

<?php
header("Expires: Thu, 1 Jan 1970 00:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");

$ch = curl_init();
$url = $_GET["url"];
$domain = $_GET["domain"];
$userAgent = $_SERVER['HTTP_USER_AGENT'];

if (isset($_GET["subscribe"])) {
$subscribe = $_GET["subscribe"];
curl_setopt ($ch, CURLOPT_URL, "http://otherhost.com/" . $url .
"&domain=" . $domain . "&subscribe=" . $subscribe);
} elseif (isset($_GET["domain"])) {
curl_setopt ($ch, CURLOPT_URL, "http://otherhost.com/" . $url .
"&domain=" . $domain);
} else {
curl_setopt ($ch, CURLOPT_URL, "http://otherhost.com/" . $url);
}

curl_setopt ($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt ($ch, CURLOPT_HEADER, 0);

curl_exec ($ch);

curl_close ($ch);
?>

It was used like so:
hub.connect("http://www.server.com/proxy.php?url=");


Hope this helps,

Please post if you come up with something better.


Thanks.

Mike Rojas

unread,
Jan 7, 2010, 3:11:02 PM1/7/10
to StreamHub Comet Server Community
Thanks for the reply.

I modified your proxy file to reflect the new StreamHub API but I am
still having trouble getting it to work. It seems to die right after
the first hidden iframe request goes out (and comes back) - it is
executing its code to set the window.x = window.parent.x functions on
the returned page - but nothing after that. I will continue to debug
it.

Here is what the file looks like now:

<?php
header("Expires: Thu, 1 Jan 1970 00:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");

$ch = curl_init();

$url = $_GET["url"];
$domain = $_GET["domain"];

$r = $_GET["r"];
$topic = $_GET["topic"];

$userAgent = $_SERVER['HTTP_USER_AGENT'];

if (strncmp($url,"subscribe/",10) == 0)
{
curl_setopt ($ch, CURLOPT_URL, "http://www.imvox.com:7878/" .
$url . "&domain=" . $domain . "&r=" . $r . "&topic=" . $topic);
}
else
{
curl_setopt ($ch, CURLOPT_URL, "http://www.imvox.com:7878/" .
$url . "&domain=" . $domain . "&r=" . $r );
}

curl_setopt ($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt ($ch, CURLOPT_HEADER, 0);

curl_exec ($ch);

curl_close ($ch);
?>


In the meanwhile, an elegant solution to this cross domain ajax
problem is to just use an <iframe> tag to allow the StreamHub enabled
page to function without messing with proxies and other such things.

We put html code like this in the end user's page:
<iframe name="imvox_widget" src="http://www.imvox.com/imvox_status.php?
server=TestServer&css=160_light" frameborder="0" style="height:570px;
width:160px; "></iframe>

This allows any web page to embed our widget and see their real-time
voice chat server updates. The user just needs to pass in their own
server name.

You can check it out live at:
http://whatisnoise.com/

or go to the page directly:
http://www.imvox.com/imvox_status.php?server=TestServer&css=160_light

Thanks again!

Reply all
Reply to author
Forward
0 new messages