-
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.
* requirements: import flask-socketio * backend: socket io * add socket.io to angular * add socket-flask to requirment.txt. * add socket test code in angular * socket working * create routers folder * import other blueprint * move populate in backend folder * requirements: hotfix jwt vimalloc/flask-jwt-extended#557 * Revert "revert me: remove angular" This reverts commit 9072317. * docs: debug * app: add images --------- Co-authored-by: @ <@> Co-authored-by: Robin Burri <robinburri@tutanota.com>
- Loading branch information
1 parent
87c0111
commit aa3d880
Showing
17 changed files
with
175 additions
and
26 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
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,35 +1,73 @@ | ||
from os import environ | ||
|
||
from flask import Flask | ||
|
||
from flask_socketio import SocketIO | ||
from flask_cors import CORS | ||
from os import environ | ||
from flask_jwt_extended import JWTManager | ||
|
||
from flask_jwt_extended import ( | ||
JWTManager, | ||
) | ||
|
||
from matcha import users | ||
from matcha import auth | ||
from matcha import images | ||
from matcha import interests | ||
from matcha import pictures | ||
from matcha.routers import users | ||
from matcha.routers import auth | ||
from matcha.routers import interests | ||
from matcha.routers import pictures | ||
from matcha.routers import images | ||
|
||
|
||
def create_app(): | ||
app = Flask(__name__) | ||
|
||
app.config["JWT_SECRET_KEY"] = environ["FLASK_JWT_SECRET_KEY"] | ||
app.config["UPLOAD_FOLDER"] = environ["FLASK_UPLOAD_FOLDER"] | ||
app.config["URL"] = environ["FLASK_URL"] | ||
|
||
CORS(app, origins="http://localhost:4200") | ||
|
||
jwt = JWTManager(app) | ||
app.config["SECRET_KEY"] = "your_secret_key" | ||
|
||
app.register_blueprint(users.bp) | ||
app.register_blueprint(auth.bp) | ||
app.register_blueprint(images.bp) | ||
app.register_blueprint(interests.bp) | ||
app.register_blueprint(pictures.bp) | ||
app.register_blueprint(images.bp) | ||
|
||
CORS( | ||
app, | ||
resources={ | ||
r"/*": { | ||
"origins": ["http://localhost:4200"], | ||
"allow_credentials": True, | ||
"methods": ["GET", "POST", "DELETE", "PUT", "OPTIONS"], | ||
} | ||
}, | ||
) | ||
|
||
socketio = SocketIO( | ||
app, | ||
cors_allowed_origins="http://localhost:4200", | ||
async_mode="threading", | ||
ping_timeout=60000, | ||
logger=True, | ||
engineio_logger=True, | ||
) | ||
|
||
jwt = JWTManager(app) | ||
|
||
@socketio.on("connect") | ||
def handle_connect(): | ||
print("Client connected") | ||
|
||
@socketio.on("disconnect") | ||
def handle_disconnect(): | ||
print("Client disconnected") | ||
|
||
@socketio.on_error() | ||
def error_handler(e): | ||
print("SocketIO error:", str(e)) | ||
|
||
@socketio.on("message") | ||
def handle_message(data): | ||
try: | ||
print("Received message:", data) | ||
socketio.emit("response", "Server received your message: " + str(data)) | ||
except Exception as e: | ||
print("Error handling message:", str(e)) | ||
print("Error handling message:", str(e)) | ||
|
||
return app | ||
|
||
|
||
# Create a separate run file, say run.py in the backend directory |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,7 +1,10 @@ | ||
PyJWT==2.9.0 | ||
Flask==3.0.3 | ||
psycopg2-binary==2.9.9 | ||
flask-cors==5.0.0 | ||
flask-socketio==5.4.1 | ||
pylint==3.3.1 | ||
black==24.10.0 | ||
Flask-JWT-Extended==4.6.0 | ||
gunicorn==20.1.0 | ||
flask-socketio==5.4.1 |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
51 changes: 51 additions & 0 deletions
51
frontend/AngularApp/src/app/shared/services/socket.service.ts
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,51 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Socket, io } from 'socket.io-client'; | ||
import { Observable } from 'rxjs'; | ||
import { environment } from '../../../environments/environment'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class SocketService { | ||
private socket: Socket; | ||
|
||
constructor() { | ||
this.socket = io(environment.websocketUrl, { | ||
withCredentials: true, | ||
transports: ['websocket', 'polling'], | ||
autoConnect: true, | ||
}); | ||
|
||
// Connection event handlers | ||
this.socket.on('connect', () => { | ||
console.log('Connected to WebSocket server'); | ||
}); | ||
|
||
this.socket.on('connect_error', (error) => { | ||
console.error('WebSocket connection error:', error); | ||
}); | ||
|
||
this.socket.on('disconnect', (reason) => { | ||
console.log('Disconnected from WebSocket server:', reason); | ||
}); | ||
} | ||
|
||
sendMessage(message: string): void { | ||
console.log('Sending message:', message); | ||
this.socket.emit('message', message); | ||
} | ||
|
||
getResponse(): Observable<any> { | ||
return new Observable((observer) => { | ||
this.socket.on('response', (data) => { | ||
observer.next(data); | ||
}); | ||
}); | ||
} | ||
|
||
ngOnDestroy() { | ||
if (this.socket) { | ||
this.socket.disconnect(); | ||
} | ||
} | ||
} |
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,4 +1,5 @@ | ||
export const environment = { | ||
production: true, | ||
apiUrl: 'http://localhost/api', | ||
websocketUrl: 'http://localhost:5001', | ||
}; |
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,4 +1,5 @@ | ||
export const environment = { | ||
production: false, | ||
apiUrl: 'http://localhost:5001/api', | ||
websocketUrl: 'http://localhost:5001', | ||
}; |