fivem icon indicating copy to clipboard operation
fivem copied to clipboard

add(citizen-scripting-core): WebSocket support

Open cqmpact opened this issue 3 weeks ago • 4 comments

Goal of this PR

This PR introduces WebSocket support to the Cfx.re framework by implementing native socket functionality and exposing it through scripting APIs. This enables resource developers to create real-time bidirectional communication channels with external services.

How is this PR achieving the goal

This PR achieves the goal through two main changes:

  1. Core WebSocket Implementation (feat(scripting-core): websockets): Implements the underlying WebSocket functionality in the scripting core, providing the foundational infrastructure for socket connections.

  2. Native Declarations (add(native-decls): socket declarations): Adds the native declarations/bindings that expose the WebSocket functionality to scripting runtimes, making the feature accessible to resource developers across different scripting languages.

This PR applies to the following area(s)

  • FiveM
  • RedM
  • LibertyM
  • Server
  • Natives
  • ScRT: Lua
  • ScRT: C#
  • ScRT: JS

Successfully tested on

Game builds: b3258

Platforms: Windows

Checklist

  • [x] Code compiles and has been tested successfully.
  • [x] Code explains itself well and/or is documented.
  • [x] My commit message explains what the changes do and what they are for.
  • [ ] No extra compilation warnings are added by these changes.

Example

local socketId = SocketConnect("ws://localhost:8080", function(eventType, data)
    print("WebSocket event: " .. eventType)
    if eventType == "message" then
        print("Received: " .. data)
    elseif eventType == "error" then
        print("Error: " .. data)
    end
end)

if socketId > 0 then
    print("WebSocket connected with ID: " .. socketId)
    SocketSend(socketId, "Hello, Server!")
else
    print("Failed to connect to WebSocket server.")
end

Success: image

Fail: image

cqmpact avatar Dec 04 '25 13:12 cqmpact

Thanks for your work on this change! Unfortunately, we’re currently in a feature freeze for FiveM, so we’re unable to merge any changes that modify or extend our APIs at this time.

radium-cfx avatar Dec 04 '25 13:12 radium-cfx

Thanks for your work on this change! Unfortunately, we’re currently in a feature freeze for FiveM, so we’re unable to merge any changes that modify or extend our APIs at this time.

No problem, and that's really unfortunate to hear. I hope that the freeze doesn't last too long! Thanks for the feedback.

cqmpact avatar Dec 04 '25 13:12 cqmpact

Aint gonna be mean but if we are in a feature freeze why aren't the issues being fixed? On another note this is an amazing feature that should be in cfx by default! Good work!

SSnowly avatar Dec 04 '25 14:12 SSnowly

Probably to reduce stuff they need to migrate to a new platform ;)

lLukDreams avatar Dec 04 '25 15:12 lLukDreams