diff --git a/_examples/websocket/basic/browser/index.html b/_examples/websocket/basic/browser/index.html index e956b3ae..836ef223 100644 --- a/_examples/websocket/basic/browser/index.html +++ b/_examples/websocket/basic/browser/index.html @@ -17,6 +17,17 @@ var port = document.location.port ? ":" + document.location.port : ""; var wsURL = scheme + "://" + document.location.hostname + port + "/echo"; + const enableJWT = true; + if (enableJWT) { + // This is just a signature and a payload of an example content, + // please replace this with your logic. + // + // Add a random letter in front of the token to make it + // invalid and see that this client is not allowed to dial the websocket server. + const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjozMjEzMjF9.8waEX7-vPKACa-Soi1pQvW3Rl8QY-SUFcHKTLZI4mvU"; + wsURL += "?token=" + token; + } + var outputTxt = document.getElementById("output"); function addMessage(msg) { outputTxt.innerHTML += msg + "\n"; @@ -24,7 +35,7 @@ function handleError(reason) { console.log(reason); - window.alert(reason); + window.alert("error: see the dev console"); } function handleNamespaceConnectedConn(nsConn) { diff --git a/_examples/websocket/basic/browserify/app.js b/_examples/websocket/basic/browserify/app.js index f6f9f6b7..8acfb9c9 100644 --- a/_examples/websocket/basic/browserify/app.js +++ b/_examples/websocket/basic/browserify/app.js @@ -5,6 +5,17 @@ var port = document.location.port ? ":" + document.location.port : ""; var wsURL = scheme + "://" + document.location.hostname + port + "/echo"; +const enableJWT = true; +if (enableJWT) { + // This is just a signature and a payload of an example content, + // please replace this with your logic. + // + // Add a random letter in front of the token to make it + // invalid and see that this client is not allowed to dial the websocket server. + const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjozMjEzMjF9.8waEX7-vPKACa-Soi1pQvW3Rl8QY-SUFcHKTLZI4mvU"; + wsURL += "?token=" + token; +} + var outputTxt = document.getElementById("output"); function addMessage(msg) { diff --git a/_examples/websocket/basic/browserify/bundle.js b/_examples/websocket/basic/browserify/bundle.js index 80af6967..9530f82c 100644 --- a/_examples/websocket/basic/browserify/bundle.js +++ b/_examples/websocket/basic/browserify/bundle.js @@ -1 +1 @@ -(function(){function b(d,e,g){function a(j,i){if(!e[j]){if(!d[j]){var f="function"==typeof require&&require;if(!i&&f)return f(j,!0);if(h)return h(j,!0);var c=new Error("Cannot find module '"+j+"'");throw c.code="MODULE_NOT_FOUND",c}var k=e[j]={exports:{}};d[j][0].call(k.exports,function(b){var c=d[j][1][b];return a(c||b)},k,k.exports,b,d,e,g)}return e[j].exports}for(var h="function"==typeof require&&require,c=0;ci[0]&&c[1]=i)return k.close(),null;var c=new Map;k.connectedNamespaces.forEach(function(a,b){var d=[];!q(a.rooms)&&0i[0]&&c[1]