/** * @fileoverview AIM Javascript API * @author Steven G. Chipman - AOL - http://developer.aim.com * @filename aimapi-core.js * @copyright Copyright (c) 2009 AOL LLC. All rights reserved * @version 04.24.2009 */ /** * These object prototypes are required by the API. */ String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); }; String.prototype.toBoolean = function() {if(this == "false") return false; return true;}; Array.prototype.indexOf = function(val) { for(i=0;i-1 || navigator.userAgent.indexOf("Camino") >-1 || window.opera) && !document.all)?2000:60000, TRANSACTION_TIMEOUT:5000, MOZILLA: { "a":"b"}.__count__, MSIE:document.all && !window.opera, MSIE6: (window.external && typeof window.XMLHttpRequest == "undefined"), OPERA:window.opera } /** * AIM.core contains all of the methods that are REQUIRED for the API to funtion. */ AIM.core = { AIMData:[], authAttempts:0, requestInterval:null, subscriptions: null, activeSession: false, pendingTransaction: null, connectionTimer: null, connectionAttempts:0, maxConnectionAttempts:3, /** * Creates a DIV element that contains an IFRAME element for authentication/consent * @param { String } url The url that will be the src of the iframe */ createAuthWindow: function(url) { if(AIM.params.authenticationMode == 0) { if(document.getElementById("AIMFrameContainer_AIMwindow")) { var oIframe = document.getElementById("AIMReqFrame"); } else { var win = AIM.ui.createWindowFrame("AIMFrameContainer","AIMFrameContainer","Web AIM"); oIframe = document.createElement("iframe"); oIframe.setAttribute("id","AIMReqFrame"); oIframe.setAttribute("frameborder","0"); win.appendChild(oIframe); win.style.left = (document.getElementsByTagName("body")[0].offsetWidth - 510)/2 + "px"; document.getElementsByTagName("body")[0].appendChild(win); } oIframe.src = "about:blank"; oIframe.src = url + "&nocache=" + Date.parse(new Date()); document.getElementById("AIMFrameContainer_AIMwindow").style.display = "block"; window.scrollTo(0,0); AIM.core.debug("createAuthWindow: " + url + "&nocache=" + Date.parse(new Date())); AIM.core.watchAuthRequest(); } else { var x = (screen.width - AIM.params.authWindowDimensions.w)/2 var y = (screen.height - AIM.params.authWindowDimensions.h)/2 AIM.core.consentWindow = window.open(url + "&succUrl=" + AIM.params.succUrl + "&f=qs", "AuthWindow", "resizable=yes,width=" + AIM.params.authWindowDimensions.w + ",height=" + AIM.params.authWindowDimensions.h + ",top=" + y + ",left=" + x + ",directories=no,titlebar=no,status=no,menubar=no,toolbar=no,location=yes"); } }, /** * Called via setTimeout to check the status of the fragment identifier set by the authentication service * when authentication/consent is complete. * 1. AUTHCANCEL - user canceled login * 2. AUTHDONE - user successfully logged in * 3. INVALIDCALLBACK - invalid jsonp callback * 4. CONSENTINVALIDTOKEN - getconsent called with invalid enc token * 5. CONSENTDONE - consent done * 6. CONSENTCANCEL - user denied consent * */ watchAuthRequest: function() { if(AIM.params.authenticationMode == 1) { if(!AIM.core.consentWindow.closed) { clearTimeout(oTimeout); var oTimeout = setTimeout(AIM.core.watchAuthRequest,500); } return; } var oLoc = location.href; if(oLoc.indexOf("#AUTHDONE") > -1 || oLoc.indexOf("#CONSENTDONE") > -1 || oLoc.indexOf("#CONSENTCANCEL") > -1 || oLoc.indexOf("#AUTHCANCEL") > -1 || oLoc.indexOf("#CONSENTINVALIDTOKEN") > -1) { if(oLoc.indexOf("#AUTHDONE") > -1) { AIM.core.debug("AIM.core.watchAuthRequest: Making a token request."); AIM.transactions.getToken(AIM.core.subscriptions); } else if (oLoc.indexOf("#CONSENTDONE") > -1) { if(!AIM.params.sessionId) { AIM.core.debug("AIM.core.watchAuthRequest: No session id. Requesting one."); AIM.transactions.startSession(AIM.core.subscriptions); } else { AIM.core.destroyListenerObject(true); } if(AIM.core.pendingTransaction) { switch(AIM.core.pendingTransaction.type) { case "textIM": AIM.transactions.sendTextIM(AIM.core.pendingTransaction.to,AIM.core.pendingTransaction.msg); AIM.core.pendingTransaction = null; break; case "sendDataIM": AIM.transactions.sendDataIM(AIM.core.pendingTransaction.to,AIM.core.pendingTransaction.msg,AIM.core.pendingTransaction.cap,AIM.core.pendingTransaction.dType); AIM.core.pendingTransaction = null; break; case "setState": AIM.transactions.setAwayMessage(AIM.params.text.awayMessage); AIM.core.prendingTransaction = null; break; } } } else if (oLoc.indexOf("#CONSENTINVALIDTOKEN")>-1) { AIM.transactions.endSession(); } location.replace("#aim"); document.getElementById("AIMFrameContainer_AIMwindow").style.display = "none" } else { clearTimeout(oTimeout); var oTimeout = setTimeout(AIM.core.watchAuthRequest,500); } }, /** * */ transactionTimeout: function(r) { var type = AIM.core.AIMData[r].objData.type; AIM.core.debug("TRANSACTION TIMEOUT! Transaction was " + type); clearInterval(AIM.params.transactionTimer[r]); AIM.core.callCallbacks("transactionTimeout",{response:{statusCode:200,"type":type}}); }, /** * Sends a request to the host, i.e, an instant message, status update, etc. * @param { Object } transactionObject An object defined by the AIM.transactions.* methods with properties required by the transaction */ requestData: function(transactionObject) { var len = AIM.core.AIMData.length; transactionObject.timestamp = Date.parse(new Date()); AIM.core.AIMData[len] = {}; AIM.core.AIMData[len].oScript = document.createElement("script"); AIM.core.AIMData[len].oScript.setAttribute("id","AIMBuddyList-AIMData-" + len); AIM.core.AIMData[len].oScript.setAttribute("type","text/javascript"); AIM.core.AIMData[len].oScript.className = "AIMBuddyList-AIMData"; AIM.core.AIMData[len].objData = transactionObject; if(transactionObject.dataURI.indexOf("?") == -1) { transactionObject.dataURI+="?r=" + len + "&nocache=" + Date.parse(new Date()); } else { transactionObject.dataURI+="&r=" + len + "&nocache=" + Date.parse(new Date()); } AIM.core.debug("requestData: " + transactionObject.dataURI); AIM.core.AIMData[len].oScript.setAttribute("src",transactionObject.dataURI); document.getElementsByTagName("head")[0].appendChild(AIM.core.AIMData[len].oScript); var fn = function() { AIM.core.transactionTimeout(len); } AIM.params.transactionTimer[len] = setTimeout(fn,AIM.params.TRANSACTION_TIMEOUT); }, /** * Accepts all the incoming responses that result from requestData and routes them to the appropriate callback(s) * @param { Object } json The JSON response from the host. */ acceptData:function(json) { var requestId = +json.response.requestId; var code = +json.response.statusCode; clearInterval(AIM.params.transactionTimer[requestId]); if(code != 200) { AIM.core.debug("AIM.core.acceptData: Response Error! Code is " + code + " transaction was " + AIM.core.AIMData[requestId].objData.type); if(code == 401) { var t = AIM.core.AIMData[requestId].objData.type; // only these transactions expect a 401 - if we get it on any other, kill the session if(t != "getToken" && t != "startSession" && t != "endSession") { //AIM.params.sessionId = null; //AIM.params.token = null; //AIM.transactions.endSession(); //AIM.transactions.getToken(AIM.core.subscriptions); } } } try{ AIM.core.debug("AIM.core.acceptData:
" + json.response.toSource()); } catch(err) { } var type = AIM.core.AIMData[requestId].objData.type; AIM.core.callCallbacks(type, json); try { if(AIM.core.AIMData[requestId]) { if(AIM.core.AIMData[requestId].oScript) { // Following line will cause IE to crash on a reload of the page and a relaunch of the app...go figure. if(!AIM.params.MSIE) AIM.core.AIMData[requestId].oScript.parentNode.removeChild(AIM.core.AIMData[requestId].oScript); } } } catch(err) { AIM.core.debug("AIM.core.acceptData: Unable to remove AIM.core.AIMData[" + requestId + "] -- " + err.message); } AIM.core.AIMData[requestId] = null; if(requestId % 10 == 0) { var id = requestId - 1; while(id-->0) { var script = document.getElementById("AIMBuddyList-AIMData-" + id); if(!script) break; script.parentNode.removeChild(script); } } }, /** * Iterates over the callbacks for the named transaction. Sends each of them the json object. */ callCallbacks:function(transaction, json) { var fn = eval("AIM.params.callbacks." + transaction); if(!fn) { AIM.core.debug("AIM.core.callCallbacks: no callback defined for " + type); return; } var i = fn.length; while(i-- >0) { try { eval(fn[i] +"(json)"); } catch(err) { AIM.core.debug("AIM.core.callCallbacks: Callback error! " + err.message + " (line " + err.line + ") for transaction " + fn[i]) } } }, /** * Listens for event updates (i.e., a buddy signs off) from the host and routes to the appropriate callback(s) * @param { Object } json The JSON response from the host. */ listen:function(json) { if(!json.response.data) return; AIM.core.destroyListenerObject(false); AIM.params.listenerURI = json.response.data.fetchBaseURL + "&f=json&c=AIM%2Ecore%2Elisten&timeout=" + AIM.params.REQUEST_TIMEOUT; if(json.response.data.events) { try { if(json.response.data.events.length > 0) AIM.core.debug("AIM.core.listen:
" + json.response.data.toSource()); } catch(err) { } if(json.response.statusCode == 200) { json.response.data.events = json.response.data.events.reverse(); var i = json.response.data.events.length; var isEndSession = false; while(i-- > 0) { AIM.core.debug("AIM.core.listen:" + json.response.data.events[i].type); if(json.response.data.events[i].type == "sessionEnded") isEndSession = true; fn = eval("AIM.params.callbacks.listener." + json.response.data.events[i].type); var j = fn.length; while(j-- > 0) { try { var oResponse = json.response.data.events[i].eventData; eval(fn[j] +"(oResponse)"); } catch(err) { AIM.core.debug("AIM.core.listen: Callback Error! " + err.message + " (line " + err.line + ")"); } } } } else { } } if(!isEndSession) AIM.core.requestInterval = setTimeout("AIM.core.destroyListenerObject(true)",json.response.data.timeToNextFetch); if(AIM.params.listenerIndex % 10 == 0) { var id = AIM.params.listenerIndex - 1; while(id-->0) { var script = document.getElementById("AIMListener-" + id); if(!script) break; script.parentNode.removeChild(script); } } }, /** * Creates a means of listenting for event updates from the AIM host. */ createListenerObject:function() { AIM.core.debug("createListenerObject called"); //if(!AIM.params.listenerSwfURI || !swfobject) AIM.params.useSWFListener = false; if(AIM.params.useSWFListener) { AIM.core.debug("createListenerObject: AIM.params.useSWFListener:" + AIM.params.useSWFListener); var listener = AIM.params.MSIE?window["aimapi_listener"]:document["aimapi_listener"]; if(!listener && (AIM.params.swfListenerLoadState == "unloaded")) { AIM.core.debug("createListenerObject: We need to create the listener"); AIM.params.swfListenerLoadState = "loading"; var div = document.getElementsByTagName("body")[0].appendChild(document.createElement("div")); div.setAttribute("id","aimapi_listener"); swfobject.embedSWF(AIM.params.listenerSwfURI, "aimapi_listener", "1", "1", "8"); listener = AIM.params.MSIE?window["aimapi_listener"]:document["aimapi_listener"]; /* If swfsocket doesn't load within 2 seconds, go back to script tags. */ var timeout = function(){if (AIM.params.swfListenerLoadState !== "loaded"){AIM.core.debug("swfsocket load/initialization timed out, reverting to script tags"); AIM.params.swfListenerLoadState = "failed"; AIM.params.useSWFListener = false; if (aimScriptFrame) {aimScriptFrame.engage();} AIM.core.createListenerObject();}}; window.setTimeout(timeout, 2000); } else if (AIM.params.swfListenerLoadState == "loaded") { AIM.core.debug("createListenerObject: Calling fetch with:" + AIM.params.listenerURI); listener.fetch(AIM.params.listenerURI); } else { AIM.core.debug("createListenerObject: Waiting for swfobject to load."); } } else { clearTimeout(AIM.core.requestInterval); AIM.core.destroyListenerObject(false); var oListener = document.createElement("script"); oListener.setAttribute("type","text/javascript"); oListener.setAttribute("src", AIM.params.listenerURI + "&" + Date.parse(new Date())); oListener.setAttribute("id","AIMListener-" + AIM.params.listenerIndex++); if(document.all) { oListener.onreadystatechange = AIM.core.watchReadyState; } else { oListener.onload = AIM.core.watchReadyState; } document.getElementsByTagName("head")[0].appendChild(oListener); AIM.core.connectionTimer = window.setTimeout(AIM.core.resetConnection,AIM.params.REQUEST_TIMEOUT + 3000); } document.cookie = "AIM-fetchURI=" + AIM.params.listenerURI + "; path=/; domain=" + document.domain; }, listenerLoaded: function() { AIM.core.debug("Calling listenerLoaded"); AIM.params.swfListenerLoadState = "loaded"; AIM.core.debug("Calling createListenerObject from listenerLoaded"); AIM.core.createListenerObject(); }, /** * Keeps an eye on the listener connection, restarts the connection after [x] seconds if it thinks we've lost it * */ watchReadyState: function() { window.clearTimeout(AIM.core.connectionTimer); AIM.core.connectionAttempts = 0; }, resetConnection: function() { AIM.core.debug("AIM.core.resetConnection: assuming our connection has died, starting a new one."); window.clearTimeout(AIM.core.connectionTimer); AIM.core.connectionAttempts++; if(AIM.core.connectionAttempts >= AIM.params.maxConnectionAttempts) { AIM.core.debug("AIM.core.resetConnection: Connection attempts exceeded maxConnectionAttempts (" + AIM.params.maxConnectionAttempts + "). Making deadConnection callback."); for(var i = 0; i< AIM.params.callbacks.deadConnection.length; i++) { var fn = eval("AIM.params.callbacks.deadConnection[" + i + "]"); eval(fn + "()"); } AIM.core.connectionAttempts = 0; } else { AIM.core.createListenerObject(); } }, /** * Destroys the data container object that houses the script element that made the request and all data associated with it. * @param { Variant } objIndex The index in the AIM.core.AIMData array that corresponds to the data to be destroyed. This is generally the requestId property of the JSON response */ destroyDataObject:function(objIndex) { return; // this function causing FF to crash all of a sudden... try { if(AIM.core.AIMData[objIndex]) { if(AIM.core.AIMData[objIndex].oScript) AIM.core.AIMData[objIndex].oScript.parentNode.removeChild(AIM.core.AIMData[objIndex].oScript); } } catch(err) { } AIM.core.AIMData[objIndex] = null; }, /** * Destroys the listener script object, and creates a new one if createNew is true. * @param { Boolean } createNew Creates a new listener if true. */ destroyListenerObject: function(createNew) { clearInterval(AIM.core.requestInterval); //if(document.getElementById("AIMListener")) document.getElementById("AIMListener").parentNode.removeChild(document.getElementById("AIMListener")); if(createNew) AIM.core.createListenerObject(); }, /** * Adds a callback to the callback object * @param { Array } callbackObject The array that contains the callback functions for the event * @param {String } newCallBack The name of the function to be called. */ addCallback: function(callbackObject,newCallback) { callbackObject.push(newCallback); }, /** * Removes a callback from the specified callback array * @param { Array } callbackObject The array that contains the callback function to be removed * @param { String } oldCallback The callback to be removed */ removeCallback: function(callbackObject,oldCallback) { callbackObject.splice(callbackObject.indexOf(oldCallback)); }, /** * General debug function for the application. Appends a DIV to the body element with an id of "AIMDebugger" and writes out debug data if the DEBUG param is true. * @param { String } str The string to be written out to the debug div. */ debug: function(str) { if(!AIM.params.DEBUG) return; if(!document.getElementById("AIMDebugger")) { var dbg = document.getElementsByTagName("body")[0].appendChild(document.createElement("div")); dbg.setAttribute("id","AIMDebugger"); } document.getElementById("AIMDebugger").innerHTML = "

" + new Date() + "(" + Date.parse(new Date()) + ")
" + str + "

" + document.getElementById("AIMDebugger").innerHTML; } } /** * Callback object contains all the functions that AIM.core.acceptData will call upon receiving a host response * for the given event type. */ AIM.callbacks = { /** * Requests a new session if a token is granted, otherwise pops the authorization window so the user can log in. * @param { Object } json The JSON response from the host */ getToken: function(json) { if(json.response.statusCode == 200) { AIM.params.token = json.response.data.token.a; AIM.transactions.startSession(AIM.core.AIMData[json.response.requestId].objData.eventList); } else if (json.response.statusCode == 450 || json.response.statusCode == 401 || json.response.statusCode == 330) { AIM.core.createAuthWindow(json.response.data.redirectURL + "?k=" + AIM.params.wimKey + "&siteui=1"); } else { //alert(AIM.params.text.errors.serverErrors[json.response.statusCode]); } }, /** * Starts a new session on a succesfull startSession request. Creates the listener object for the session. * @param { Object } json The JSON response from the host. */ startSession: function(json) { if(json.response.statusCode == 200) { AIM.params.user = json.response.data.myInfo.displayId; AIM.params.sessionId = json.response.data.aimsid; AIM.params.listenerURI = json.response.data.fetchBaseURL + "&f=json&c=AIM%2Ecore%2Elisten&timeout=" + AIM.params.REQUEST_TIMEOUT; var fn = function() { AIM.core.createListenerObject(); } // give BOSS a chance to get its pants on window.setTimeout(fn,500); AIM.core.activeSession = true; } else if(json.response.statusCode == 450) { AIM.core.createAuthWindow(json.response.data.redirectURL + "&k=" + AIM.params.wimKey + "&siteUI=1"); } else if (json.response.statusCode == 451) { AIM.transactions.endSession(); } else { AIM.core.debug("Unable to start a session. Code is " + json.response.statusCode); } AIM.core.destroyDataObject(json.response.requestId); } } /** * User interface helper methods. */ AIM.ui = { /** * Creates the basic elements required for a window, and sets up drag and title. * @param { String } identifier The "id" of the window. * @param { String } clsName The "class" of the window. * @param { String } winTitle The title of the window. * @return { HTMLObject } An DIV element styled like a window, w/o content. * @type HTMLObject */ createWindowFrame: function(identifier,clsName,winTitle) { var win = document.createElement("div"); win.setAttribute("id",identifier + "_AIMwindow"); win.style.zIndex = 10000; win.className = clsName; win.AIMTopWindow = "false"; var h2 = document.createElement("h2"); h2.appendChild(document.createTextNode(winTitle)); h2.className = "AIMBuddyListWindowTitleBar"; win.appendChild(h2); return win; } } /** * A set of methods for sending data to the host. */ AIM.transactions = { /** * Sends a text IM * @param { String } aimId The id to whom the IM should go. * @param { String } txt The message to tbe sent. */ sendTextIM:function(aimId,txt) { if(txt.trim() == "") return; if(AIM.params.comscoreKey) { var comscore = "comScoreChannel=" + AIM.params.comscoreKey; } else { var comscore = ""; } aimId = encodeURIComponent(aimId); txt = encodeURIComponent(txt); tObj = { dataURI:AIM.params.baseTransactionURI + AIM.params.transactions.sendTextIM + "?aimsid=" + AIM.params.sessionId + "&message=" + txt + "&t=" + aimId + "&f=json&c=AIM%2Ecore%2EacceptData&offlineIM=" + AIM.params.SEND_OFFLINE_IM + "&" + comscore, type:"sendTextIM", to:aimId, msg:txt } AIM.core.requestData(tObj); }, /** * Sends a data IM * @param { String } aimId The id to whom the IM should go. * @param { String } data The data to be sent. * @param { String } cap UUID of the capability * @param { String} type the type of data being sent */ sendDataIM: function(aimId,data,cap,type) { if(data.trim() == "") return; var aimId = encodeURIComponent(aimId); var data = encodeURIComponent(data); var cap = encodeURIComponent(cap); var type = encodeURIComponent(type); var tObj = { dataURI: AIM.params.baseTransactionURI + AIM.params.transactions.sendDataIM + "?aimsid=" + AIM.params.sessionId + "&data=" + data + "&k=" + AIM.params.wimKey + "&t=" + aimId + "&type=" + type + "&cap=" + cap + "&f=json&c=AIM%2Ecore%2EacceptData", type:"sendDataIM", to:aimId, data:data, dType:type, cap:cap } AIM.core.requestData(tObj); }, /** * Requests the user's share settings. Will always return a 450 along with a redirectURI to display a UI that will allow the user to adjust their settings. */ getShareSettings: function() { var tObj = { dataURI:AIM.params.baseTransactionURI + AIM.params.transactions.getShareSettings + "?a=" + AIM.params.token + "&k=" + AIM.params.wimKey + "&f=json&c=AIM%2Ecore%2EacceptData", type:"getShareSettings" } AIM.core.requestData(tObj); }, /** * Requests the user's current status message */ getStatus: function() { if(AIM.params.disabled) return; var tObj = { dataURI:AIM.params.baseTransactionURI + AIM.params.transactions.getStatus + "?profileMsg=1&statusMsg=1&awayMsg=1&k=" + AIM.params.wimKey + "&t=" + AIM.params.owner + "&f=json&c=AIM%2Ecore%2EacceptData", type:"getStatus" } AIM.core.requestData(tObj); }, /** * Sets the user's status message * @param { String } statusMsg The status message to be set */ setStatus: function(statusMsg) { statusMsg = encodeURIComponent(statusMsg); var tObj = { dataURI: AIM.params.baseTransactionURI + AIM.params.transactions.setStatus + "?statusMsg=" + statusMsg + "&k=" + AIM.params.wimKey + "&a=" + AIM.params.token + "&f=json&c=AIM%2Ecore%2EacceptData", type:"setStatus" } AIM.core.requestData(tObj); }, /** * Requests a users buddy list * */ getBuddyList:function() { var tObj = { dataURI:AIM.params.baseTransactionURI + AIM.params.transactions.getBuddyList + "?bl=1&statusMsg=1&awayMsg=1&aimsid=" + AIM.params.sessionId + "&f=json&a=" + AIM.params.token + "&c=AIM%2Ecore%2EacceptData", aimId:AIM.params.user, type:"getBuddyList" }; AIM.core.requestData(tObj); }, /** * Retrieves the user's buddy feed * @param { Object } args Arguments to pass over the URI to the host transaction. */ getBuddyFeed: function(args) { if(!args) args = {}; if(!args.maxItems) args.maxItems = 50; if(!args.maxItemsPerMember) args.maxItemsPerMember = 3; if(!args.maxMembers) args.maxMembers = 50; if(!args.groupBy) args.groupBy = "F"; var sig = AIM.params.sessionId?"aimsid=" + AIM.params.sessionId:"a=" + AIM.params.token; var tObj = { dataURI:AIM.params.baseTransactionURI + AIM.params.transactions.getBuddyFeed + "?" + sig + "&bfUI=0&awayMsgs=N&c=AIM%2Ecore%2EacceptData&f=json&groupBy=" + args.groupBy + "&k=" + AIM.params.wimKey + "&maxItems=" + args.maxItems + "&maxItemsPerMember=" + args.maxItemsPerMember + "&maxMembers=" + args.maxMembers + "&includeSelf=1", type:"getBuddyFeed" } AIM.core.requestData(tObj); }, /** * Pushes an item into a user's buddy feed. * @param { Object } args Arguments to pass over the URI to the host transaction */ pushFeed: function(args) { if(!args) args = {}; if(!AIM.params.feeds.feedTitle || !AIM.params.feeds.feedLink || !AIM.params.feeds.feedDesc || !args.itemTitle || !args.itemLink) { AIM.core.debug("AIM.transactions.pushFeed: Missing a required attribute, aborting."); return; } if(!args.guidPrefix) args.guidPrefix = "StMsg"; args.itemGuid = args.guidPrefix + Date.parse(new Date()); var argString = ""; for(var i in args) argString += "&" + i + "=" + encodeURIComponent(args[i]); argString += "&feedDesc=" + AIM.params.feeds.feedDesc + "&feedTitle=" + AIM.params.feeds.feedTitle + "&feedLink=" + AIM.params.feeds.feedLink; var tObj = { dataURI:AIM.params.baseTransactionURI + AIM.params.transactions.pushFeed + "?a=" + AIM.params.token + "&f=json&c=AIM%2Ecore%2EacceptData&k=" + AIM.params.wimKey + argString, type:"pushFeed" } AIM.core.requestData(tObj); }, /** * Retrieves the site feed. */ getSiteFeed: function() { var tObj = { dataURI: AIM.params.baseTransactionURI + AIM.params.transactions.getSiteFeed + "?k=" + AIM.params.wimKey + "&f=json&c=AIM%2Ecore%2EacceptData", type:"getSiteFeed" } AIM.core.requestData(tObj); }, /* * Deprectacated. use getStatus */ getBuddyInfo: function(oScreenName) { var tObj = { dataURI:AIM.params.baseTransactionURI + AIM.params.transactions.getBuddyInfo + "?displayId=" + oScreenName, aimId:oScreenName, type:"getBuddyInfo" } AIM.core.requestData(tObj); }, /** * Requests an authentication token from the host. * @param { String } eList A comma dilimited list of events the application should subscribe to. Defined in AIM.core.subscriptions. */ getToken: function(eList) { var succUrl = ""; var f = "json"; if(AIM.params.authenticationMode == 1) { var succUrl = AIM.params.succUrl?"&succUrl=" + encodeURIComponent(AIM.params.succUrl):""; var f = AIM.params.getTokenResponseFormat?AIM.params.getTokenResponseFormat:"json"; } var tObj = { dataURI:AIM.params.baseAuthURI + AIM.params.transactions.getToken + "?k=" + AIM.params.wimKey + "&f=" + f + "&c=AIM%2Ecore%2EacceptData" + succUrl, type:"getToken", eventList:eList } AIM.core.authenticationStep = "getToken"; if(AIM.params.authenticationMode == 1) { var x = (screen.width - AIM.params.authWindowDimensions.w)/2 var y = (screen.height - AIM.params.authWindowDimensions.h)/2 var oWin = window.open(tObj.dataURI,"AuthWindow","resizable=yes,width=" + AIM.params.authWindowDimensions.w + ",height=" + AIM.params.authWindowDimensions.h + ",top=" + y + ",left=" + x + ",directories=no,titlebar=no,status=no,menubar=no,toolbar=no,location=yes"); //oWin.location.href = tObj.dataURI; } else { AIM.core.requestData(tObj); } }, /** * Request presence data from the host. If signed is false, call is made anonymously (no login required). * @param { String } paramString the "t" param for the request, i.e. t=screename&t=foo&t=bar&t=baz * @param { Boolean } signed if true call passes the aimsid, otherwise call is made anonymously */ getPresenceInfo: function(paramString,signed) { var aimsid = signed?"&aimsid=" + AIM.params.sessionId:""; var tObj = { dataURI: AIM.params.baseTransactionURI + AIM.params.transactions.getPresenceInfo + "?" + paramString + "&k=" + AIM.params.wimKey + "&awayMsg=1&f=json&c=AIM%2Ecore%2EacceptData" + aimsid, type:"getPresenceInfo" } AIM.core.requestData(tObj); }, /** * Retrieves the permit deny list (users that are being ignored/blocked/etc) */ getPermitDeny: function() { var tObj = { dataURI:AIM.params.baseTransactionURI + AIM.params.transactions.getPermitDeny + "?aimsid=" + AIM.params.sessionId + "&f=json&c=AIM%2Ecore%2EacceptData", type:"getPermitDeny" } AIM.core.requestData(tObj); }, setPermitDeny: function(args) { function createParamString(paramName, values) { var params = ""; if(values[paramName]) { var items = values[paramName].length; if (items) { // These might be an array of id's, so go through each id to url-safe them // This is important for ids like phone numbers (+94945551234) and emails for(var i=0; iAIM.params.AWAY_MSG_LIMIT) msg = msg.substring(0,AIM.params.AWAY_MSG_LIMIT); if(msg.trim() == "") msg = "I am away from my computer right now."; msg = encodeURIComponent(msg); AIM.params.text.awayMessage = msg; AIM.util.resetUserNotified(); AIM.transactions.setState("away"); }, /** * Not yet implimented. */ setProfile:function() { }, /** * Notifies the host that the user is typing. * @param { String } tStatus The status of the typing. typing typed or none. * @param { aimId } The id of the user to notify of the typing status. */ typingStatus:function(tStatus,aimId) { if(new Date() - AIM.util.typingStatusTimeStamp < 2000) return; AIM.util.typingStatusTimeStamp = new Date(); aimId = encodeURIComponent(aimId); var tObj = { dataURI:AIM.params.baseTransactionURI + AIM.params.transactions.typingStatus + "?aimsid=" + AIM.params.sessionId + "&t=" + aimId + "&typingStatus=" + tStatus + "&f=json&c=AIM%2Ecore%2EacceptData", type:"typingStatus" } AIM.core.requestData(tObj); } } /** * utility methods */ AIM.util = { /** * Creates a script element and appends it to the head element * @param { String } uri The url of the javascript file to import */ importScript: function(uri) { var oScript = document.createElement("script"); oScript.setAttribute("type","text/javascript"); oScript.setAttribute("src",uri); document.getElementsByTagName("head")[0].appendChild(oScript); } }