Skip to content

Commit 8efb91d

Browse files
authored
Merge pull request #219 from scribear/https-support
Automatically select secure/not secure protocols
2 parents 25972ee + 66b1abb commit 8efb91d

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/components/navbars/topbar/apiDropdown.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export default function ApiDropdown(props) {
3737
const serverAddress = urlParams.get('serverAddress');
3838
const accessToken = urlParams.get('accessToken');
3939
const sourceToken = urlParams.get('sourceToken');
40+
const wsProtocol = window.isSecureContext ? 'wss' : 'ws';
41+
const httpProtocol = window.isSecureContext ? 'https' : 'http';
4042

4143
// Automatically use scribear server as sink when in student mode or as sourcesink if in kiosk mode
4244
useEffect(() => {
@@ -63,10 +65,10 @@ export default function ApiDropdown(props) {
6365
}
6466

6567
if (mode === 'kiosk') {
66-
switchToScribeARServer(`ws://${kioskServerAddress}/api/sourcesink`, undefined);
68+
switchToScribeARServer(`${wsProtocol}://${kioskServerAddress}/api/sourcesink`, undefined);
6769
} else if (mode === 'student') {
6870
console.log("Sending startSession POST with accessToken:", accessToken);
69-
fetch(`http://${serverAddress}/api/startSession`, {
71+
fetch(`${httpProtocol}://${serverAddress}/api/startSession`, {
7072
method: 'POST',
7173
headers: {
7274
'Content-Type': 'application/json'
@@ -77,7 +79,7 @@ export default function ApiDropdown(props) {
7779
.then(data => {
7880
console.log('Session token:', data.sessionToken);
7981

80-
const scribearServerAddress = `ws://${serverAddress}/api/sink`;
82+
const scribearServerAddress = `${wsProtocol}://${serverAddress}/api/sink`;
8183

8284
switchToScribeARServer(scribearServerAddress, data.sessionToken);
8385
})
@@ -148,3 +150,4 @@ export default function ApiDropdown(props) {
148150
</React.Fragment>
149151
);
150152
}
153+

src/components/navbars/topbar/qrCodeScreen.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default function QRCodeComponent() {
1616
const isStudentMode = urlParams.get('mode') === 'student';
1717
const scribearURLParam = urlParams.get('scribearURL');
1818
const sourceToken = urlParams.get('sourceToken');
19+
const httpProtocol = window.isSecureContext ? 'https' : 'http';
1920

2021
useEffect(() => {
2122
if (!isKioskMode) return;
@@ -29,7 +30,7 @@ export default function QRCodeComponent() {
2930

3031
let updateAccessTokenTimeout;
3132
function updateAccessToken() {
32-
fetch(`${kioskServerAddress}/api/accessToken`, {
33+
fetch(`${httpProtocol}://${kioskServerAddress}/api/accessToken`, {
3334
method: 'POST',
3435
headers: {
3536
'Content-Type': 'application/json'

0 commit comments

Comments
 (0)