-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
70 lines (57 loc) · 1.83 KB
/
Copy pathapp.js
File metadata and controls
70 lines (57 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* @description Main application module configuration
* Initializes the Angular application with required dependencies and HTTP interceptor setup
*/
/**
* @type {Object}
* @description Angular module instance for the main application
* @requires ui.router - For client-side routing
* @requires ui.bootstrap - For Bootstrap UI components
*/
const myApp = angular.module('myApp', [
'ui.router', // Handles client-side routing
'ui.bootstrap' // Bootstrap UI components
]);
/**
* @description Configure HTTP interceptors for the application
* Sets up the AuthInterceptor to handle authentication for all HTTP requests
*/
myApp.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('AuthInterceptor');
}]);
// add hrere
myApp.controller('MainController', ['$scope', 'AuthService', 'ToastService',
function($scope, AuthService, ToastService) {
let socket = null;
let currentUser = null;
const initSocket = function(user) {
if (!socket) {
socket = io("https://ezycar-hosted-1.onrender.com");
currentUser = user;
socket.emit('joinUserRoom', user._id);
// Listen for new bid notifications
socket.on('newBid', function(data) {
// Only show notification if it's for the current user
if (data.userId === currentUser._id) {
ToastService.success(data.message || 'Bid placed successfully!', 3000);
}
});
// Handle connection error
socket.on('connect_error', function(error) {
console.error('Socket connection error:', error);
});
}
};
// Initialize on app start
$scope.init = function() {
AuthService.userProfile().then((user) => {
if (user) {
initSocket(user);
}
})
.catch((error) => {
console.log("Please login");
});
};
$scope.init();
}]);