Frame 1
var rtmp_host = r;
var http_host = h;
var session_id = s;
var connection = (new logic.PMSConnection(rtmp_host, http_host, session_id));
flash.external.ExternalInterface.addCallback("server_session_call", connection, connection.server_session_call);
connection.onServerError = function (error, code) {
flash.external.ExternalInterface.call("psession_error", error, code);
};
connection.onServerEvents = function (events) {
flash.external.ExternalInterface.call("psession_events", events);
};
connection.connect();
Symbol 1 MovieClip [__Packages.logic.PMSConnection] Frame 0
class logic.PMSConnection
{
var session_calls, session_id, rtmp_nc, http_nc, current_nc, onServerEvents, onCallResult, onCallError;
function PMSConnection (rtmp_server, http_server, _session_id) {
session_calls = [];
allowDomains();
session_id = _session_id;
rtmp_nc = new logic.RTMPConnection(rtmp_server, true);
http_nc = new logic.PMSRestXML(http_server);
var _local2 = mx.utils.Delegate.create(this, switchToHttp);
rtmp_nc.onConnectFailed = mx.utils.Delegate.create(this, switchToHttp);
rtmp_nc.onConnectClosed = mx.utils.Delegate.create(this, switchToHttp);
rtmp_nc.onConnected = mx.utils.Delegate.create(this, onRTMPConnect);
}
function connect() {
connectRTMP();
}
function connectRTMP() {
rtmp_nc.getConnection().server_error = mx.utils.Delegate.create(this, onSyncError);
rtmp_nc.getConnection().server_result = mx.utils.Delegate.create(this, onSyncResult);
rtmp_nc.connect("fun");
}
static function allowDomains() {
System.security.allowDomain("www.youtube.com");
System.security.allowDomain("s.ytimg.com");
System.security.allowDomain("youtube.com");
System.security.allowDomain("web1.sjl.youtube.com");
}
function switchToHttp() {
if (current_nc != http_nc) {
current_nc = http_nc;
sync();
}
}
function onRTMPConnect() {
current_nc = rtmp_nc;
sync();
}
function sync() {
if (session_id) {
make_call(this, onSyncResult, onSyncError, "sync", {sid:session_id, last_eid:last_eid});
} else {
make_call(this, onSyncResult, onSyncError, "init", {});
}
}
function updateLastEid(changed) {
if (current_nc == rtmp_nc) {
if (changed) {
make_call(this, onSyncResult, onSyncError, "sync", {last_eid:last_eid});
}
} else {
sync();
}
}
function onSyncResult(result) {
var _local5 = false;
if (result.events != undefined) {
if (result.last_eid != undefined) {
var _local4 = (last_eid + result.events.length) - Number(result.last_eid);
if (_local4 < 0) {
_local4 = 0;
}
last_eid = Number(result.last_eid);
_local5 = true;
onServerEvents(result.events.slice(_local4));
}
sync_error_timeout = DEFAULT_CONNECT_ERROR_TIMEOUT;
_global.setTimeout(this, "updateLastEid", 10, _local5);
} else if (result.init_sid != undefined) {
session_id = result.init_sid;
last_eid = 0;
_global.setTimeout(this, "sync", 10);
} else if (result == "server_dead") {
make_call(this, onSyncResult, onSyncError, "init", {});
}
}
function onSyncError(result, error) {
sync_error_timeout = sync_error_timeout * 2;
_global.setTimeout(this, "sync", sync_error_timeout);
}
function make_call(result_obj, result_call_back, error_call_back, call, params_obj) {
current_nc.dispatch(result_obj, result_call_back, error_call_back, call, params_obj);
}
function send_call(call, params_obj) {
make_call(this, onCallResult, onCallError, call, params_obj);
}
function server_session_call(server_call) {
send_call("sa_call", {call:server_call, sid:session_id, last_eid:last_eid});
}
var CONNECT_TIMEOUT = 100;
var DEFAULT_CONNECT_ERROR_TIMEOUT = 500;
var last_eid = 0;
var sync_error_timeout = logic.PMSConnection.prototype.DEFAULT_CONNECT_ERROR_TIMEOUT;
}
Symbol 2 MovieClip [__Packages.logic.RTMPConnection] Frame 0
class logic.RTMPConnection
{
var host_url, reconnect, connection, connect_timeout, connect_timeout_id, reconnect_timeout_id, onConnectFailed, onConnected, onConnectClosed, onCallFailed;
function RTMPConnection (url, _reconnect) {
host_url = url;
reconnect = _reconnect;
connection = new NetConnection();
connection.onStatus = mx.utils.Delegate.create(this, onStatus);
}
function connect() {
if (connect_timeout == undefined) {
connect_timeout = DEFAULT_CONNECT_TIMEOUT;
}
connection.connect.apply(connection, [host_url].concat(arguments));
connect_timeout_id = _global.setTimeout(this, "connectTimeout", connect_timeout);
}
function try_reconnect() {
if (!reconnect) {
return(undefined);
}
if (connect_timeout == undefined) {
connect_timeout = DEFAULT_CONNECT_TIMEOUT;
}
reconnect_timeout_id = _global.setTimeout(this, "connect", connect_timeout, connect_timeout);
if (connect_timeout < MAX_CONNECT_TIMEOUT) {
connect_timeout = connect_timeout * 2;
}
}
function clearTimeout() {
_global.clearTimeout(connect_timeout_id);
}
function connectTimeout() {
if (!connection.isConnected) {
close();
onConnectFailed();
}
}
function onStatus(info) {
switch (info.code) {
case "NetConnection.Connect.Success" :
connect_timeout = undefined;
clearTimeout();
onConnected();
break;
case "NetConnection.Connect.Failed" :
case "NetConnection.Connect.InvalidApp" :
case "NetConnection.Connect.Rejected" :
case "NetConnection.Connect.AppShutdown" :
clearTimeout();
try_reconnect();
onConnectFailed();
break;
case "NetConnection.Connect.Closed" :
clearTimeout();
try_reconnect();
onConnectClosed();
break;
case "NetConnection.Call.Failed" :
onCallFailed(info.description);
}
}
function isConnected() {
return(connection.isConnected);
}
function getConnection() {
return(connection);
}
function close() {
_global.clearTimeout(reconnect_timeout_id);
connection.close();
}
function dispatch(dispatcher, cb, cb_error, method, params) {
var _local2 = new Object();
_local2.onResult = mx.utils.Delegate.create(dispatcher, cb);
connection.call.apply(connection, [method, _local2].concat(params));
}
var closed = false;
var DEFAULT_CONNECT_TIMEOUT = 1000;
var MAX_CONNECT_TIMEOUT = 1800000;
}
Symbol 3 MovieClip [__Packages.mx.utils.Delegate] Frame 0
class mx.utils.Delegate extends Object
{
var func;
function Delegate (f) {
super();
func = f;
}
static function create(obj, func) {
var _local2 = function () {
var _local2 = arguments.callee.target;
var _local3 = arguments.callee.func;
return(_local3.apply(_local2, arguments));
};
_local2.target = obj;
_local2.func = func;
return(_local2);
}
function createDelegate(obj) {
return(create(obj, func));
}
}
Symbol 4 MovieClip [__Packages.logic.restXML] Frame 0
class logic.restXML
{
var request_url;
function restXML (_req_url) {
request_url = _req_url;
}
function close() {
}
function get_call_string(method) {
return(call_location + escape(method));
}
function dispatch(dispatcher, cb, cb_error, method, params) {
var xml_rsp = new XML();
var _local7 = new XML();
_local7.ignoreWhite = false;
xml_rsp.ignoreWhite = true;
if (_root.auth_code != undefined) {
_local7.addRequestHeader("Authorization", _root.auth_code);
}
var _local3 = get_call_string(method);
for (var _local5 in params) {
if (_local3.indexOf("?") == -1) {
_local3 = _local3 + "?";
} else {
_local3 = _local3 + "&";
}
_local3 = _local3 + (_local5 + "=");
_local3 = _local3 + escape(params[_local5]);
}
var _local6 = request_url + _local3;
xml_rsp.pr = this;
xml_rsp.dispatcher = dispatcher;
xml_rsp.cb = cb;
xml_rsp.req_url = _local6;
xml_rsp.cb_error = cb_error;
xml_rsp.onLoad = function (success) {
this.pr.parse_dispatch_xml(this, success);
};
_local7.sendAndLoad(_local6, xml_rsp);
}
function parse_dispatch_xml(loader, success) {
if (success) {
var _local3 = process(loader);
if (_local3.error) {
loader.cb_error.call(loader.dispatcher, _local3.data);
} else {
loader.cb.call(loader.dispatcher, _local3.data);
}
} else {
loader.cb_error.call(loader.dispatcher, undefined, true);
}
}
function process(xml_rsp) {
var _local1 = {};
var _local2 = get_sub_node("ut_response", xml_rsp);
if (_local2.attributes.status == "ok") {
_local1.data = get_dict(_local2);
} else if (_local2.attributes.status == "fail") {
var _local3 = get_dict(_local2);
_local1.data = get_dict(_local3.error);
_local1.error = true;
} else {
_local1.error = true;
}
return(_local1);
}
static function get_dict(node) {
if (!node) {
return(undefined);
}
var _local4 = new Object();
var _local2 = 0;
while (_local2 < node.childNodes.length) {
var _local1 = node.childNodes[_local2];
if (_local1.nodeType == 1) {
var _local3 = _local1.childNodes[0];
if (_local3.nodeType == 3) {
_local4[_local1.nodeName] = strip_white_space(_local3.nodeValue);
} else {
_local4[_local1.nodeName] = _local1;
}
}
_local2++;
}
return(_local4);
}
static function get_sub_array(name, node) {
if (!node) {
return(undefined);
}
var _local4 = [];
var _local1 = 0;
while (_local1 < node.childNodes.length) {
var _local2 = node.childNodes[_local1];
if (_local2.nodeName == name) {
_local4.push(_local2);
}
_local1++;
}
return(_local4);
}
static function get_sub_node(name, node) {
var _local2 = node.childNodes;
for (var _local4 in _local2) {
var _local1 = _local2[_local4];
if ((_local1.nodeType == 1) and (_local1.nodeName == name)) {
return(_local1);
}
}
}
static function get_sub_text(name, node) {
var _local1 = get_sub_node(name, node);
var _local2 = _local1.childNodes;
for (var _local3 in _local2) {
_local1 = _local2[_local3];
if (_local1.nodeType == 3) {
return(strip_white_space(_local1.nodeValue));
}
}
}
static function add_text_node(name, value, node) {
var _local2 = new XML();
var _local1 = _local2.createElement(name);
_local1.appendChild(_local2.createTextNode(value));
node.appendChild(_local1);
}
static function is_whitespace(c) {
return(((c == " ") || (c == newline)) || (c == "\t"));
}
static function strip_white_space(buffer) {
var _local4 = 0;
var _local3 = buffer.length - 1;
var _local1 = 0;
while (_local1 < buffer.length) {
if ((_local4 == _local1) && (is_whitespace(buffer.charAt(_local4)))) {
_local4++;
}
if ((_local3 == (buffer.length - (_local1 + 1))) && (is_whitespace(buffer.charAt(_local3)))) {
_local3--;
}
if ((_local4 == (_local1 + 1)) || (_local3 == (buffer.length - (_local1 + 2)))) {
} else {
break;
}
_local1++;
}
return(buffer.slice(_local4, _local3 + 1));
}
var call_location = "api2_rest?method=";
}
Symbol 5 MovieClip [__Packages.logic.PMSRestXML] Frame 0
class logic.PMSRestXML extends logic.restXML
{
function PMSRestXML (r) {
super(r);
}
function process(xml_rsp) {
var _local1 = {};
var _local2 = logic.restXML.get_sub_node("ut_response", xml_rsp);
if (_local2.attributes.status == "ok") {
_local1.data = get_object(_local2).result;
} else if (_local2.attributes.status == "fail") {
var _local3 = get_object(_local2);
_local1.data = get_object(_local3.error);
_local1.error = true;
} else {
_local1.error = true;
}
return(_local1);
}
static function get_object(node) {
if (!node) {
return(undefined);
}
var _local4 = new Object();
var _local2 = 0;
while (_local2 < node.childNodes.length) {
var _local1 = node.childNodes[_local2];
if (_local1.nodeType == 1) {
_local4[_local1.nodeName] = get_node_data(_local1);
}
_local2++;
}
return(_local4);
}
static function get_array(node) {
if (!node) {
return(undefined);
}
var _local4 = [];
var _local2 = 0;
while (_local2 < node.childNodes.length) {
var _local1 = node.childNodes[_local2];
if (_local1.nodeType == 1) {
_local4[Number(_local1.nodeName)] = get_node_data(_local1);
}
_local2++;
}
return(_local4);
}
static function get_node_data(n) {
var _local1 = n.childNodes[0];
if (_local1.nodeType == 3) {
return(logic.restXML.strip_white_space(_local1.nodeValue));
}
if (n.attributes.array) {
return(get_array(n));
}
return(get_object(n));
}
var call_location = "pms?cmd=";
}