edgedb-editor-plugin icon indicating copy to clipboard operation
edgedb-editor-plugin copied to clipboard

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

Open Tizum5 opened this issue 2 years ago • 1 comments

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 `

Tizum5 avatar May 09 '23 07:05 Tizum5

It seems like there was some issue formatting the code correctly in this issue, do you mind trying again and maybe running it throw the Prettier playground to get proper formatting? It seems like there are parts of the code that is missing, etc. See https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#syntax-highlighting for more guidance on correctly creating code blocks in GitHub markdown.

Also, all of these errors look like formatting errors (using CRLF instead of LF for line endings, indentation issues, etc) and nothing related to the EdgeDB editor plugin. Maybe ensure that your linting and formatting tools are set up properly?

scotttrinh avatar May 09 '23 13:05 scotttrinh