Skip to content

Commit

Permalink
Merge pull request #137 from CS3219-AY2425S1/c-fix
Browse files Browse the repository at this point in the history
add annotation to k8 session service  to accept http
  • Loading branch information
simbayippy authored Nov 5, 2024
2 parents 858a37e + 8859878 commit 4795988
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 2 additions & 0 deletions k8s/session-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ apiVersion: v1
kind: Service
metadata:
name: session-svc
annotations:
cloud.google.com/app-protocols: '{"websocket":"HTTP", "audio":"HTTP"}'
spec:
type: LoadBalancer
ports:
Expand Down
24 changes: 13 additions & 11 deletions session-service/src/audio-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ interface AudioData {
}

const app = express();
app.use(cors({
origin: '*',
methods: ['GET', 'POST'],
credentials: true,
}));
app.use(
cors({
origin: "*",
methods: ["GET", "POST"],
credentials: true,
})
);

const httpServer = createServer(app);
const io = new Server(httpServer, {
cors: {
origin: "*",
methods: ["GET", "POST"],
credentials: true,
allowedHeaders: ["*"]
allowedHeaders: ["*"],
},
path: "/socket.io/",
transports: ["websocket"],
Expand All @@ -33,7 +35,7 @@ const io = new Server(httpServer, {

// Add connection error handling
io.engine.on("connection_error", (err) => {
console.log('Connection error:', err);
console.log("Connection error:", err);
});

io.on("connection", (socket: Socket) => {
Expand All @@ -45,7 +47,7 @@ io.on("connection", (socket: Socket) => {

// Handle signaling data for WebRTC connections
socket.on("signal", (signalData) => {
console.log('Received signal data, broadcasting to others');
console.log("Received signal data, broadcasting to others");
socket.broadcast.emit("signal", signalData);
});

Expand All @@ -54,11 +56,11 @@ io.on("connection", (socket: Socket) => {
});
});

app.get('/health', (req, res) => {
res.send('Server is running');
app.get("/health", (req, res) => {
res.send("Server is running");
});

const PORT = process.env.AUDIO_PORT || 5555;
httpServer.listen(PORT, () => {
console.log(`Audio service is running on port ${PORT}`);
});
});
2 changes: 1 addition & 1 deletion session-service/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const setupWSConnection = require("y-websocket/bin/utils").setupWSConnection;
export const allowedOrigins = ["*"];

/**
* Server INITIALIZATION and CONFIGURATION
* Server INITIALIZATION and CONFIGURATION.
* CORS configuration
* Request body parsing
*/
Expand Down

0 comments on commit 4795988

Please sign in to comment.