Skip to content

im haveing trouble deleteing an extra 'const createPool = edged.createPool' #29

@Tizum5

Description

@Tizum5

whenever i delete the 2nd 'const createPool = edged.createPool' it breaks my code any advice on how to fix it? im only haveing it send call logs to the database

`const { createPool } = require('edgedb');

if (!crypto.timingSafeEqual(calculatedTag, authTag)) {
throw new Error('Message authentication failed');
}

class RtcSignalingService extends Service {
constructor(options) {
super(options);
this.sessions = {};
}

async create(data, params) {
    const { sessionId, offer } = data;
    const { user } = params;
    this.sessions[sessionId] = {
        caller: user._id,
        startTime: new Date(), //record the start time
    };

    if (!this.sessions[sessionId]) {
        this.sessions[sessionId] = { caller: user._id };
    } else {
        this.sessions[sessionId].callee = user._id;
    }

    const session = this.sessions[sessionId];
    const otherUserId = session.caller === user._id ? session.callee : session.caller;

    this.app.channel(`user/${otherUserId}`).send({
        event: 'offer',
        offer,
        from: user._id,
        sessionId,
    });

    return { sessionId };
}

async patch(id, data, params) {
    const { sessionId, answer } = data;
    const { user } = params;

    const session = this.sessions[sessionId];
    const otherUserId = session.caller === user._id ? session.callee : session.caller;

    this.app.channel(`user/${otherUserId}`).send({
        event: 'answer',
        answer,
        from: user._id,
        sessionId,
    });

    return {};
}

async remove(id, params) {
    const { sessionId } = params.query;
    const session = this.sessions[sessionId];
    await this.insertCallRecord(
        sessionId,
        session.caller,
        session.callee,
        session.startTime,
        new Date() //Record the end time
    );
    delete this.sessions[sessionId];
    return {};
}

async insertCallRecord(sessionId, callerId, calleeId, startTime, endTime) {
    const query = `
        INSERT Call {
            sessionId := <uuid>$sessionId,
            caller := (SELECT User FILTER .id = <uuid>$callerId),
            callee := (SELECT User FILTER .id = <uuid>$calleeId),
            startTime := <datetime>$startTime,
            endTime := <datetime>$endTime,
        }
    `;
    const connectionPool = createPool({
        host: process.env.HOST,
        port: process.env.PORT,
        user: process.env.ADMIN,
        password: process.env.PASSWORD,
        database: process.env.VOICE_LOGS
    });
    await connectionPool.query(query, {
        sessionId,
        callerId,
        calleeId,
        startTime,
        endTime,
    });
}

}

module.exports = function(app) {
app.use('/rtc-signaling', new RtcSignalingService());
};

//on caller side
const session = this.sessions[sessionId];
const otherUserId = session.caller === user._id ? session.callee : session.caller;
const callerOffer = await pc.createOffer();
await pc.setLocalDescription(callerOffer);

//send the offer to the other party via signaling server
this.app.channel(user/${otherUserId}).send({
event: 'offer',
offer: callerOffer.toJSON(),
from: user._id,
sessionId,
});

// On the callee side:
const { from: incomingOtherUserId, sessionId } = data;
const calleeOffer = new RTCSessionDescription(data.offer);
await pc.setRemoteDescription(calleeOffer);
const answer = await pc.createAnswer();
await pc.setLocalDescription(answer);

//send the answer to the caller via the signaling server
this.app.channel(user/${otherUserId}).send({
event: 'answer',
answer: answer.toJSON(),
from: user._id,
sessionId,
});

const createPool = edged.createPool
calllogs
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions