-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
81 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
Websocket API Protocol | ||
|
||
=== Objects === | ||
|
||
""" | ||
ObjectName { | ||
requiredProp: type | ||
optionalProp: type? | ||
} | ||
""" | ||
|
||
Location { | ||
lat: float, | ||
lon: float, | ||
geohash: string? (generated if not provided) | ||
} | ||
|
||
Message { | ||
author: string, | ||
content: { | ||
text?: string, | ||
attachment?: string, | ||
}, | ||
location: Location, | ||
replyTo?: string, | ||
reactions: { | ||
[key: string]: int, | ||
} | ||
} | ||
|
||
UserProfile { | ||
displayName: string, | ||
profilePicture: int, | ||
} | ||
|
||
=== | ||
|
||
=== Client -> Server Methods === | ||
|
||
""" | ||
methodName( | ||
arguments / inputs... | ||
) ack -> ackResponse | ||
""" | ||
|
||
// Must be called at least once before calling any other methods | ||
updateLocation( | ||
location: Location | ||
ack: func? | ||
) ack -> "success" | ||
|
||
sendMessage( | ||
message: Message | ||
ack: func? | ||
) ack -> "success" | ||
|
||
getNearbyUsers( | ||
callback: func(nearbyUserUids: { [uid: string]: UserProfile }) -> _, | ||
) callback -> map of nearby user uids to user profiles | ||
|
||
// Call after the client has already updated their profile document in firestore | ||
notifyUpdateProfile( | ||
ack: func? | ||
) ack -> "success" | ||
|
||
|
||
=== |
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,3 +1,7 @@ | ||
import { initializeApp } from "firebase-admin/app"; | ||
import { startSocketServer } from "./socket_server/socket_server" | ||
|
||
// Must be called from google environment (Cloud Run, App Engine, and Cloud Functions) | ||
initializeApp(); | ||
|
||
startSocketServer(); |
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,24 +1,21 @@ | ||
import { ActiveUser } from "../../types"; | ||
import { ActiveUser, UserProfile } from "../../types"; | ||
import { getActiveUsersInView } from "../regions"; | ||
import { ConnectionContext } from "../socket_server"; | ||
|
||
const filterOutSenderAndConvertToProfiles = function* (ctx: ConnectionContext, activeUsers: Generator<ActiveUser, any, any>): Generator<any, any, any> { | ||
for (const activeUser of activeUsers) { | ||
if (activeUser.uid === ctx.user.uid) continue; | ||
yield { | ||
uid: activeUser.uid, | ||
profile: activeUser.profile, | ||
}; | ||
yield { uid: activeUser.profile } | ||
} | ||
} | ||
|
||
export const getNearbyUsers = (ctx: ConnectionContext, callback: (nearbyUserUids: string[]) => void): void => { | ||
export const getNearbyUsers = (ctx: ConnectionContext, callback: (nearbyUserUids: { [uid: string]: UserProfile }) => void): void => { | ||
// Get all users in view | ||
const usersInView = getActiveUsersInView(ctx.user.location); | ||
|
||
// Filter out user who send this request and convert ActiveUser objects to uids | ||
const others = filterOutSenderAndConvertToProfiles(ctx, usersInView); | ||
|
||
// Response to the sender (also convert generator to array) | ||
callback([...others]); | ||
callback(Object.assign([...others])); | ||
} |
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,14 +1,4 @@ | ||
export interface UserProfile { | ||
displayName: string, | ||
profilePicture: number, | ||
} | ||
|
||
// [ | ||
// { | ||
// uid: "uid", | ||
// profile: { | ||
// displayName: "Name", | ||
// profilePicture: 2, | ||
// } | ||
// } | ||
// ] | ||
} |