RealTime Collaborative Text-Editor in Nodejs & Socket.io

后端 未结 2 832
-上瘾入骨i
-上瘾入骨i 2021-02-06 19:57

I am developing a real-time text editor with paragraph locking property similar to https://quip.com/. in socket.io and nodejs

相关标签:
2条回答
  • 2021-02-06 20:14

    I saw this yesterday already. What exactly is your question? Do you want to know how to 'lock' a text area with javascript? I am confused as to why you put such a strong emphasis on node/socket.io in your question.

    Also, next time please format your code. You want help, I get it, but then make it easier for others to help you.

    What you have to do in order to make a paragraph not editable by others, I don't know. But let me suggest what I'ld do in socket.io:

    Store each paragraph separately and remember who has a lock on it. For locking, I would use the sessionID in case users don't have to register. This would look something like this:

    var paragraphs = {
        data : [
            {
                text: "this is an unlocked paragraph",
                lock: ""
            },
            {
                text: "this is a locked paragraph",
                lock: "oWEALlLx5E-VejicAAAC"
            }
        ]
    }
    

    Now, users will likely be allowed to add a paragraph before an existing one. Therefore you should keep an additional index like:

    var paragraphs = {
        index : [
            1,
            0
        ],
        data : [
            {
                text: "this the second paragraph",
                lock: "oWEALlLx5E-VejicAAAC"
            },
            {
                text: "this is the first paragraph",
                lock: ""
            }
        ]
    }
    

    The amount of data being sent over the sockets should now be very small - altough with additional client/server-side logic.

    0 讨论(0)
  • 2021-02-06 20:30

    Paragraph lock can be easily achieved by adding a class to the currently editing paragraph. Transfer this paragraph with the class to the other user. so that if the user tries to write over that prevent him by validate with the class.

    Generate a class name look like - className_userid (className_1).

    0 讨论(0)
提交回复
热议问题