![]() 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/server/ |
Upload File : |
/*** * * @param {GDVServer} server * @param {{conversationId: string, outgoingUser:User, incomeUser:User}} props * @constructor */ function Conversation(server, props) { this.server = server; this.conversationId = null; this.outgoingUser = null; this.incomeUser = null; Object.assign(this, props); } Conversation.prototype.start = function () { this.incomeUser.conversation = this; this._incomeEvents = { createSendTransport: this.ev_createSendTransport.bind(this, this.incomeUser), connectSendTransport: this.ev_connectSendTransport.bind(this, this.incomeUser), createRecvTransport: this.ev_createRecvTransport.bind(this, this.incomeUser), connectRecvTransport: this.ev_connectRecvTransport.bind(this, this.incomeUser), produce: this.ev_produce.bind(this, this.incomeUser), consume: this.ev_consume.bind(this, this.incomeUser) }; this._outgoinEvents = { createSendTransport: this.ev_createSendTransport.bind(this, this.outgoingUser), connectSendTransport: this.ev_connectSendTransport.bind(this, this.outgoingUser), createRecvTransport: this.ev_createRecvTransport.bind(this, this.outgoingUser), connectRecvTransport: this.ev_connectRecvTransport.bind(this, this.outgoingUser), produce: this.ev_produce.bind(this, this.outgoingUser), consume: this.ev_consume.bind(this, this.outgoingUser) } this.incomeUser.producerSync = new Promise(function (resolve) { this.producerSyncResolve = resolve; }.bind(this.incomeUser)); this.incomeUser.consumerSync = new Promise(function (resolve) { this.consumerSyncResolve = resolve; }.bind(this.incomeUser)) this.outgoingUser.producerSync = new Promise(function (resolve) { this.producerSyncResolve = resolve; }.bind(this.outgoingUser)); this.outgoingUser.consumerSync = new Promise(function (resolve) { this.consumerSyncResolve = resolve; }.bind(this.outgoingUser)); this._addEventObj(this.incomeUser.socket, this._incomeEvents); this._addEventObj(this.outgoingUser.socket, this._outgoinEvents); }; Conversation.prototype.stop = function () { this.incomeUser.conversation = null; this._removeEventObj(this.incomeUser.socket, this._incomeEvents); this._removeEventObj(this.outgoingUser.socket, this._outgoinEvents); }; Conversation.prototype.ev_createRecvTransport = function (user, data, resolveCb) { var server = this.server; const otherUser = user === this.incomeUser ? this.outgoingUser : this.incomeUser; if (!user.recvTransportSync) user.recvTransportSync = server.createWebRtcTransport(otherUser); user.recvTransportSync.then(function (result) { user.recvTransport = result.transport; console.log(user.name, "createRecvTransport"); resolveCb(result.params); }); }; Conversation.prototype.ev_createSendTransport = function (user, data, resolveCb) { var server = this.server; if (!user.sendTransportSync) user.sendTransportSync = server.createWebRtcTransport(user); user.sendTransportSync.then(function (result) { user.sendTransport = result.transport; console.log(user.name, "createSendTransport"); resolveCb(result.params); }); }; Conversation.prototype.ev_connectRecvTransport = function (user, data, callback) { console.log(user.name, "connectRecvTransport"); user.recvTransport.connect({ dtlsParameters: data.dtlsParameters }) .then(callback); }; Conversation.prototype.ev_connectSendTransport = function (user, data, callback) { console.log(user.name, "connectSendTransport"); user.sendTransport.connect({ dtlsParameters: data.dtlsParameters }) .then(callback); }; Conversation.prototype.ev_produce = function (user, data, resolveCb) { console.log(user.name, "ev_produce"); const { kind, rtpParameters } = data; user.sendTransport.produce({ kind, rtpParameters }).then(function (producer) { user.producer = producer; user.producerSyncResolve && user.producerSyncResolve(producer); user.producerSyncResolve = null; console.log('create producer', user.name); resolveCb({ id: producer.id }); }); }; Conversation.prototype.ev_consume = function (user, data, resolveCb) { console.log(user.name, "ev_consume"); const { rtpCapabilities } = data; const otherUser = user === this.incomeUser ? this.outgoingUser : this.incomeUser; otherUser.producerSync.then(function (producer) { if (!otherUser.router.canConsume({ producerId: producer.id, rtpCapabilities, })) { resolveCb({ error: "CANNOT_CONSUME" }); return; } user.recvTransport.consume({ producerId: producer.id, rtpCapabilities, paused: producer.kind === 'video' }).then(function (consumer) { user.consumer = consumer; user.consumerSyncResolve && user.consumerSyncResolve(consumer); user.consumerSyncResolve = null; console.log({producerId: producer.id, id: consumer.id}) resolveCb({ producerId: producer.id, id: consumer.id, kind: consumer.kind, rtpParameters: consumer.rtpParameters, type: consumer.type, producerPaused: false }); }); }.bind(this)); }; Conversation.prototype._addEventObj = function (obj, events) { Object.keys(events).forEach(function (key) { obj.on(key, events[key]); }); }; Conversation.prototype._removeEventObj = function (obj, events) { Object.keys(events).forEach(function (key) { obj.off(key, events[key]); }); }; module.exports = Conversation;