Drop public client IDs for simplicity
This commit is contained in:
24
main.go
24
main.go
@@ -22,14 +22,14 @@ import (
|
|||||||
type activeRequest struct {
|
type activeRequest struct {
|
||||||
RoomId string `json:"room_id"`
|
RoomId string `json:"room_id"`
|
||||||
AdminSecret string `json:"admin_secret"`
|
AdminSecret string `json:"admin_secret"`
|
||||||
PublicClientId string `json:"public_client_id"`
|
ClientId string `json:"client_id"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type adminRequest struct {
|
type adminRequest struct {
|
||||||
RoomId string `json:"room_id"`
|
RoomId string `json:"room_id"`
|
||||||
AdminSecret string `json:"admin_secret"`
|
AdminSecret string `json:"admin_secret"`
|
||||||
PublicClientId string `json:"public_client_id"`
|
ClientId string `json:"client_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type resetRequest struct {
|
type resetRequest struct {
|
||||||
@@ -61,13 +61,12 @@ type removeRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type client struct {
|
type client struct {
|
||||||
PublicClientId string `json:"public_client_id"`
|
ClientId string `json:"client_id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Admin bool `json:"admin"`
|
Admin bool `json:"admin"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
ActiveStart int64 `json:"active_start"`
|
ActiveStart int64 `json:"active_start"`
|
||||||
|
|
||||||
clientId string
|
|
||||||
room *room
|
room *room
|
||||||
lastSeen time.Time
|
lastSeen time.Time
|
||||||
eventChan chan *event
|
eventChan chan *event
|
||||||
@@ -98,7 +97,6 @@ type room struct {
|
|||||||
roomId string
|
roomId string
|
||||||
timerStart time.Time
|
timerStart time.Time
|
||||||
clientById map[string]*client
|
clientById map[string]*client
|
||||||
clientByPublicId map[string]*client
|
|
||||||
present map[*presentState]bool
|
present map[*presentState]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,9 +217,9 @@ func active(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c := rm.clientByPublicId[req.PublicClientId]
|
c := rm.clientById[req.ClientId]
|
||||||
if c == nil {
|
if c == nil {
|
||||||
http.Error(w, "invalid public_client_id", http.StatusBadRequest)
|
http.Error(w, "invalid client_id", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,9 +254,9 @@ func admin(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c := rm.clientByPublicId[req.PublicClientId]
|
c := rm.clientById[req.ClientId]
|
||||||
if c == nil {
|
if c == nil {
|
||||||
http.Error(w, "invalid public_client_id", http.StatusBadRequest)
|
http.Error(w, "invalid client_id", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,8 +460,7 @@ func (c *client) sendEvent(e *event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) remove() {
|
func (c *client) remove() {
|
||||||
delete(c.room.clientById, c.clientId)
|
delete(c.room.clientById, c.ClientId)
|
||||||
delete(c.room.clientByPublicId, c.PublicClientId)
|
|
||||||
|
|
||||||
c.room.sendAdminEvent(&adminEvent{
|
c.room.sendAdminEvent(&adminEvent{
|
||||||
Client: c,
|
Client: c,
|
||||||
@@ -490,7 +487,6 @@ func newRoom(roomId string) *room {
|
|||||||
roomId: roomId,
|
roomId: roomId,
|
||||||
timerStart: time.Now(),
|
timerStart: time.Now(),
|
||||||
clientById: map[string]*client{},
|
clientById: map[string]*client{},
|
||||||
clientByPublicId: map[string]*client{},
|
|
||||||
present: map[*presentState]bool{},
|
present: map[*presentState]bool{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -513,12 +509,10 @@ func (rm *room) getClient(clientId string) *client {
|
|||||||
c := rm.clientById[clientId]
|
c := rm.clientById[clientId]
|
||||||
if c == nil {
|
if c == nil {
|
||||||
c = &client{
|
c = &client{
|
||||||
clientId: clientId,
|
ClientId: clientId,
|
||||||
PublicClientId: uuid.New().String(),
|
|
||||||
room: rm,
|
room: rm,
|
||||||
}
|
}
|
||||||
rm.clientById[clientId] = c
|
rm.clientById[clientId] = c
|
||||||
rm.clientByPublicId[c.PublicClientId] = c
|
|
||||||
|
|
||||||
rm.sendAdminEvent(&adminEvent{
|
rm.sendAdminEvent(&adminEvent{
|
||||||
Client: c,
|
Client: c,
|
||||||
|
|||||||
@@ -178,10 +178,10 @@ function renderAdmin(roomId, adminSecret, prnt, es) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const client = event.admin_event.client;
|
const client = event.admin_event.client;
|
||||||
let row = rows.get(client.public_client_id);
|
let row = rows.get(client.client_id);
|
||||||
if (row) {
|
if (row) {
|
||||||
row.remove();
|
row.remove();
|
||||||
rows.delete(client.public_client_id);
|
rows.delete(client.client_id);
|
||||||
}
|
}
|
||||||
if (event.admin_event.remove) {
|
if (event.admin_event.remove) {
|
||||||
return;
|
return;
|
||||||
@@ -206,14 +206,14 @@ function renderAdmin(roomId, adminSecret, prnt, es) {
|
|||||||
if (!confirm(`Grant admin access to ${client.name}?`)) {
|
if (!confirm(`Grant admin access to ${client.name}?`)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
admin(roomId, adminSecret, client.public_client_id);
|
admin(roomId, adminSecret, client.client_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const activeCell = create(row, "td", "👆", client.active ? ["active", "enable"] : ["active"]);
|
const activeCell = create(row, "td", "👆", client.active ? ["active", "enable"] : ["active"]);
|
||||||
activeCell.addEventListener("click", () => {
|
activeCell.addEventListener("click", () => {
|
||||||
active(roomId, adminSecret, client.public_client_id, !activeCell.classList.contains("enable"));
|
active(roomId, adminSecret, client.client_id, !activeCell.classList.contains("enable"));
|
||||||
});
|
});
|
||||||
rows.set(client.public_client_id, row);
|
rows.set(client.client_id, row);
|
||||||
});
|
});
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
@@ -227,11 +227,11 @@ function renderAdmin(roomId, adminSecret, prnt, es) {
|
|||||||
}
|
}
|
||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
function active(roomId, adminSecret, publicClientId, val) {
|
function active(roomId, adminSecret, clientId, val) {
|
||||||
const req = {
|
const req = {
|
||||||
room_id: roomId,
|
room_id: roomId,
|
||||||
admin_secret: adminSecret,
|
admin_secret: adminSecret,
|
||||||
public_client_id: publicClientId,
|
client_id: clientId,
|
||||||
active: val,
|
active: val,
|
||||||
};
|
};
|
||||||
fetch("api/active", {
|
fetch("api/active", {
|
||||||
@@ -242,11 +242,11 @@ function active(roomId, adminSecret, publicClientId, val) {
|
|||||||
body: JSON.stringify(req),
|
body: JSON.stringify(req),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function admin(roomId, adminSecret, publicClientId) {
|
function admin(roomId, adminSecret, clientId) {
|
||||||
const req = {
|
const req = {
|
||||||
room_id: roomId,
|
room_id: roomId,
|
||||||
admin_secret: adminSecret,
|
admin_secret: adminSecret,
|
||||||
public_client_id: publicClientId,
|
client_id: clientId,
|
||||||
};
|
};
|
||||||
fetch("api/admin", {
|
fetch("api/admin", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
interface ActiveRequest {
|
interface ActiveRequest {
|
||||||
room_id: string;
|
room_id: string;
|
||||||
admin_secret: string;
|
admin_secret: string;
|
||||||
public_client_id: string;
|
client_id: string;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AdminRequest {
|
interface AdminRequest {
|
||||||
room_id: string;
|
room_id: string;
|
||||||
admin_secret: string;
|
admin_secret: string;
|
||||||
public_client_id: string;
|
client_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AnnounceRequest {
|
interface AnnounceRequest {
|
||||||
@@ -57,7 +57,7 @@ interface AdminEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface Client {
|
interface Client {
|
||||||
public_client_id: string;
|
client_id: string;
|
||||||
name: string;
|
name: string;
|
||||||
admin: boolean;
|
admin: boolean;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
@@ -285,11 +285,11 @@ function renderAdmin(roomId: string, adminSecret: string, prnt: HTMLElement, es:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const client = event.admin_event.client;
|
const client = event.admin_event.client;
|
||||||
let row = rows.get(client.public_client_id);
|
let row = rows.get(client.client_id);
|
||||||
|
|
||||||
if (row) {
|
if (row) {
|
||||||
row.remove();
|
row.remove();
|
||||||
rows.delete(client.public_client_id);
|
rows.delete(client.client_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.admin_event.remove) {
|
if (event.admin_event.remove) {
|
||||||
@@ -319,16 +319,16 @@ function renderAdmin(roomId: string, adminSecret: string, prnt: HTMLElement, es:
|
|||||||
if (!confirm(`Grant admin access to ${client.name}?`)) {
|
if (!confirm(`Grant admin access to ${client.name}?`)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
admin(roomId, adminSecret, client.public_client_id);
|
admin(roomId, adminSecret, client.client_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const activeCell = create(row, "td", "👆", client.active ? ["active", "enable"] : ["active"]) as HTMLTableCellElement;
|
const activeCell = create(row, "td", "👆", client.active ? ["active", "enable"] : ["active"]) as HTMLTableCellElement;
|
||||||
activeCell.addEventListener("click", () => {
|
activeCell.addEventListener("click", () => {
|
||||||
active(roomId, adminSecret, client.public_client_id, !activeCell.classList.contains("enable"));
|
active(roomId, adminSecret, client.client_id, !activeCell.classList.contains("enable"));
|
||||||
});
|
});
|
||||||
|
|
||||||
rows.set(client.public_client_id, row);
|
rows.set(client.client_id, row);
|
||||||
});
|
});
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
@@ -345,11 +345,11 @@ function renderAdmin(roomId: string, adminSecret: string, prnt: HTMLElement, es:
|
|||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
|
|
||||||
function active(roomId: string, adminSecret: string, publicClientId: string, val: boolean) {
|
function active(roomId: string, adminSecret: string, clientId: string, val: boolean) {
|
||||||
const req: ActiveRequest = {
|
const req: ActiveRequest = {
|
||||||
room_id: roomId,
|
room_id: roomId,
|
||||||
admin_secret: adminSecret,
|
admin_secret: adminSecret,
|
||||||
public_client_id: publicClientId,
|
client_id: clientId,
|
||||||
active: val,
|
active: val,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -362,11 +362,11 @@ function active(roomId: string, adminSecret: string, publicClientId: string, val
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function admin(roomId: string, adminSecret: string, publicClientId: string) {
|
function admin(roomId: string, adminSecret: string, clientId: string) {
|
||||||
const req: AdminRequest = {
|
const req: AdminRequest = {
|
||||||
room_id: roomId,
|
room_id: roomId,
|
||||||
admin_secret: adminSecret,
|
admin_secret: adminSecret,
|
||||||
public_client_id: publicClientId,
|
client_id: clientId,
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch("api/admin", {
|
fetch("api/admin", {
|
||||||
|
|||||||
Reference in New Issue
Block a user