realtime-csharp icon indicating copy to clipboard operation
realtime-csharp copied to clipboard

Presence can send both a `Leave` and `Join` event that cancel each other out.

Open acupofjose opened this issue 2 years ago • 1 comments

I noticed that sending a Track Event manually whilst already joined to the channel causes both a Join and Leave eventto be raised. However, the Leave event is raised after the join making it appear as though I left when I didn't.

29 May 2023 12:08:29 Sending Track Event
29 May 2023 12:08:29 Realtime Client Debug Message: Socket Push [topic: realtime:11111111111111111111111111111111, event: presence, ref: 5d6df879-afa3-4961-8eea-c8f548630ad9]:	{  "event": "track",  "payload": {    "LastSeen": "2023-05-29T11:08:29.1576795Z",    "Email": "[email protected]",    "Name": "Daz Kuffs",    "ComputerName": "RAGE",    "UserID": "7aaab6a9-fe93-47e9-a3d0-eb717389cf9a",    "ConnectID": "00000000-0000-0000-0000-000000000000",    "SharedInstances": [      {        "InstanceID": "409f44f0-0542-49bc-bec5-47de2b59be48",        "InstanceName": "Ruffster",        "ComputerName": "RAGE",        "RemoteComputerID": "1a796a13-bd00-4a35-835e-648682a2601b",        "UserID": "7aaab6a9-fe93-47e9-a3d0-eb717389cf9a"      }    ]  }}
29 May 2023 12:08:29 Realtime Client Debug Message: Socket Message Received:	{"event":"phx_reply","payload":{"response":{},"status":"ok"},"ref":"5d6df879-afa3-4961-8eea-c8f548630ad9","topic":"realtime:11111111111111111111111111111111"}
29 May 2023 12:08:29 Realtime Client Debug Message: Socket Message Received:	{"event":"presence_diff","payload":{"joins":{"145bacf8-fe11-11ed-9abb-6a2047d90b67":{"metas":[{"phx_ref":"F2OYoo6yrtA9v9zm","phx_ref_prev":"F2OYnFmge_Q9v3RI","ComputerName":"RAGE","ConnectID":"00000000-0000-0000-0000-000000000000","Email":"[email protected]","LastSeen":"2023-05-29T11:08:29.1576795Z","Name":"Daz Kuffs","SharedInstances":[{"ComputerName":"RAGE","InstanceID":"409f44f0-0542-49bc-bec5-47de2b59be48","InstanceName":"Ruffster","RemoteComputerID":"1a796a13-bd00-4a35-835e-648682a2601b","UserID":"7aaab6a9-fe93-47e9-a3d0-eb717389cf9a"}],"UserID":"7aaab6a9-fe93-47e9-a3d0-eb717389cf9a"}]}},"leaves":{"145bacf8-fe11-11ed-9abb-6a2047d90b67":{"metas":[{"phx_ref":"F2OYnFmge_Q9v3RI","ComputerName":"RAGE","ConnectID":"00000000-0000-0000-0000-000000000000","Email":"[email protected]","LastSeen":"2023-05-29T11:08:02.5031865Z","Name":"Daz Kuffs","SharedInstances":[{"ComputerName":"RAGE","InstanceID":"409f44f0-0542-49bc-bec5-47de2b59be48","InstanceName":"Ruffster","RemoteComputerID":"1a796a13-bd00-4a35-835e-648682a2601b","UserID":"7aaab6a9-fe93-47e9-a3d0-eb717389cf9a"}],"UserID":"7aaab6a9-fe93-47e9-a3d0-eb717389cf9a"}]}}},"ref":null,"topic":"realtime:11111111111111111111111111111111"}
29 May 2023 12:08:29 Presence Sync: Daz Kuffs on RAGE
29 May 2023 12:08:29 Presence Join: Daz Kuffs on RAGE
29 May 2023 12:08:29 Presence Leave: Daz Kuffs on RAGE

I notice that the Json for the Join Event apparently (with my limited knowledge) contains a reference to the Leave event in the : phx_ref_prev field.

Maybe some internal magic needs to check for this and not raise events when they cancel each other out. Personally, I feel that this should only have raised a Sync event and neither a Join or Leave.

Here is the Json for easier viewing.

{
"event": "presence_diff",
"payload":
    {
    "joins":
        {
        "145bacf8-fe11-11ed-9abb-6a2047d90b67":
            {
            "metas":
                [
                    {
                    "ComputerName": "RAGE",
                    "ConnectID": "00000000-0000-0000-0000-000000000000",
                    "Email": "[email protected]",
                    "LastSeen": "2023-05-29T11:08:29.1576795Z",
                    "Name": "Daz Kuffs",
                    "phx_ref": "F2OYoo6yrtA9v9zm",
                    "phx_ref_prev": "F2OYnFmge_Q9v3RI", ' MATCH '
                    "SharedInstances":
                        [
                            {
                            "ComputerName": "RAGE",
                            "InstanceID": "409f44f0-0542-49bc-bec5-47de2b59be48",
                            "InstanceName": "Ruffster",
                            "RemoteComputerID": "1a796a13-bd00-4a35-835e-648682a2601b",
                            "UserID": "7aaab6a9-fe93-47e9-a3d0-eb717389cf9a"
                            }
                        ],
                    "UserID": "7aaab6a9-fe93-47e9-a3d0-eb717389cf9a"
                    }
                ]
            }
        },
    "leaves":
        {
        "145bacf8-fe11-11ed-9abb-6a2047d90b67":
            {
            "metas":
                [
                    {
                    "ComputerName": "RAGE",
                    "ConnectID": "00000000-0000-0000-0000-000000000000",
                    "Email": "[email protected]",
                    "LastSeen": "2023-05-29T11:08:02.5031865Z",
                    "Name": "Daz Kuffs",
                    "phx_ref": "F2OYnFmge_Q9v3RI", ' MATCH '
                    "SharedInstances":
                        [
                            {
                            "ComputerName": "RAGE",
                            "InstanceID": "409f44f0-0542-49bc-bec5-47de2b59be48",
                            "InstanceName": "Ruffster",
                            "RemoteComputerID": "1a796a13-bd00-4a35-835e-648682a2601b",
                            "UserID": "7aaab6a9-fe93-47e9-a3d0-eb717389cf9a"
                            }
                        ],
                    "UserID": "7aaab6a9-fe93-47e9-a3d0-eb717389cf9a"
                    }
                ]
            }
        }
    },
"ref": null,
"topic": "realtime:11111111111111111111111111111111"
}

Originally posted by @Kuffs2205 in https://github.com/supabase-community/realtime-csharp/issues/29#issuecomment-1567024728

acupofjose avatar Jun 01 '23 03:06 acupofjose

I was about to open issue for this. I noticed the same behavior, I need to track user last seen down to 10 secs difference. When use track manually, it triggers leave event also. Lemme know if you found any solutions to this.

kaushalkumar86 avatar Jun 26 '25 10:06 kaushalkumar86