-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from SimerusM/rtc-changes
webrtc working
- Loading branch information
Showing
12 changed files
with
439 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,24 @@ | ||
from flask import jsonify, request | ||
from flask_socketio import emit, join_room | ||
import uuid | ||
|
||
def setup_chat_routes(app, session_storage, log_message): | ||
@app.route('/api/create-meeting', methods=['POST']) | ||
def create_meeting(): | ||
meeting_id = str(uuid.uuid4()) | ||
data = request.get_json() | ||
username = data['username'] | ||
session_storage[meeting_id] = { | ||
'host': username, | ||
'users': [], | ||
'chat_history': [] | ||
} | ||
log_message('INFO', f'User {username} created a new meeting', meeting_id) | ||
return jsonify({'meeting_id': meeting_id}) | ||
from flask_socketio import emit | ||
|
||
def setup_chat(app, socketio, session_storage, log_message): | ||
@app.route('/api/chat_history/<meeting_id>', methods=['GET']) | ||
def get_chat_history(meeting_id): | ||
if meeting_id in session_storage: | ||
return jsonify(session_storage[meeting_id]['chat_history']) | ||
else: | ||
return jsonify({'error': 'Meeting ID not found'}), 404 | ||
|
||
@app.route('/api/session/<meeting_id>', methods=['GET']) | ||
def get_users(meeting_id): | ||
if meeting_id in session_storage: | ||
return jsonify(session_storage[meeting_id]) | ||
else: | ||
if meeting_id not in session_storage: | ||
return jsonify({'error': 'Meeting ID not found'}), 404 | ||
|
||
def setup_chat_sockets(socketio, session_storage, log_message): | ||
@socketio.on('join') | ||
def handle_join(data): | ||
if 'username' not in data or 'meeting_id' not in data: | ||
log_message('ERROR', f'Join request missing username or meeting ID: {data}') | ||
return | ||
meeting_id = data['meeting_id'] | ||
username = data['username'] | ||
join_room(meeting_id) | ||
session = session_storage[meeting_id] | ||
session['users'].append(username) | ||
log_message('INFO', f'User {username} joined the meeting', meeting_id) | ||
emit('user_joined', {'username': username, 'meeting_id': meeting_id}, room=meeting_id) | ||
return jsonify(session_storage[meeting_id]['chat_history']) | ||
|
||
@socketio.on('chat_message') | ||
def handle_chat_message(data): | ||
meeting_id = data['meeting_id'] | ||
sender = data['sender'] | ||
message = data['text'] | ||
|
||
if meeting_id not in session_storage: | ||
log_message('ERROR', f'Meeting ID {meeting_id} not found', meeting_id) | ||
emit('error', {'message': 'Meeting ID not found'}, to=request.sid) | ||
return | ||
|
||
session_storage[meeting_id]['chat_history'].append({'sender': sender, 'text': message}) | ||
log_message('INFO', f'User {sender} sent: {message}', meeting_id) | ||
emit('chat_message', {'sender': sender, 'text': message}, room=meeting_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { io } from 'socket.io-client'; | ||
|
||
const socket = io('http://127.0.0.1:5000'); | ||
|
||
// Join a room with a specific meeting ID | ||
socket.emit('join', { 'username': 'teet', meeting_id: 'e45f73db-9973-4acd-9467-c48f56b26804' }); | ||
|
||
// Emit the SDP offer immediately | ||
socket.emit('offer', { meeting_id: 'e45f73db-9973-4acd-9467-c48f56b26804', sdp: '...' }); | ||
|
||
// Simulate receiving the offer and sending back an SDP answer after 1 second | ||
socket.emit('answer', { meeting_id: 'e45f73db-9973-4acd-9467-c48f56b26804', sdp: 'v=0\r\no=- 25678 753849 IN IP4 192.0.2.2\r\ns=-\r\nc=IN IP4 192.0.2.2\r\nt=0 0\r\na=recvonly\r\nm=video 49170 RTP/AVP 98\r\na=rtpmap:98 H264/90000\r\n' }); | ||
|
||
// Simulate sending ICE candidates after 2 seconds | ||
socket.emit('ice_candidate', { meeting_id: 'e45f73db-9973-4acd-9467-c48f56b2', candidate: 'candidate:842163049 1 udp 1677729535 192.0.2.1 3478 typ srflx raddr 192.0.2.1 rport 3478' }); | ||
|
||
// Listen for events | ||
socket.on('offer', (data) => console.log('Received offer:', data)); | ||
socket.on('answer', (data) => console.log('Received answer:', data)); | ||
socket.on('ice_candidate', (data) => console.log('Received ICE candidate:', data)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
from flask import request | ||
from flask_socketio import emit | ||
|
||
def setup_webrtc_sockets(socketio): | ||
def setup_webrtc(app, socketio, session_storage, log_message): | ||
@socketio.on('offer') | ||
def handle_offer(data): | ||
meeting_id = data['meeting_id'] | ||
emit('offer', data, room=meeting_id) | ||
to_sid = session_storage[data['meeting_id']]['users'][data['to']] | ||
log_message('INFO', f'User {data["from"]} sent an offer', data['meeting_id']) | ||
emit('offer', data, room=to_sid, skip_sid=request.sid) | ||
|
||
@socketio.on('answer') | ||
def handle_answer(data): | ||
meeting_id = data['meeting_id'] | ||
emit('answer', data, room=meeting_id) | ||
to_sid = session_storage[data['meeting_id']]['users'][data['to']] | ||
log_message('INFO', f'User {data["from"]} sent an answer', data['meeting_id']) | ||
emit('answer', data, room=to_sid, skip_sid=request.sid) | ||
|
||
@socketio.on('ice_candidate') | ||
def handle_ice_candidate(data): | ||
meeting_id = data['meeting_id'] | ||
emit('ice_candidate', data, room=meeting_id) | ||
to_sid = session_storage[data['meeting_id']]['users'][data['to']] | ||
emit('ice_candidate', data, room=to_sid, skip_sid=request.sid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.