diff --git a/packages/mobile-client/package.json b/packages/mobile-client/package.json index a1169c63..39d852de 100644 --- a/packages/mobile-client/package.json +++ b/packages/mobile-client/package.json @@ -5,9 +5,8 @@ "license": "Apache-2.0", "author": "Fishjam Team", "main": "./dist/index.js", - "module": "./dist/index.js", "types": "./dist/index.d.ts", - "react-native": "src/index.ts", + "react-native": "dist/index.js", "files": [ "dist/**", "plugin/build/**", @@ -25,29 +24,23 @@ "webrtc", "fishjam" ], - "exports": { - ".": { - "import": "./dist/index.js", - "types": "./dist/index.d.ts" - }, - "./app.plugin": "./app.plugin.js", - "./app.plugin.js": "./app.plugin.js", - "./package.json": "./package.json" - }, "scripts": { "build": "tsc && EXPO_NONINTERACTIVE=1 expo-module build plugin", "lint": "eslint . --ext .ts,.tsx --fix", "prepare": "tsc && EXPO_NONINTERACTIVE=1 expo-module build plugin" }, "peerDependencies": { + "@fishjam-cloud/react-native-webrtc": "0.25.0", "expo": "*", "react": "*", - "react-native": "*" + "react-native": "*", + "react-native-get-random-values": "1.11.0" }, "dependencies": { "@fishjam-cloud/react-client": "workspace:*", "@fishjam-cloud/react-native-webrtc": "0.25.0", - "react-native-get-random-values": "^1.11.0" + "fast-text-encoding": "^1.0.6", + "react-native-get-random-values": "1.11.0" }, "devDependencies": { "eslint-config-expo": "~9.2.0", diff --git a/packages/mobile-client/src/webrtc-polyfill.ts b/packages/mobile-client/src/webrtc-polyfill.ts index b18d33a0..4310fada 100644 --- a/packages/mobile-client/src/webrtc-polyfill.ts +++ b/packages/mobile-client/src/webrtc-polyfill.ts @@ -1,3 +1,4 @@ +import 'fast-text-encoding'; import 'react-native-get-random-values'; import { registerGlobals } from '@fishjam-cloud/react-native-webrtc'; diff --git a/packages/react-client/src/utils/fishjamUrl.ts b/packages/react-client/src/utils/fishjamUrl.ts index e4428aee..8291aa88 100644 --- a/packages/react-client/src/utils/fishjamUrl.ts +++ b/packages/react-client/src/utils/fishjamUrl.ts @@ -1,11 +1,10 @@ type LivestreamKind = "whip" | "whep"; export function resolveFishjamUrl(fishjamId: string): string { - try { + if (/^https?:\/\//.test(fishjamId)) { return new URL(fishjamId).href; - } catch { - return `https://fishjam.io/api/v1/connect/${fishjamId}`; } + return `https://fishjam.io/api/v1/connect/${fishjamId}`; } export function httpToWebsocketUrl(url: string): string { diff --git a/packages/ts-client/src/livestream.ts b/packages/ts-client/src/livestream.ts index a94fdcf6..a00ab1dc 100644 --- a/packages/ts-client/src/livestream.ts +++ b/packages/ts-client/src/livestream.ts @@ -1,6 +1,3 @@ -import { WHEPClient } from '@binbat/whip-whep/whep'; -import { WHIPClient } from '@binbat/whip-whep/whip'; - export type ReceiveLivestreamResult = { stream: MediaStream; stop: () => Promise; @@ -21,13 +18,14 @@ export type LivestreamCallbacks = { onConnectionStateChange?: (pc: RTCPeerConnection) => void; }; -export function receiveLivestream(url: string, token?: string, callbacks?: LivestreamCallbacks) { +export async function receiveLivestream(url: string, token?: string, callbacks?: LivestreamCallbacks) { const pc = new RTCPeerConnection({ bundlePolicy: 'max-bundle' }); pc.addTransceiver('video', { direction: 'recvonly' }); pc.addTransceiver('audio', { direction: 'recvonly' }); pc.onconnectionstatechange = (_ev) => callbacks?.onConnectionStateChange?.(pc); + const { WHEPClient } = await import('@binbat/whip-whep/whep'); const whep = new WHEPClient(); return new Promise((resolve, reject) => { @@ -77,6 +75,7 @@ export async function publishLivestream( if (video) pc.addTransceiver(video, { direction: 'sendonly' }); if (audio) pc.addTransceiver(audio, { direction: 'sendonly' }); + const { WHIPClient } = await import('@binbat/whip-whep/whip'); const whip = new WHIPClient(); try { await whip.publish(pc, url, token); diff --git a/yarn.lock b/yarn.lock index 8e78d6c2..bf799f1a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3868,11 +3868,14 @@ __metadata: eslint-config-expo: "npm:~9.2.0" eslint-plugin-prettier: "npm:^5.5.1" expo-module-scripts: "npm:^5.0.7" - react-native-get-random-values: "npm:^1.11.0" + fast-text-encoding: "npm:^1.0.6" + react-native-get-random-values: "npm:1.11.0" peerDependencies: + "@fishjam-cloud/react-native-webrtc": 0.25.0 expo: "*" react: "*" react-native: "*" + react-native-get-random-values: 1.11.0 languageName: unknown linkType: soft @@ -11865,6 +11868,13 @@ __metadata: languageName: node linkType: hard +"fast-text-encoding@npm:^1.0.6": + version: 1.0.6 + resolution: "fast-text-encoding@npm:1.0.6" + checksum: 10c0/e1d0381bda229c92c7906f63308f3b9caca8c78b732768b1ee16f560089ed21bc159bbe1434138ccd3815931ec8d4785bdade1ad1c45accfdf27ac6606ac67d2 + languageName: node + linkType: hard + "fastq@npm:^1.6.0": version: 1.19.1 resolution: "fastq@npm:1.19.1" @@ -16729,7 +16739,7 @@ __metadata: languageName: node linkType: hard -"react-native-get-random-values@npm:^1.11.0": +"react-native-get-random-values@npm:1.11.0": version: 1.11.0 resolution: "react-native-get-random-values@npm:1.11.0" dependencies: