2 * ICQJS - áèáëèîòåêà äëÿ èñïîëüçîâàíèÿ Âåá ÀÏÈ àñüêè â äæàâàñêðèïòå
3 * (c) InceptionTime, 2024.
4 * Äîêóìåíòàöèÿ íà OSDN è â docs/index.MD
7 constructor(login, password, fetchCallback, devId, screenNameAPIHost = "https://api.screenname.nina.bz", mainAPIHost = "https://api.oscar.nina.bz"){
10 * Docs: COMING SOON...
14 * Èíèöèàëèçàöèÿ ïåðåìåííûõ êëàññà
17 this.password = password;
18 this.screenNameAPIHost = screenNameAPIHost;
19 this.mainAPIHost = mainAPIHost;
20 this.fetchCallback = fetchCallback;
22 this.loggedIn = false;
24 * Àóòåíòèôèêàöèÿ ïîëüçîâàòåëÿ. Èñïîëüçóåì clientLogin è ñèíõðîííûé XHR
26 let xhr = new XMLHttpRequest();
27 let data = `f=JSON&k=${this.devId}&s=${this.login}&pwd=${this.password}&clientVersion=0.1&ClientName=OscarWave`;
28 xhr.open('POST', `${this.screenNameAPIHost}/auth/clientLogin?f=JSON`), false);
29 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
31 if (xhr.status === 200) {
32 let respObj = JSON.parse(xhr.responseText);
33 this.aToken = respObj.response.data.token.a;
34 this.sessionSecret = respObj.response.data.sessionSecret;
37 throw new Error('Request failed: ' + xhr.statusText);
40 // Ãåíåðèðóåì êëþ÷. Çäåñü ïîíàäîáèòñÿ çàâèñèìîñòü lib/CryptHMAC.js
41 this.sessionKey = btoa(_HMAC(this.password,this.sessionSecret));
43 // Ñòàâèì ñåññèîííóþ ïåðåìåííóþ âõîäà
46 // Óíè÷òîæàåì ïàðîëü äëÿ áåçîïàñíîñòè
59 * Docs: COMING SOON...
61 let xhr = new XMLHttpRequest();
62 let data = `f=JSON&k=${this.devId}&a=${this.aToken}&events=im`;
63 xhr.open('GET', `${this.screenNameAPIHost}/aim/startSession?${data}`;
65 if (xhr.status === 200) {
66 let respObj = JSON.parse(xhr.responseText);
67 this.aimsid = respObj.response.data.aimsid;
68 this.status = respObj.response.data.myInfo.state;
69 this.displayName = respObj.response.data.myInfo.displayId;
70 this.fetchURL = respObj.response.data.fetchBaseURL;
73 throw new Error('Request failed: ' + xhr.statusText);
80 * Áåñêîíå÷íûé ôåò÷ èâåíòîâ.
81 * Docs: COMING SOON...