-
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.
Browse files
Browse the repository at this point in the history
…roxy-Controller-for-Server #27 Add Proxy Client
- Loading branch information
Showing
13 changed files
with
136 additions
and
51 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,3 @@ | ||
[submodule "scylla-server/src/odyssey-base"] | ||
path = scylla-server/src/odyssey-base | ||
url = https://github.com/Northeastern-Electric-Racing/Odyssey-Base.git |
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,2 +1,3 @@ | ||
src/prisma/mydatabase.db | ||
src/prisma/mydatabase.db-journal | ||
src/prisma/mydatabase.db-journal | ||
src/odyssey-base |
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 |
---|---|---|
|
@@ -11,10 +11,17 @@ RUN npm install | |
|
||
COPY . . | ||
|
||
# Initialize for git submodules | ||
RUN git init | ||
RUN git submodule add -f https://github.com/Northeastern-Electric-Racing/Odyssey-Base.git ./src/odyssey-base && \ | ||
git submodule update --init --recursive | ||
|
||
RUN npx [email protected] generate | ||
|
||
RUN npx [email protected] migrate deploy | ||
|
||
RUN npm i --save-dev @types/ws | ||
|
||
RUN npm run build | ||
|
||
CMD ["sh", "-c", "npm run start:production"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Submodule odyssey-base
added at
31f3e5
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,97 @@ | ||
// Ignoring this because it wont build on github for some reason | ||
// @ts-ignore | ||
import { ErrorEvent, Event, MessageEvent, WebSocket } from 'ws'; | ||
import { ServerMessage, SubscriptionMessage } from '../odyssey-base/src/types/message.types'; | ||
import { Topic } from '../odyssey-base/src/types/topic'; | ||
|
||
/** | ||
* Handler for receiving messages from Siren | ||
*/ | ||
export default class ProxyClient { | ||
socket: WebSocket; | ||
|
||
/** | ||
* Constructor | ||
* @param socket The socket to send and receive messages from | ||
*/ | ||
constructor(socket: WebSocket) { | ||
this.socket = socket; | ||
} | ||
|
||
/** | ||
* Sends a subscription message to Siren | ||
* @param topics The topics to subscribe to | ||
*/ | ||
private subscribeToTopics = (topics: Topic[]) => { | ||
const subscriptionMessage: SubscriptionMessage = { | ||
argument: 'subscribe', | ||
topics | ||
}; | ||
this.socket.send(JSON.stringify(subscriptionMessage)); | ||
}; | ||
|
||
/** | ||
* Handles disconnecting from Siren | ||
* @param event The event that triggered the close | ||
*/ | ||
private handleClose = (event: Event) => { | ||
console.log('Disconnected from Siren', event); | ||
}; | ||
|
||
/** | ||
* Handles connecting to Siren | ||
* @param event The event that triggered the open | ||
*/ | ||
private handleOpen = (event: Event) => { | ||
console.log('Connected to Siren', event); | ||
this.subscribeToTopics(Object.values(Topic)); | ||
}; | ||
|
||
/** | ||
* Handles messages received from Siren | ||
* @param message The message received from Siren | ||
*/ | ||
private handleMessage = (message: MessageEvent) => { | ||
console.log('Received Message: ', message); | ||
try { | ||
const data = JSON.parse(message.data.toString()) as ServerMessage; | ||
this.handleData(data); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
console.log('Error Decoding Message: ', error.message); | ||
this.socket.emit('Error', error.message); | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Handles receiving data from the car and: | ||
* 1. Logs the data | ||
* 2. Sends the data to the client | ||
* @param data The data received from Siren | ||
*/ | ||
private handleData = (data: ServerMessage) => { | ||
//TODO: Send data to client | ||
//TODO: Log data | ||
console.log('Received Data: ', data); | ||
}; | ||
|
||
/** | ||
* Handles errors that occur | ||
* @param error The error that occurred | ||
*/ | ||
private handleError = (error: ErrorEvent) => { | ||
console.log('Error Encountered: ', error.message); | ||
}; | ||
|
||
/** | ||
* Configures the proxy client for connecting and disconnecting to/from Siren, | ||
* sending and receiving messages, and handling errors | ||
*/ | ||
public configure = () => { | ||
this.socket.onopen = this.handleOpen; | ||
this.socket.onmessage = this.handleMessage; | ||
this.socket.onerror = this.handleError; | ||
this.socket.onclose = this.handleClose; | ||
}; | ||
} |
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