-
Notifications
You must be signed in to change notification settings - Fork 1
Models
The circle makes use of 3 different types of entities for both the TrueYou web app and the backend server.
The database stores these as follows:
Person: A person is a user of the application. A person can be both a transparent person (streamer) or a viewer on the TrueYou app. Every Person has a name. This can be a username or someones full name, as long as the name is shorter than 121 characters. The public key is used to maintain the persons integrity and is stored in the database. When a user streams they can make money in cryptocurrency form. The satochi value represents the amount of money they have made from live streaming. A person can be followed by other people. The followed list stores the Persons followers.
const PersonSchema = new Schema<IPerson>({
name: {
type: String,
max: 120,
required: [true, "Name is required"],
},
publicKey: {
type: String,
required: [true, "PublicKey is required"],
},
satochi: {
type: Number,
required: [true, "Satochi is required"],
},
followed: {
type: [RoomModel.schema],
},
});
export const PersonModel = model<IPerson>("person", PersonSchema);
Room: A room is the location a person livestreams to. A room has a streamer which is a referenced person. The room has a title which will be displayed on the browse page of the TrueYou app. If a streamer stops streaming the isLive value will be set to false. When a streamer starts again the value will go back to true. The purpose of the isLive value is to filter out streams that are offline so only rooms that are live are displayed on TrueYou. Every room has a viewer count that frequently updates. The "viewers" value represents the current amount of people that are watching a room.
const RoomSchema = new Schema<IRoom>({
streamer: {
type: Schema.Types.ObjectId,
ref: "person",
required: [true, "Person is required"],
},
title: {
type: String,
max: 120,
required: [true, "Title is required"],
},
isLive: {
type: Boolean,
required: [true, "IsLive is required"],
},
viewers: {
type: Number,
required: [true, "viewers is required"],
},
});
export const RoomModel = model<IRoom>("room", RoomSchema);
Chat: A chat object is a message sent by a person. The person who sent the message is referenced in the chat object. The chat itself contains a message which can not be longer than 120 characters. Apart from these values a chat message contains a dateTime object with a date and a signature for integrity. When someone sends a message it should end up in the chatbox of a certain livestream. The room is referenced in every chat object.
const ChatSchema = new Schema<IChatMessage>({
person: {
type: Schema.Types.ObjectId,
ref: "person",
required: [true, "Person is required"],
},
room: {
type: Schema.Types.ObjectId,
ref: "room",
required: [true, "Room is required"],
},
message: {
type: String,
max: 120,
required: [true, "Message is required"],
},
dateTime: {
type: Date,
required: [true, "DateTime is required"],
},
signature: {
type: String,
required: [true, "Hash is required"],
},
});
export const ChatModel = model<IChatMessage>("chat", ChatSchema);
The application landscape contains 3 different apps: the Android stream app, the TruYou web app and the server.
the TruYou app and server both make use of libs
which is a directory containing resources that can be used in different apps.
The libs
directory contains all the models and interfaces. The TruYou web app makes use of these models primarily for sending the data in the correct format to the server. This way the data is consistent in both the web app and *backend server. There are interfaces for each model, this is because the schemas in the backend can't use a class but need an interface.
*schemas are located in the backend.
The relation of the models with each application can be shown here:
The Android app is written in Java, therefor the libs folder can't be used. To get around this the model is simply rewritten in Java to prevent inconsistency. Because the streaming app has different use cases not all models have been rewritten as they would serve no purpose. There are some changes made to the models as seen below.
Auth:
The Auth model contains similar information to the Person model but also contains the roomId. This is done to direct the stream to the correct room.
public class AuthClass {
private String username;
private int personId;
private int roomId;
private String privateKey;
private String publicKey;
public AuthClass(String username, int personId, int roomId, String privateKey, String publicKey) {
this.username = username;
this.personId = personId;
this.roomId = roomId;
this.privateKey = privateKey;
this.publicKey = publicKey;
}
}
Message:
The Message model is basically identical to the Chat model.
public class MessageClass {
private int id;
private Date timestamp;
private AuthClass user;
private String message;
public MessageClass(int id, Date timestamp, AuthClass userName, String message) {
this.id = id;
this.timestamp = timestamp;
this.user = userName;
this.message = message;
}
}
The other models are not of any use in the android app. Its purpose is to send the streaming data over.