diff options
author | Jakob Stendahl <14180120+JakobST1n@users.noreply.github.com> | 2021-10-11 20:02:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-11 20:02:04 +0200 |
commit | c67531161e56488166a33232f87566309ba8676e (patch) | |
tree | 846e59a020e80bea48557d5a06af5728e44961ff /docs/Code Documentation/SocketIO.md | |
parent | e6880cd8ccf82d993f222cb14b4860581654acb8 (diff) | |
parent | c1b6eec770b885a9829e1f62bad5cc99389ca429 (diff) | |
download | Luxcena-Neo-c67531161e56488166a33232f87566309ba8676e.tar.gz Luxcena-Neo-c67531161e56488166a33232f87566309ba8676e.zip |
Merge pull request #24 from JakobST1n/rebuild
v1.0.0
Diffstat (limited to 'docs/Code Documentation/SocketIO.md')
-rw-r--r-- | docs/Code Documentation/SocketIO.md | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/docs/Code Documentation/SocketIO.md b/docs/Code Documentation/SocketIO.md new file mode 100644 index 0000000..b605857 --- /dev/null +++ b/docs/Code Documentation/SocketIO.md @@ -0,0 +1,116 @@ +# SocketIO + +## Client +Socketio is setup in the file `globals`. +This means, import `globals`, and then you can use `Socket` from there. + +### Connect +1. Client first needs to get an Authentication token, + this can be obtained by doing this: + ```javascript + import {setCookie} from "../../../cookies"; + let CryptoJS = require("crypto-js"); + let passwordHash = CryptoJS.SHA256(<PASSWORD>;).toString(); + + Socket.emit("authenticate", <USERNAME>, passwordHash, (token) => { + // Token will be a string if username/password combo is right, + // if not, it is false. + setCookie("session_token", token, 500); + };) + ``` +2. Then the user can authenticate like this: + ```javascript + import {getCookie} from "../../../cookies"; + let cookieToken = getCookie("session_token"); + + Socket.emit("authenticateToken", cookieToken, (res) => { + // Res is true if we got authenticated, + // If not, it is false. + }); + ``` +3. We are now authenticated, and all actions and events are available to the client. + +### "Actions" +```javascript +Socket.emit(Action, *Arguments, (Return) => { +};) +``` + +##### NeoRuntime/status + + +| Name | Type | Description | +| ------ | ------ | ----------- | +| status | object | | + +??? info "Return/status" + + | Name | Type | Description | + | -------------- | ------- | ----------------------------- | + | currentScript | string | "None"/Name of current script | + | scriptIsExited | boolean | | + | uptime | number | | + +##### NeoRuntime/Script/Create + +??? info "Arguments" + + | Name | Type | Description | + | ---------- | ------ | ------------------------------------- | + | scriptPath | string | Path of the new script, local/example | + +??? info "Return" + + | Name | Type | Description | + | ------ | ------- | --------------------- | + | res | boolean | success | + | resMsg | string | if fail, errorMessage | + + +##### NeoRuntime/Script/Delete + +??? info "Arguments" + + | Name | Type | Description | + | ---------- | ------ | ------------------------------------------- | + | scriptPath | string | Path of the script to delete, local/example | + +??? info "Return" + + | Name | Type | Description | + | ------ | ------- | --------------------- | + | res | boolean | success | + | resMsg | string | if fail, errorMessage | + +##### NeoRuntime/Script/Select + +??? info "Arguments" + + | Name | Type | Description | + | ---------- | ------ | ------------------------------------------ | + | scriptPath | string | Path of the script to start, local/example | + +##### NeoRuntime/Scripts/get + +??? info "Return" + + | Name | Type | Description | + | ------ | ------- | --------------------- | + | local | list | local scripts | + | remote | list | remote scripts | + +### "Events" +```javascript +// Listen for a event +Socket.emit(event + "::join"); +Socket.on(event, (*Return); => { + +}) +``` +```javascript +// Stop listening for an event +Socket.emit(event + "::leave") +``` + + +## Server |