This repository has been archived by the owner on Nov 7, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(posts): initial live feed implementation (broadcasting)
- Loading branch information
1 parent
48e386d
commit 73ccb2a
Showing
17 changed files
with
403 additions
and
23 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
worker_processes 1; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
include mime.types; | ||
default_type application/octet-stream; | ||
|
||
keepalive_timeout 65; | ||
|
||
server { | ||
listen 8080; | ||
|
||
location / { | ||
proxy_pass https://zkillboard.com; | ||
} | ||
} | ||
} |
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,8 @@ | ||
vcl 4.0; | ||
|
||
# On Kuberentes is "localhost" | ||
# In Docker-Compose is "zkill-nginx" | ||
backend default { | ||
.host = "zkill-nginx"; | ||
.port = "8080"; | ||
} |
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
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
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,77 @@ | ||
import { EventsHandler, IEventHandler } from '@nestjs/cqrs'; | ||
import { | ||
CharacterPostedOnAllianceWallEvent, | ||
CharacterPostedOnCharacterWallEvent, CharacterPostedOnCorporationWallEvent, CharacterPostedEvent, | ||
} from '../create.character.event'; | ||
import { | ||
CorporationPostedOnCharacterWallEvent, | ||
CorporationPostedOnCorporationWallEvent, | ||
CorporationPostedOnAllianceWallEvent, | ||
CorporationPostedEvent, | ||
} from '../create.corporation.event'; | ||
import { | ||
AlliancePostedOnCharacterWallEvent, | ||
AlliancePostedOnCorporationWallEvent, | ||
AlliancePostedOnAllianceWallEvent, | ||
AlliancePostedEvent, | ||
} from '../create.alliance.event'; | ||
import { PostedEvent } from '../create.event'; | ||
import { WebsocketGateway } from '../../../websocket/websocket.gateway'; | ||
import { Character } from '../../../character/character.entity'; | ||
import { Corporation } from '../../../corporation/corporation.entity'; | ||
import { Alliance } from '../../../alliance/alliance.entity'; | ||
import { DPost } from '../../post.dto'; | ||
|
||
@EventsHandler( | ||
CharacterPostedEvent, | ||
CharacterPostedOnCharacterWallEvent, | ||
CharacterPostedOnCorporationWallEvent, | ||
CharacterPostedOnAllianceWallEvent, | ||
CorporationPostedEvent, | ||
CorporationPostedOnCharacterWallEvent, | ||
CorporationPostedOnCorporationWallEvent, | ||
CorporationPostedOnAllianceWallEvent, | ||
AlliancePostedEvent, | ||
AlliancePostedOnCharacterWallEvent, | ||
AlliancePostedOnCorporationWallEvent, | ||
AlliancePostedOnAllianceWallEvent, | ||
) | ||
export class AnyonePostedEventHandler implements IEventHandler<PostedEvent> { | ||
|
||
constructor( | ||
private websocketGateway: WebsocketGateway, | ||
) { | ||
} | ||
|
||
async handle(event: PostedEvent) { | ||
const post = new DPost(event.post); | ||
|
||
// Send event for hashtags | ||
for (const hashtag of event.post.hashtags) { | ||
await this.websocketGateway.sendEventToHashtagWallSub<DPost>(hashtag, post); | ||
} | ||
|
||
// First check if it was posted on wall | ||
// else check who posted it | ||
const sendTo = event.post.characterWall | ||
|| event.post.corporationWall | ||
|| event.post.allianceWall | ||
|| event.post.character | ||
|| event.post.corporation | ||
|| event.post.alliance; | ||
|
||
// and send it to correct wall | ||
if (sendTo instanceof Character) { | ||
await this.websocketGateway.sendEventToCharacterWallSub<DPost>(sendTo, post); | ||
} | ||
if (sendTo instanceof Corporation) { | ||
await this.websocketGateway.sendEventToCorporationWallSub<DPost>(sendTo, post); | ||
} | ||
if (sendTo instanceof Alliance) { | ||
await this.websocketGateway.sendEventToAllianceWallSub<DPost>(sendTo, post); | ||
} | ||
|
||
// Also send it to latest | ||
await this.websocketGateway.sendEventToLatestWallSub<DPost>(post); | ||
} | ||
} |
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,5 +1,7 @@ | ||
import { CharacterPostedOnWallEventHandler } from './create.character.wall.handler'; | ||
import { AnyonePostedEventHandler } from './create.handler'; | ||
|
||
export const eventHandlers = [ | ||
CharacterPostedOnWallEventHandler, | ||
AnyonePostedEventHandler, | ||
]; |
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 +1,39 @@ | ||
export const MAX_ROOMS_JOINED = 50; | ||
|
||
export const WS_EVENT_AUTHENTICATION = 'WS_EVENT_AUTHENTICATION'; | ||
export const WS_EVENT_SUBSCRIPTION = 'WS_EVENT_SUBSCRIPTION'; | ||
|
||
export const WS_NEW_SUBSCRIPTION_EVENT = 'WS_NEW_SUBSCRIPTION_EVENT'; | ||
|
||
// Subscribe (Initial requests) | ||
export enum WS_SUBSCRIBE_EVENTS { | ||
TO_LATEST_WALL = 'WS_EVENT_SUBSCRIBE_TO_LATEST_WALL', | ||
TO_HASHTAG_WALL = 'WS_EVENT_SUBSCRIBE_TO_HASHTAG_WALL', | ||
TO_CHARACTER_WALL = 'WS_EVENT_SUBSCRIBE_TO_CHARACTER_WALL', | ||
TO_CORPORATION_WALL = 'WS_EVENT_SUBSCRIBE_TO_CORPORATION_WALL', | ||
TO_ALLIANCE_WALL = 'WS_EVENT_SUBSCRIBE_TO_ALLIANCE_WALL', | ||
TO_POST_COMMENTS = 'WS_EVENT_SUBSCRIBE_TO_POST_COMMENTS', | ||
} | ||
|
||
export enum WS_SUBSCRIPTIONS { | ||
TO_LATEST_WALL = 'WS_EVENT_SUBSCRPTION_TO_LATEST_WALL', | ||
TO_HASHTAG_WALL = 'WS_EVENT_SUBSCRPTION_TO_HASHTAG_WALL', | ||
TO_CHARACTER_WALL = 'WS_EVENT_SUBSCRPTION_TO_CHARACTER_WALL', | ||
TO_CORPORATION_WALL = 'WS_EVENT_SUBSCRPTION_TO_CORPORATION_WALL', | ||
TO_ALLIANCE_WALL = 'WS_EVENT_SUBSCRPTION_TO_ALLIANCE_WALL', | ||
TO_POST_COMMENTS = 'WS_EVENT_SUBSCRPTION_TO_POST_COMMENTS', | ||
} | ||
|
||
export const WS_EVENT_UNSUBSCRIBE_TO_LATEST_WALL = 'WS_EVENT_UNSUBSCRIBE_TO_LATEST_WALL'; | ||
export const WS_EVENT_UNSUBSCRIBE_TO_HASHTAG_WALL = 'WS_EVENT_UNSUBSCRIBE_TO_HASHTAG_WALL'; | ||
export const WS_EVENT_UNSUBSCRIBE_TO_CHARACTER_WALL = 'WS_EVENT_UNSUBSCRIBE_TO_CHARACTER_WALL'; | ||
export const WS_EVENT_UNSUBSCRIBE_TO_CORPORATION_WALL = 'WS_EVENT_UNSUBSCRIBE_TO_CORPORATION_WALL'; | ||
export const WS_EVENT_UNSUBSCRIBE_TO_ALLIANCE_WALL = 'WS_EVENT_UNSUBSCRIBE_TO_ALLIANCE_WALL'; | ||
export const WS_EVENT_UNSUBSCRIBE_TO_POST_COMMENTS = 'WS_EVENT_UNSUBSCRIBE_TO_POST_COMMENTS'; | ||
|
||
export const getRoomForLatestWall = () => 'wall:latest'; | ||
export const getRoomForHashtagWall = (hashtag: string) => `wall:hashtag:${hashtag}`; | ||
export const getRoomForCharacterWall = (characterId: string) => `wall:character:${characterId}`; | ||
export const getRoomForCorporationWall = (corpId: string) => `wall:corporation:${corpId}`; | ||
export const getRoomForAllianceWall = (allianceId: string) => `wall:alliance:${allianceId}`; | ||
export const getRoomForPostComments = (postId: string) => `post:comments:${postId}`; |
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.