1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 18:37:05 +00:00

Add the new websocket package (which is just a helper for kataras/neffos) and an example for go server, client, browser client and nodejs client. Add a .fossa.yml and the generated NOTICE file for 3rd-party libs. Update go.mod, go.sum. Update the vendor folder for pongo2 to its latest master as well

Former-commit-id: 89c05079415977d65e7328a1eb8a1c602d76f78a
This commit is contained in:
Gerasimos (Makis) Maropoulos
2019-06-02 17:49:45 +03:00
parent 8d388fb1c6
commit 04bc21dd3b
35 changed files with 661 additions and 2897 deletions

View File

@@ -0,0 +1,11 @@
# Browserify example
```sh
$ npm install --only=dev # install browserify from the devDependencies.
$ npm run-script build # browserify and minify the `app.js` into `bundle.js`.
$ cd ../ && go run server.go # start the neffos server.
```
> make sure that you have [golang](https://golang.org/dl) installed to run and edit the neffos (server-side).
That's all, now navigate to <http://localhost:8080/browserify>.

View File

@@ -0,0 +1,61 @@
const neffos = require('neffos.js');
var scheme = document.location.protocol == "https:" ? "wss" : "ws";
var port = document.location.port ? ":" + document.location.port : "";
var wsURL = scheme + "://" + document.location.hostname + port + "/echo";
var outputTxt = document.getElementById("output");
function addMessage(msg) {
outputTxt.innerHTML += msg + "\n";
}
function handleError(reason) {
console.log(reason);
window.alert(reason);
}
function handleNamespaceConnectedConn(nsConn) {
const inputTxt = document.getElementById("input");
const sendBtn = document.getElementById("sendBtn");
sendBtn.disabled = false;
sendBtn.onclick = function () {
const input = inputTxt.value;
inputTxt.value = "";
nsConn.emit("chat", input);
addMessage("Me: " + input);
};
}
async function runExample() {
try {
const conn = await neffos.dial(wsURL, {
default: { // "default" namespace.
_OnNamespaceConnected: function (nsConn, msg) {
addMessage("connected to namespace: " + msg.Namespace);
handleNamespaceConnectedConn(nsConn);
},
_OnNamespaceDisconnect: function (nsConn, msg) {
addMessage("disconnected from namespace: " + msg.Namespace);
},
chat: function (nsConn, msg) { // "chat" event.
addMessage(msg.Body);
}
}
});
// You can either wait to conenct or just conn.connect("connect")
// and put the `handleNamespaceConnectedConn` inside `_OnNamespaceConnected` callback instead.
// const nsConn = await conn.connect("default");
// handleNamespaceConnectedConn(nsConn);
conn.connect("default");
} catch (err) {
handleError(err);
}
}
runExample();

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,10 @@
<!-- the message's input -->
<input id="input" type="text" />
<!-- when clicked then a websocket event will be sent to the server, at this example we registered the 'chat' -->
<button id="sendBtn" disabled>Send</button>
<!-- the messages will be shown here -->
<pre id="output"></pre>
<script src="./bundle.js"></script>

View File

@@ -0,0 +1,16 @@
{
"name": "neffos.js.example.browserify",
"version": "0.0.1",
"scripts": {
"browserify": "browserify ./app.js -o ./bundle.js",
"minifyES6": "minify ./bundle.js --outFile ./bundle.js",
"build": "npm run-script browserify && npm run-script minifyES6"
},
"dependencies": {
"neffos.js": "latest"
},
"devDependencies": {
"browserify": "^16.2.3",
"babel-minify": "^0.5.0"
}
}