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/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/gadevoir/app/GDVClient.js
import SocketIOClient from 'socket.io-client';
import EventEmitter from "absol/src/HTML5/EventEmitter";
import OOP from "absol/src/HTML5/OOP";
import {Device} from "mediasoup-client";

/***
 * @extends EventEmitter
 * @param config
 * @constructor
 */
function GDVClient(config) {
    EventEmitter.call(this);
    this.config = config;
    this.socket = new SocketIOClient('https://' + this.config.host + ':' + this.config.port,
        {
            path: '/server',
            transports: ['websocket'],
        }
    );
    this.device = new Device();
    this._setupSocket();

}

OOP.mixClass(GDVClient, EventEmitter);


GDVClient.prototype.eventList = [
    'other_offline', 'other_online',
    'outcome_resolve',
    'income'
]
GDVClient.prototype._setupSocket = function () {
    for (var i = 0; i < this.eventList.length; ++i) {
        this.socket.on(this.eventList[i], this._repeatEvent.bind(this, this.eventList[i]));
    }
};

GDVClient.prototype._loadDevice = function () {
    var thisC = this;
    return new Promise(function (resolve) {
        thisC.request('getRouterRtpCapabilities').then(function (result) {
            thisC.device.load({ routerRtpCapabilities: result }).then(resolve);
        })
    });
}

GDVClient.prototype._repeatEvent = function () {
    this.emit.apply(this, arguments);
};

GDVClient.prototype.request = function (type, data) {
    var socket = this.socket;
    return new Promise(function (resolve) {
        socket.emit(type, data, resolve);
    });
};

GDVClient.prototype.send = function (type, data) {
    this.socket.emit(type, data);
};

/***
 *
 * @param {string} type
 * @param {function(data: object):void} callback
 */
GDVClient.prototype.onReceive = function (type, callback) {
    this.socket.on(type, callback);
};

/***
 *
 * @param {string} type
 * @param {function(data: object):void} callback
 */
GDVClient.prototype.offReceive = function (type, callback) {
    this.socket.off(type, callback);
};

/***
 *
 * @param {string} type
 * @param {function(data: object):void} callback
 */
GDVClient.prototype.onceReceive = function (type, callback) {
    this.socket.once(type, callback);
};


GDVClient.prototype.login = function (userData) {
    var thisC = this;
    return this.request('login', userData)
        .then(function (result) {
            if (result.error) {
                console.error(result.error)
            }
            else {
                thisC.id = result.id;
                thisC.name = result.name;
                thisC.token = result.token;
                return thisC._loadDevice().then(function (){return result});

            }
            return result;
        });
};


GDVClient.prototype.getContactList = function () {
    return this.request('getContactList');
};


export default GDVClient;

VaKeR 2022