VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/gadevoir/app/fragment/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/gadevoir/app/fragment/MainFrg.js
import EventEmitter from "absol/src/HTML5/EventEmitter";
import Fragment from "absol/src/AppPattern/Fragment";
import OOP from "absol/src/HTML5/OOP";
import '../../style/mainfrag.css';
import {$, _} from "../dom/Core";
import MHeaderBar from "absol-mobile/js/dom/MHeaderBar";
import ContactItem from "../dom/ContactItem";
import OutgoingFrg from "./OutgoingFrg";
import IncomeFrg from "./IncomeFrg";
import ConversationFrg from "./ConversationFrg";


/***
 * @augments EventEmitter
 * @augments Fragment
 * @constructor
 */
function MainFrg() {
    EventEmitter.call(this);
    Fragment.call(this);
    /***
     *
     * @type {GPhone|null}
     */
    this.phone = null;
    this.$itemByName = {};
    this.ev_income = this.ev_income.bind(this);
    this.ev_whoOnline = this.ev_whoOnline.bind(this);
}

OOP.mixClass(MainFrg, EventEmitter, Fragment);

MainFrg.prototype.createView = function () {
    this.$view = _({
        class: ['gdv-fragment', 'gdv-main-frag'],
        child: [
            {
                tag: MHeaderBar.tag,
                props: {
                    title: "Contact"
                }
            },
            '.gdv-main-frag-contact-list'
        ]
    });
    this.$header = $(MHeaderBar.tag, this.$view);
    this.$contactList = $('.gdv-main-frag-contact-list', this.$view);
};


MainFrg.prototype.onStart = function () {
    this.phone = this.getContext("PHONE");
    this.$header.title = this.phone.number + "'s contacts";
};

MainFrg.prototype.onResume = function () {
    this._loadOnlineList();
    setTimeout(this._loadOnlineList.bind(this), 1000);
    this.phone.pkgRecv.on('who_online', this.ev_whoOnline);
    this.phone.on('income', this.ev_income);
};

MainFrg.prototype.onStop = function () {
    // this.connector.offReceive('income', this.ev_income);
};

MainFrg.prototype.onPause = function () {
    this.phone.pkgRecv.off('who_online', this.ev_whoOnline);
    this.phone.off('income', this.ev_income);
};

MainFrg.prototype._loadOnlineList = function () {
    var thisF = this;
    this.phone.getOnlineList().then(function (result){
        var phoneNumbers = Object.keys(result);
        thisF.$contactList.clearChild();
        thisF.$itemByName = phoneNumbers.reduce(function (ac, item) {
            var itemElt = thisF._makeContactItem(item);
            thisF.$contactList.addChild(itemElt);
            ac[item] = itemElt;
            return ac;
        }, {});
    });
};

MainFrg.prototype._makeContactItem = function (phoneNumber) {
    return _({
        tag: ContactItem.tag,
        props: {
            name: phoneNumber,
            online: true
        },
        on: {
            pressvoice: this.callTo.bind(this, phoneNumber, 'voice'),
            pressvideo: this.callTo.bind(this, phoneNumber, 'video')
        }
    })
};

MainFrg.prototype.ev_whoOnline = function (data, pack) {
    if (pack.sourcePhone === this.phone.number) return;
    if (!pack.sourcePhone) return;
    var itemElt = this.$itemByName[pack.sourcePhone];
    if (!itemElt) {
        itemElt = this._makeContactItem(pack.sourcePhone);
        this.$itemByName[pack.sourcePhone] = itemElt;
        this.$contactList.addChild(itemElt);
    }
    itemElt.online = true;
};

MainFrg.prototype.ev_otherOffline = function (userInfo) {
    var itemElt = this.$itemByName[userInfo.name]
    if (itemElt) itemElt.online = false;
};

MainFrg.prototype.ev_income = function (incomeData) {
    var app = this.getContext("APP");
    console.log(incomeData)
    app.startFrag(IncomeFrg, {
        incomeType: incomeData.type, from: incomeData.from,
        conversationId: incomeData.id
    }, true).then(function (returns) {
        if (returns && returns.answer === 'ACCEPT') {
            app.startFrag(ConversationFrg);
        }
    });
};

MainFrg.prototype.callTo = function (phoneNumber, type) {
    var app = this.getContext("APP");
    app.startFrag(OutgoingFrg, { outgoingType: type, to: phoneNumber }, true)
        .then(function (returns) {
            if (returns && returns.answer === 'ACCEPT') {
                app.startFrag(ConversationFrg);
            }
        });
};


export default MainFrg;

VaKeR 2022