-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from stzups/temp
v0.3.4 Bugfixes, improve db creation, improve exceptions, overhaul config
- Loading branch information
Showing
91 changed files
with
1,012 additions
and
557 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM postgres | ||
COPY init.sql /docker-entrypoint-initdb.d/ |
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,43 @@ | ||
CREATE DATABASE board; | ||
|
||
-- Connect to board database (currently on default postgres database) | ||
\c board | ||
REVOKE CONNECT ON DATABASE board FROM PUBLIC; | ||
REVOKE ALL ON SCHEMA public FROM PUBLIC; | ||
|
||
CREATE USER board_room PASSWORD 'changeme'; | ||
GRANT CONNECT ON DATABASE board TO board_room; | ||
GRANT USAGE ON SCHEMA public TO board_room; | ||
|
||
-- Create tables and grant permissions | ||
CREATE TABLE users( | ||
id bigint NOT NULL, | ||
owned_documents bigint[] NOT NULL, | ||
shared_documents bigint[] NOT NULL, | ||
PRIMARY KEY (id) | ||
); | ||
GRANT SELECT, INSERT, UPDATE ON users TO board_room; | ||
|
||
CREATE TABLE documents( | ||
id bigint NOT NULL, | ||
owner bigint NOT NULL, | ||
name varchar(64) not null, | ||
PRIMARY KEY (id) | ||
); | ||
GRANT SELECT, INSERT, UPDATE, DELETE ON documents TO board_room; | ||
|
||
CREATE TABLE canvases( | ||
document bigint NOT NULL, | ||
data bytea NOT NULL, | ||
PRIMARY KEY (document) | ||
); | ||
GRANT SELECT, INSERT, UPDATE, DELETE ON canvases TO board_room; | ||
|
||
CREATE TABLE persistent_user_sessions( | ||
id bigint NOT NULL, | ||
"user" bigint NOT NULL, | ||
creation_time timestamp, | ||
hashed_token bytea NOT NULL, | ||
PRIMARY KEY (id) | ||
); | ||
GRANT SELECT, INSERT, DELETE ON persistent_user_sessions TO board_room; |
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,5 @@ | ||
let SocketEventType; | ||
export default SocketEventType = { | ||
OPEN:0, | ||
CLOSE:1, | ||
}; |
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,90 @@ | ||
import BufferReader from './BufferReader.js' | ||
import BufferWriter from "./BufferWriter.js"; | ||
import ServerMessageType from "./server/ServerMessageType.js"; | ||
import SocketEventType from "./SocketEventType.js"; | ||
import {getServerMessage} from "./server/ServerMessageType.js"; | ||
|
||
const HTTP_PORT = 8080; | ||
const HTTPS_PORT = 443; | ||
|
||
class WebSocketHandler { | ||
constructor() { | ||
this.socketEvents = {}; | ||
Object.keys(SocketEventType).forEach((key, value) => { | ||
this.socketEvents[value] = []; | ||
}); | ||
|
||
this.serverMessageEvents = {}; | ||
Object.keys(ServerMessageType).forEach((key, value) => { | ||
this.serverMessageEvents[value] = []; | ||
}); | ||
|
||
let webSocketUrl; | ||
if (window.location.protocol === 'https:') { | ||
webSocketUrl = 'wss://localhost:' + HTTPS_PORT + '/websocket'; | ||
} else { | ||
console.warn('Insecure connection, this better be a development environment');//todo disable/disallow | ||
webSocketUrl = 'ws://localhost:' + HTTP_PORT + '/websocket'; | ||
} | ||
console.log('Opening WebSocket connection to ' + webSocketUrl); | ||
this.socket = new WebSocket(webSocketUrl); | ||
this.socket.binaryType = 'arraybuffer'; | ||
|
||
this.socket.addEventListener('open', (event) => { | ||
console.log('WebSocket connection opened'); | ||
this.dispatchEvent(SocketEventType.OPEN); | ||
}); | ||
|
||
this.socket.addEventListener('close', (event) => { | ||
console.log('WebSocket connection closed'); | ||
this.dispatchEvent(SocketEventType.CLOSE); | ||
}); | ||
|
||
this.socket.addEventListener('message', (event) => { | ||
console.warn('recv'); | ||
if (typeof event.data === 'string') { | ||
console.log(event.data); | ||
} else { | ||
let reader = new BufferReader(event.data); | ||
while (reader.hasNext()) { | ||
this.dispatchMessageEvent(getServerMessage(reader.readUint8(), reader)); | ||
} | ||
} | ||
}); | ||
|
||
this.socket.addEventListener('error', (event) => { | ||
console.error('socket error', event); | ||
}); | ||
} | ||
|
||
addEventListener(socketEventType, onSocketEvent) { | ||
this.socketEvents[socketEventType].push(onSocketEvent); | ||
} | ||
|
||
dispatchEvent(socketEventType, socketEvent) { | ||
console.log('recv', socketEventType, socketEvent); | ||
this.socketEvents[socketEventType].forEach(onSocketEvent => onSocketEvent(socketEvent)); | ||
} | ||
|
||
addMessageListener(serverMessageType, onServerMessage) { | ||
this.serverMessageEvents[serverMessageType].push(onServerMessage); | ||
} | ||
|
||
dispatchMessageEvent(serverMessage) { | ||
console.log('recv', serverMessage.type, serverMessage); | ||
this.serverMessageEvents[serverMessage.type].forEach(onServerMessage => onServerMessage(serverMessage)); | ||
} | ||
|
||
send(message) { | ||
if (this.socket.readyState === WebSocket.OPEN) { | ||
console.log('send', message); | ||
let writer = new BufferWriter(message.getBufferSize()); | ||
message.serialize(writer); | ||
this.socket.send(writer.getBuffer()); | ||
} else { | ||
console.error('tried to send message while websocket was closed', message); | ||
} | ||
} | ||
} | ||
|
||
export default new WebSocketHandler(); |
File renamed without changes.
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
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
board-frontend/html/scripts/protocol/client/messages/ClientMessageDeleteDocument.js
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,18 @@ | ||
import ClientMessageType from "../ClientMessageType.js"; | ||
import ClientMessage from "../ClientMessage.js"; | ||
|
||
export default class ClientMessageDeleteDocument extends ClientMessage { | ||
constructor(document) { | ||
super(ClientMessageType.DELETE_DOCUMENT); | ||
this.id = document.id; | ||
} | ||
|
||
getBufferSize() { | ||
return super.getBufferSize() + 8; | ||
} | ||
|
||
serialize(writer) { | ||
super.serialize(writer); | ||
writer.writeBigInt64(this.id); | ||
} | ||
} |
File renamed without changes.
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
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
board-frontend/html/scripts/protocol/client/messages/ClientMessageUpdateDocument.js
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,19 @@ | ||
import ClientMessageType from "../ClientMessageType.js"; | ||
import ClientMessage from "../ClientMessage.js"; | ||
|
||
export default class ClientMessageUpdateDocument extends ClientMessage { | ||
constructor(document) { | ||
super(ClientMessageType.UPDATE_DOCUMENT); | ||
this.id = document.id; | ||
this.name = document.name; | ||
} | ||
|
||
getBufferSize() { | ||
return super.getBufferSize() + 8; | ||
} | ||
|
||
serialize(writer) { | ||
super.serialize(writer); | ||
writer.writeBigInt64(this.id); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ export default class ServerMessage { | |
constructor(type) { | ||
this.type = type; | ||
} | ||
} | ||
} |
Oops, something went wrong.