kodenique-game-sdk 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -108,6 +108,15 @@ export function useWebRTC(options) {
108
108
  const buildWhepUrl = useCallback((streamUrl, serverUrl, streamName) => {
109
109
  if (streamUrl) {
110
110
  console.log("[useWebRTC] Original stream URL:", streamUrl);
111
+ // Extract protocol (http or https)
112
+ const protocolMatch = streamUrl.match(/^(https?):\/\//);
113
+ let protocol = protocolMatch ? protocolMatch[1] : "https"; // Default to https for security
114
+ // Force HTTPS if page is loaded over HTTPS (prevent mixed content)
115
+ if (typeof window !== 'undefined' && window.location.protocol === 'https:' && protocol === 'http') {
116
+ console.log("[useWebRTC] Page is HTTPS - upgrading stream URL to HTTPS");
117
+ protocol = 'https';
118
+ }
119
+ console.log("[useWebRTC] Protocol:", protocol);
111
120
  const urlMatch = streamUrl.match(/stream=([^&]+)/);
112
121
  const streamId = urlMatch ? urlMatch[1] : null;
113
122
  console.log("[useWebRTC] Extracted stream ID:", streamId);
@@ -115,15 +124,19 @@ export function useWebRTC(options) {
115
124
  const serverMatch = streamUrl.match(/\/\/([^:\/]+)/);
116
125
  const server = serverMatch ? serverMatch[1] : "stg-srs.wspo.club";
117
126
  console.log("[useWebRTC] Server:", server);
118
- const whepUrl = `http://${server}:1985/rtc/v1/whep/?app=live&stream=${streamId}`;
127
+ // Use determined protocol (forced to HTTPS if page is HTTPS)
128
+ const whepUrl = `${protocol}://${server}:1985/rtc/v1/whep/?app=live&stream=${streamId}`;
119
129
  console.log("[useWebRTC] Rebuilt clean URL:", whepUrl);
120
130
  return whepUrl;
121
131
  }
122
132
  else {
123
133
  let fixedUrl = streamUrl;
124
- if (fixedUrl.includes("https://")) {
125
- fixedUrl = fixedUrl.replace("https://", "http://");
134
+ // Force HTTPS if page is HTTPS
135
+ if (typeof window !== 'undefined' && window.location.protocol === 'https:' && fixedUrl.startsWith('http://')) {
136
+ console.log("[useWebRTC] Upgrading URL to HTTPS for mixed content");
137
+ fixedUrl = fixedUrl.replace('http://', 'https://');
126
138
  }
139
+ // Fix path if needed
127
140
  if (fixedUrl.includes(":1985/v1/whep/")) {
128
141
  fixedUrl = fixedUrl.replace(":1985/v1/whep/", ":1985/rtc/v1/whep/");
129
142
  }
@@ -135,7 +148,8 @@ export function useWebRTC(options) {
135
148
  }
136
149
  }
137
150
  else if (serverUrl && streamName) {
138
- const whepUrl = `http://${serverUrl}:1985/rtc/v1/whep/?app=live&stream=${streamName}`;
151
+ // For manual server/stream construction, use https by default
152
+ const whepUrl = `https://${serverUrl}:1985/rtc/v1/whep/?app=live&stream=${streamName}`;
139
153
  console.log("[useWebRTC] Constructed stream URL:", whepUrl);
140
154
  return whepUrl;
141
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kodenique-game-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "React SDK for real-time game streaming with WebSocket updates and WebRTC video player",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",