Skip to content
Snippets Groups Projects
Commit 4aa0c47c authored by Ronnie Friman's avatar Ronnie Friman
Browse files

added socket-notifs

parent 01da9d6f
No related branches found
No related tags found
3 merge requests!59Development to master,!36Development,!33Small fixes
......@@ -149,7 +149,9 @@ export class GameService {
updatedGame.state = game.state;
await this.gameRepository.save(updatedGame);
// notify players about game state change
this.notificationGateway.server.emit(game.id, 'event update');
this.notificationGateway.server.emit(game.id, {
type: 'gamestate-update',
});
return {
code: 200,
message: 'State was updated',
......@@ -217,7 +219,7 @@ export class GameService {
});
await this.objectivePoint_HistoryRepository.insert(eventUpdate);
// send flagbox event to flagbox subscribers
this.notificationGateway.server.emit('flagbox', 'event update');
this.notificationGateway.server.emit(gameId, { type: 'flagbox-event' });
return {
code: 201,
message: 'OK',
......
......@@ -10,7 +10,7 @@ import {
GameEntity,
} from '../game/game.entity';
import { ScoreEntity } from './score.entity';
import { map } from 'rxjs/operators';
import { NotificationGateway } from '../notifications/notifications.gateway';
@Injectable()
export class ScoreService {
......@@ -23,6 +23,7 @@ export class ScoreService {
private flagHistoryRepository: Repository<ObjectivePoint_HistoryEntity>,
@InjectRepository(FactionEntity)
private factionRepository: Repository<FactionEntity>,
private notificationGateway: NotificationGateway,
) {}
async addScore(scoreData: ScoreDTO, gameId: GameEntity) {
......@@ -80,6 +81,7 @@ export class ScoreService {
scoreData.map(async data => {
await this.addScore(data, gameId);
});
this.notificationGateway.server.emit(gameId, { type: 'score-update' });
return {
code: 200,
message: 'Scores added',
......
......@@ -36,8 +36,8 @@ export class TaskService {
// notify subscribers about a new task
// if faction was set it notifies only faction members, else everyone
this.notificationGateway.server.emit(
task.faction != null ? task.faction.toString() : 'global',
'new task',
task.faction != null ? task.faction.toString() : task.taskGame.toString(),
{ type: 'task-update' },
);
return {
code: 201,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment