diff --git a/app/mobile/src/context/useAppContext.hook.js b/app/mobile/src/context/useAppContext.hook.js index d02e6fc7..abbdfaa6 100644 --- a/app/mobile/src/context/useAppContext.hook.js +++ b/app/mobile/src/context/useAppContext.hook.js @@ -192,7 +192,9 @@ export function useAppContext() { } const setWebsocket = (session) => { - ws.current = createWebsocket(`wss://${session.server}/status?mode=ring`); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(session.server); + const protocol = insecure ? 'ws' : 'wss'; + ws.current = createWebsocket(`${protocol}://${session.server}/status?mode=ring`); ws.current.onmessage = (ev) => { if (ev.data == '') { actions.logout(); diff --git a/app/mobile/src/context/useRingContext.hook.js b/app/mobile/src/context/useRingContext.hook.js index 442c5168..59e98bf7 100644 --- a/app/mobile/src/context/useRingContext.hook.js +++ b/app/mobile/src/context/useRingContext.hook.js @@ -239,7 +239,9 @@ export function useRingContext() { videoTrack.current = false; audioTrack.current = false; - ws.current = createWebsocket(`wss://${node}/signal`); + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(node); + const protocol = insecure ? 'ws' : 'wss'; + ws.current = createWebsocket(`${protocol}://${node}/signal`); ws.current.onmessage = async (ev) => { // handle messages [impolite] try { diff --git a/app/mobile/src/context/useUploadContext.hook.js b/app/mobile/src/context/useUploadContext.hook.js index 48ccb551..dfc2c7e0 100644 --- a/app/mobile/src/context/useUploadContext.hook.js +++ b/app/mobile/src/context/useUploadContext.hook.js @@ -66,11 +66,13 @@ export function useUploadContext() { const actions = { addTopic: (node, token, channelId, topicId, files, success, failure, cardId) => { + const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(node); + const protocol = insecure ? 'http' : 'https'; const key = cardId ? `${cardId}:${channelId}` : `:${channelId}`; const controller = new AbortController(); const entry = { index: index.current, - baseUrl: cardId ? `https://${node}/content/channels/${channelId}/topics/${topicId}/` : `https://${node}/content/channels/${channelId}/topics/${topicId}/`, + baseUrl: cardId ? `${protocol}://${node}/content/channels/${channelId}/topics/${topicId}/` : `${protocol}://${node}/content/channels/${channelId}/topics/${topicId}/`, urlParams: cardId ? `?contact=${token}` : `?agent=${token}`, files, assets: [],