Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tizum5 opened this issue May 9, 2023 · 1 comment

Comments

@Tizum5
Copy link

Tizum5 commented May 9, 2023

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
`

@scotttrinh
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants