diff --git a/basic/backend/java/src/main/java/io/openvidu/basic/java/Controller.java b/basic/backend/java/src/main/java/io/openvidu/basic/java/Controller.java index 6740b0d3..7e7e2661 100644 --- a/basic/backend/java/src/main/java/io/openvidu/basic/java/Controller.java +++ b/basic/backend/java/src/main/java/io/openvidu/basic/java/Controller.java @@ -25,13 +25,16 @@ public class Controller { * @param params JSON object with roomName and participantName * @return The JWT token */ - @PostMapping("/token") + @PostMapping( + value = "/token", + produces = "application/json" + ) public ResponseEntity getToken(@RequestBody Map params) { String roomName = params.get("roomName"); String participantName = params.get("participantName"); if (roomName == null || participantName == null) { - return ResponseEntity.badRequest().body("roomName and participantName are required"); + return ResponseEntity.badRequest().body("\"roomName and participantName are required\""); } AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET); @@ -39,7 +42,7 @@ public class Controller { token.setIdentity(participantName); token.addGrants(new RoomJoin(true), new RoomName(roomName)); - return ResponseEntity.ok(token.toJwt()); + return ResponseEntity.ok("\"" + token.toJwt() + "\""); } } diff --git a/basic/backend/node/index.js b/basic/backend/node/index.js index db377601..cf63a869 100644 --- a/basic/backend/node/index.js +++ b/basic/backend/node/index.js @@ -17,18 +17,18 @@ app.post("/token", async (req, res) => { const participantName = req.body.participantName; if (!roomName || !participantName) { - res.status(400).send("roomName and participantName are required"); + res.status(400).json("roomName and participantName are required"); return; } const at = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, { - identity: participantName, + identity: participantName }); at.addGrant({ roomJoin: true, room: roomName }); const token = await at.toJwt(); - res.send(token); + res.json(token); }); app.listen(SERVER_PORT, () => { - console.log("Application started on port: ", SERVER_PORT); + console.log("Server started on port:", SERVER_PORT); }); diff --git a/basic/backend/php/index.php b/basic/backend/php/index.php index b5388a8b..4277da45 100644 --- a/basic/backend/php/index.php +++ b/basic/backend/php/index.php @@ -1,5 +1,5 @@ setGrant($videoGrant) ->toJwt(); - echo $token; + echo json_encode($token); exit(); } -echo "Unsupported endpoint or method"; +echo json_encode("Unsupported endpoint or method"); exit(); diff --git a/basic/backend/python/app.py b/basic/backend/python/app.py index e757746d..64f385d8 100644 --- a/basic/backend/python/app.py +++ b/basic/backend/python/app.py @@ -1,5 +1,5 @@ import os -from flask import Flask, request +from flask import Flask, request, jsonify from flask_cors import CORS from dotenv import load_dotenv from livekit import api @@ -20,7 +20,7 @@ def getToken(): participant_name = request.json.get("participantName") if not room_name or not participant_name: - return "roomName and participantName are required", 400 + return jsonify("roomName and participantName are required"), 400 token = api.AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET) \ .with_identity(participant_name) \ @@ -28,7 +28,7 @@ def getToken(): room_join=True, room=room_name )) - return token.to_jwt() + return jsonify(token.to_jwt()) if __name__ == "__main__": app.run(debug=True, host="0.0.0.0", port=SERVER_PORT) diff --git a/basic/backend/ruby/app.rb b/basic/backend/ruby/app.rb index 554ba527..e2c24fa0 100644 --- a/basic/backend/ruby/app.rb +++ b/basic/backend/ruby/app.rb @@ -1,11 +1,11 @@ -require 'sinatra' -require 'sinatra/cors' -require 'livekit' -require './env.rb' +require "sinatra" +require "sinatra/cors" +require "livekit" +require "./env.rb" -SERVER_PORT = ENV['SERVER_PORT'] || 6080 -LIVEKIT_API_KEY = ENV['LIVEKIT_API_KEY'] || 'devkey' -LIVEKIT_API_SECRET = ENV['LIVEKIT_API_SECRET'] || 'secret' +SERVER_PORT = ENV["SERVER_PORT"] || 6080 +LIVEKIT_API_KEY = ENV["LIVEKIT_API_KEY"] || "devkey" +LIVEKIT_API_SECRET = ENV["LIVEKIT_API_SECRET"] || "secret" set :port, SERVER_PORT @@ -14,21 +14,21 @@ set :allow_origin, "*" set :allow_methods, "POST,OPTIONS" set :allow_headers, "content-type" -post '/token' do +post "/token" do content_type :json body = JSON.parse(request.body.read) - room_name = body['roomName'] - participant_name = body['participantName'] + room_name = body["roomName"] + participant_name = body["participantName"] if room_name.nil? || participant_name.nil? status 400 - return 'roomName and participantName are required' + return JSON.generate("roomName and participantName are required") end token = LiveKit::AccessToken.new(api_key: LIVEKIT_API_KEY, api_secret: LIVEKIT_API_SECRET) token.identity = participant_name token.add_grant(roomJoin: true, room: room_name) - return token.to_jwt + return JSON.generate(token.to_jwt) end