Skip to content

Commit be361a4

Browse files
Add mechanism to route into the right instance
1 parent 7acbbed commit be361a4

File tree

7 files changed

+142
-22
lines changed

7 files changed

+142
-22
lines changed

example/package-lock.json

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"eslint": "^8.19.0",
3838
"jest": "^29.6.3",
3939
"prettier": "2.8.8",
40+
"react-native-url-polyfill": "^2.0.0",
4041
"react-test-renderer": "18.3.1",
4142
"typescript": "5.0.4"
4243
},

example/src/Play.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ export default function App() {
3939
break;
4040
case 'play_finished':
4141
console.log('play_finished');
42-
42+
4343
setIsPlaying(false);
4444
setRemoteStream('');
4545
break;
46-
case "newStreamAvailable":
46+
case "newStreamAvailable":
4747
if(data.streamId == streamNameRef.current)
4848
setRemoteStream(data.stream.toURL());
4949
break;
@@ -63,6 +63,7 @@ export default function App() {
6363
],
6464
},
6565
debug: true,
66+
playMode: true,
6667
});
6768

6869

example/yarn.lock

+23-2
Original file line numberDiff line numberDiff line change
@@ -2547,7 +2547,7 @@ buffer-from@^1.0.0:
25472547
resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz"
25482548
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==
25492549

2550-
buffer@^5.5.0:
2550+
buffer@^5.4.3, buffer@^5.5.0:
25512551
version "5.7.1"
25522552
resolved "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz"
25532553
integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==
@@ -5696,7 +5696,7 @@ prop-types@^15.7.2, prop-types@^15.8.1:
56965696
object-assign "^4.1.1"
56975697
react-is "^16.13.1"
56985698

5699-
punycode@^2.1.0:
5699+
punycode@^2.1.0, punycode@^2.1.1:
57005700
version "2.3.1"
57015701
resolved "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz"
57025702
integrity sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==
@@ -5761,6 +5761,13 @@ react-native-incall-manager@^4.2.0:
57615761
resolved "https://registry.npmjs.org/react-native-incall-manager/-/react-native-incall-manager-4.2.0.tgz"
57625762
integrity sha512-DC5XRQVAwNgNA6YZ3ILF6ttWXv/MUQ4omzmVDh/uHc0TW0v4f8QIdt6D9GHZhGKb3+qB7XKUxpXVBrLH+9zqfQ==
57635763

5764+
react-native-url-polyfill@^2.0.0:
5765+
version "2.0.0"
5766+
resolved "https://registry.npmjs.org/react-native-url-polyfill/-/react-native-url-polyfill-2.0.0.tgz"
5767+
integrity sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA==
5768+
dependencies:
5769+
whatwg-url-without-unicode "8.0.0-3"
5770+
57645771
react-native-vector-icons@^10.1.0:
57655772
version "10.1.0"
57665773
resolved "https://registry.npmjs.org/react-native-vector-icons/-/react-native-vector-icons-10.1.0.tgz"
@@ -6752,11 +6759,25 @@ webidl-conversions@^3.0.0:
67526759
resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz"
67536760
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==
67546761

6762+
webidl-conversions@^5.0.0:
6763+
version "5.0.0"
6764+
resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-5.0.0.tgz"
6765+
integrity sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==
6766+
67556767
whatwg-fetch@^3.0.0:
67566768
version "3.6.20"
67576769
resolved "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz"
67586770
integrity sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==
67596771

6772+
6773+
version "8.0.0-3"
6774+
resolved "https://registry.npmjs.org/whatwg-url-without-unicode/-/whatwg-url-without-unicode-8.0.0-3.tgz"
6775+
integrity sha512-HoKuzZrUlgpz35YO27XgD28uh/WJH4B0+3ttFqRo//lmq+9T/mIOJ6kqmINI9HpUpz1imRC/nR/lxKpJiv0uig==
6776+
dependencies:
6777+
buffer "^5.4.3"
6778+
punycode "^2.1.1"
6779+
webidl-conversions "^5.0.0"
6780+
67606781
whatwg-url@^5.0.0:
67616782
version "5.0.0"
67626783
resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz"

package-lock.json

+41-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antmedia/react-native-ant-media",
3-
"version": "1.10.0",
3+
"version": "1.11.0",
44
"description": "Ant Media Server WebRTC React Native SDK and Reference Project",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
@@ -47,10 +47,19 @@
4747
"registry": "https://registry.npmjs.org/"
4848
},
4949
"devDependencies": {
50+
"@babel/core": "^7.20.0",
51+
"@babel/preset-env": "^7.20.0",
52+
"@babel/runtime": "^7.20.0",
5053
"@commitlint/config-conventional": "^11.0.0",
54+
"@react-native/babel-preset": "0.75.2",
55+
"@react-native/eslint-config": "0.75.2",
56+
"@react-native/metro-config": "0.75.2",
57+
"@react-native/typescript-config": "0.75.2",
5158
"@release-it/conventional-changelog": "^2.0.0",
5259
"@types/jest": "^26.0.0",
5360
"@types/react": "^18.2.6",
61+
"@types/react-test-renderer": "^18.0.0",
62+
"babel-jest": "^29.6.3",
5463
"commitlint": "^11.0.0",
5564
"eslint": "^8.19.0",
5665
"eslint-config-prettier": "^7.0.0",
@@ -62,20 +71,10 @@
6271
"react": "18.3.1",
6372
"react-native": "0.75.2",
6473
"react-native-builder-bob": "^0.18.0",
74+
"react-native-url-polyfill": "^2.0.0",
75+
"react-test-renderer": "18.3.1",
6576
"release-it": "^14.2.2",
66-
"typescript": "5.0.4",
67-
"@babel/core": "^7.20.0",
68-
"@babel/preset-env": "^7.20.0",
69-
"@babel/runtime": "^7.20.0",
70-
"@react-native/babel-preset": "0.75.2",
71-
"@react-native/eslint-config": "0.75.2",
72-
"@react-native/metro-config": "0.75.2",
73-
"@react-native/typescript-config": "0.75.2",
74-
"@types/react-test-renderer": "^18.0.0",
75-
"babel-jest": "^29.6.3",
76-
"react-test-renderer": "18.3.1"
77-
78-
77+
"typescript": "5.0.4"
7978
},
8079
"peerDependencies": {
8180
"react": "*",

src/index.tsx

+22-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
RTCView,
1616
} from 'react-native-webrtc';
1717

18+
import 'react-native-url-polyfill/auto';
19+
1820
//Interfaces
1921
export interface Params {
2022
url: string;
@@ -24,6 +26,7 @@ export interface Params {
2426
peer_connection_config?: any;
2527
debug?: boolean;
2628
onlyDataChannel?: boolean;
29+
playMode?: boolean;
2730
}
2831
export interface RemoteStreams {
2932
[key: string]: MediaStream;
@@ -90,11 +93,22 @@ export function useAntMedia(params: Params) {
9093
peer_connection_config,
9194
debug,
9295
onlyDataChannel,
96+
playMode,
9397
} = params;
9498

99+
var websocketUrl = url;
100+
95101
const adaptorRef: any = useRef<null | Adaptor>(null);
96102

97-
const wsRef: any = useRef<null | WebSocket>(new WebSocket(url));
103+
const isPlayMode = playMode || false;
104+
105+
const updatedUrl = new URL(websocketUrl);
106+
if (!['origin', 'edge'].includes(updatedUrl.searchParams.get('target'))) {
107+
updatedUrl.searchParams.set('target', isPlayMode ? 'edge' : 'origin');
108+
websocketUrl = updatedUrl.toString();
109+
}
110+
111+
const wsRef: any = useRef<null | WebSocket>(new WebSocket(websocketUrl));
98112

99113
var ws = wsRef.current;
100114

@@ -690,7 +704,13 @@ export function useAntMedia(params: Params) {
690704
return;
691705
}
692706

693-
wsRef.current = new WebSocket(url);
707+
const updatedUrl: URL = new URL(websocketUrl);
708+
if (!['origin', 'edge'].includes(updatedUrl.searchParams.get('target'))) {
709+
updatedUrl.searchParams.set('target', isPlayMode ? 'edge' : 'origin');
710+
websocketUrl = updatedUrl.toString();
711+
}
712+
713+
wsRef.current = new WebSocket(websocketUrl);
694714
ws = wsRef.current;
695715
setWebSocketListeners();
696716
console.log('WebSocket is connected');

0 commit comments

Comments
 (0)