react-native-meshstream 0.0.0-stage → 1.0.0
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.
- package/CHANGELOG.md +8 -0
- package/LICENSE +176 -0
- package/MeshStreamP2P.podspec +20 -0
- package/README.md +125 -2
- package/README.zh-CN.md +126 -0
- package/android/build.gradle +23 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/net/meshstream/reactnative/MeshStreamP2PModule.kt +367 -0
- package/android/src/main/java/net/meshstream/reactnative/MeshStreamP2PPackage.kt +13 -0
- package/ios/MeshStreamP2P.h +4 -0
- package/ios/MeshStreamP2P.m +339 -0
- package/ios/MeshStreamP2PValidation.h +9 -0
- package/ios/MeshStreamP2PValidation.m +23 -0
- package/lib/typescript/NativeMeshStreamP2P.d.ts +19 -0
- package/lib/typescript/NativeMeshStreamP2P.js +11 -0
- package/lib/typescript/index.d.ts +41 -0
- package/lib/typescript/index.js +129 -0
- package/lib/typescript/types.d.ts +78 -0
- package/lib/typescript/types.js +2 -0
- package/package.json +49 -4
- package/react-native.config.js +11 -0
- package/src/NativeMeshStreamP2P.ts +35 -0
- package/src/index.ts +147 -0
- package/src/types.ts +118 -0
- package/tests/ios/MeshStreamP2PValidationTests.m +30 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
- Unified Android and iOS React Native bridges over the respective native MeshStream SDKs.
|
|
6
|
+
- Multi-client and multi-session lifecycle API.
|
|
7
|
+
- Playback URL, preload, player telemetry, status, statistics, diagnostics, and typed events.
|
|
8
|
+
- CDN-safe fallback semantics preserved from the native SDK.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Pod::Spec.new do |s|
|
|
2
|
+
s.name = 'MeshStreamP2P'
|
|
3
|
+
s.version = '1.0.0'
|
|
4
|
+
s.summary = 'MeshStream P2P playback URL bridge for React Native.'
|
|
5
|
+
s.homepage = 'https://github.com/Mesh-Stream/meshstream-p2p-react-native-sdk'
|
|
6
|
+
s.license = { :type => 'Apache-2.0' }
|
|
7
|
+
s.author = { 'MeshStream' => 'support@meshstream.net' }
|
|
8
|
+
s.platforms = { :ios => '13.0' }
|
|
9
|
+
s.source = { :git => 'https://github.com/Mesh-Stream/meshstream-p2p-react-native-sdk.git', :tag => s.version.to_s }
|
|
10
|
+
s.source_files = 'ios/**/*.{h,m}'
|
|
11
|
+
s.public_header_files = 'ios/MeshStreamP2P.h'
|
|
12
|
+
s.private_header_files = 'ios/MeshStreamP2PValidation.h'
|
|
13
|
+
s.dependency 'React-Core'
|
|
14
|
+
s.dependency 'MeshStreamKit', '= 1.0.2'
|
|
15
|
+
s.frameworks = 'Foundation', 'Network', 'Security'
|
|
16
|
+
|
|
17
|
+
s.test_spec 'Validation' do |test_spec|
|
|
18
|
+
test_spec.source_files = 'tests/ios/MeshStreamP2PValidationTests.m'
|
|
19
|
+
end
|
|
20
|
+
end
|
package/README.md
CHANGED
|
@@ -1,3 +1,126 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MeshStream React Native SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React Native binding for MeshStream P2P playback acceleration. It creates a CDN-safe local playback URL; use that URL with `react-native-video` or your existing player. The SDK does not include a player and does not control your player lifecycle.
|
|
4
|
+
|
|
5
|
+
> This is one cross-platform React Native package. It bridges to the MeshStream Android SDK on Android and MeshStreamKit on iOS. The JavaScript API and client/session lifecycle are identical on both platforms.
|
|
6
|
+
|
|
7
|
+
[中文文档](./README.zh-CN.md) | [Web SDK](https://github.com/Mesh-Stream/meshstream-p2p-web-sdk) | [Android SDK](https://github.com/Mesh-Stream/meshstream-p2p-android-sdk) | [iOS SDK](https://github.com/Mesh-Stream/meshstream-p2p-ios-sdk) | [Windows SDK](https://github.com/Mesh-Stream/meshstream-p2p-Windows-sdk) | [Online demo](https://demo.meshstream.net/)
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- React Native `0.72+`
|
|
12
|
+
- Android API 24+ (Android 7.0+) or iOS 13+
|
|
13
|
+
- MeshStream SDK key enabled for the target platform
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install react-native-meshstream
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For Android, add the MeshStream Maven repository to `android/settings.gradle` in the app's `dependencyResolutionManagement.repositories` block:
|
|
22
|
+
|
|
23
|
+
```kotlin
|
|
24
|
+
repositories {
|
|
25
|
+
google()
|
|
26
|
+
mavenCentral()
|
|
27
|
+
maven {
|
|
28
|
+
url = uri("https://pub-61830e1369904d19af505ff74fd55ba4.r2.dev/maven")
|
|
29
|
+
content { includeGroup("io.meshstream") }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For iOS, the bridge resolves the public `MeshStreamKit 1.0.2` CocoaPod. After installation, run `pod install --repo-update` from the app's `ios` directory and rebuild the native app. Do not add a local `MeshStreamKit` pod path or embed its XCFramework yourself.
|
|
35
|
+
|
|
36
|
+
## Basic usage
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import Video from 'react-native-video';
|
|
40
|
+
import { MeshStream } from 'react-native-meshstream';
|
|
41
|
+
|
|
42
|
+
const client = await MeshStream.create({ key: 'key_your_android_key' });
|
|
43
|
+
const session = await client.createPlaybackSession({
|
|
44
|
+
url: 'https://cdn.example.com/live/playlist.m3u8',
|
|
45
|
+
contentId: 'live-channel-42', // Stable across rotating signed URLs.
|
|
46
|
+
mimeType: 'm3u8',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Keep the session alive while the player uses this URL.
|
|
50
|
+
<Video source={{ uri: session.playbackUrl }} controls />;
|
|
51
|
+
|
|
52
|
+
// On player teardown:
|
|
53
|
+
await session.close();
|
|
54
|
+
await client.close();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`createPlaybackSession` returns promptly with a CDN-safe URL. P2P policy/bootstrap work proceeds in the background. A policy, tracker, or peer issue falls back to your origin/CDN and does not intentionally stop an already running player.
|
|
58
|
+
|
|
59
|
+
## Multiple players and preload
|
|
60
|
+
|
|
61
|
+
One client can host several sessions. A session is independent and must be closed when its player is no longer using the URL.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const next = await client.createPlaybackSession({
|
|
65
|
+
url: nextItem.url,
|
|
66
|
+
contentId: nextItem.id,
|
|
67
|
+
mimeType: 'mp4',
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
await next.preload();
|
|
71
|
+
// Give next.playbackUrl to the player only when it becomes active.
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Close the `MeshStream` client or session created by this binding instead of shutting down a native SDK globally. This keeps other React Native players in the same process isolated.
|
|
75
|
+
|
|
76
|
+
## Player telemetry
|
|
77
|
+
|
|
78
|
+
Forward state from the active player at a low frequency. These methods do not cause reporting by themselves; native SDK reporting remains internal.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
await session.updateBufferedDurationMs(bufferedDurationMs);
|
|
82
|
+
await session.updateCurrentPositionMs(currentPositionMs);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Events, status, and diagnostics
|
|
86
|
+
|
|
87
|
+
Events always include `clientId` and `sessionId`, which makes multiple players safe to observe.
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { MeshStream, addMeshStreamEventListener } from 'react-native-meshstream';
|
|
91
|
+
|
|
92
|
+
const subscription = addMeshStreamEventListener((event) => {
|
|
93
|
+
if (event.type === 'p2pUnavailable') {
|
|
94
|
+
console.info('P2P unavailable for this session:', event.reason);
|
|
95
|
+
}
|
|
96
|
+
}, { clientId: client.clientId });
|
|
97
|
+
|
|
98
|
+
const status = await client.getStatus();
|
|
99
|
+
const stats = await session.getStats();
|
|
100
|
+
const diagnostics = await session.getDiagnostics();
|
|
101
|
+
|
|
102
|
+
subscription.remove();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Available event types: `peerCountChanged`, `playbackPrepared`, `p2pReady`, `p2pUnavailable`, `statistics`, `cdnFallback`, `trackerError`, and `peerConnectError`.
|
|
106
|
+
|
|
107
|
+
## Supported media
|
|
108
|
+
|
|
109
|
+
The binding forwards to the platform-native SDK. HLS (`m3u8`), DASH (`mpd`), MP4, and MP3 can be declared through `mimeType`; provide a stable `contentId` for any URL that rotates credentials. Your chosen React Native player must independently support the source format.
|
|
110
|
+
|
|
111
|
+
## Native dependencies
|
|
112
|
+
|
|
113
|
+
The package is a unified JavaScript layer, not an Android SDK repackaged for React Native:
|
|
114
|
+
|
|
115
|
+
### Versioning
|
|
116
|
+
|
|
117
|
+
- `react-native-meshstream` follows its own React Native package version. This release is `1.0.0`.
|
|
118
|
+
- The Android bridge keeps its independent native dependency: `io.meshstream:meshstream-android-sdk:1.0.2`.
|
|
119
|
+
- The iOS bridge keeps its independent native dependency: `MeshStreamKit >= 1.0.0`.
|
|
120
|
+
|
|
121
|
+
Updating the React Native package does not implicitly upgrade either native SDK.
|
|
122
|
+
|
|
123
|
+
- Android resolves `io.meshstream:meshstream-android-sdk:1.0.2` from the MeshStream Maven repository.
|
|
124
|
+
- iOS resolves the public `MeshStreamKit 1.0.2` CocoaPod.
|
|
125
|
+
|
|
126
|
+
Both bridges maintain client/session isolation. Closing a client only closes its own sessions and never interrupts another React Native player in the same process.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# MeshStream React Native SDK
|
|
2
|
+
|
|
3
|
+
面向 React Native 的 MeshStream P2P 播放加速绑定。SDK 返回可直接交给播放器的本地代理播放地址;应用可继续使用 `react-native-video` 或现有播放器。SDK 不内置播放器,也不接管播放器生命周期。
|
|
4
|
+
|
|
5
|
+
> 这是一个统一的跨端 React Native 包:Android 运行时桥接 MeshStream Android SDK,iOS 运行时桥接 MeshStreamKit。两端使用相同的 JavaScript API、client/session 生命周期和事件模型。
|
|
6
|
+
|
|
7
|
+
[English](./README.md) | [Web SDK](https://github.com/Mesh-Stream/meshstream-p2p-web-sdk) | [Android SDK](https://github.com/Mesh-Stream/meshstream-p2p-android-sdk) | [iOS SDK](https://github.com/Mesh-Stream/meshstream-p2p-ios-sdk) | [Windows SDK](https://github.com/Mesh-Stream/meshstream-p2p-Windows-sdk) | [在线 Demo](https://demo.meshstream.net/)
|
|
8
|
+
|
|
9
|
+
## 环境要求
|
|
10
|
+
|
|
11
|
+
- React Native `0.72+`
|
|
12
|
+
- Android API 24+(Android 7.0+)或 iOS 13+
|
|
13
|
+
- 已启用对应目标平台的 MeshStream SDK Key
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install react-native-meshstream
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
在 React Native Android 工程的 `android/settings.gradle` 中,向 `dependencyResolutionManagement.repositories` 添加 MeshStream Maven 仓库:
|
|
22
|
+
|
|
23
|
+
```kotlin
|
|
24
|
+
repositories {
|
|
25
|
+
google()
|
|
26
|
+
mavenCentral()
|
|
27
|
+
maven {
|
|
28
|
+
url = uri("https://pub-61830e1369904d19af505ff74fd55ba4.r2.dev/maven")
|
|
29
|
+
content { includeGroup("io.meshstream") }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
接入 iOS 时,bridge 会解析公开的 `MeshStreamKit 1.0.2` CocoaPod。安装 npm 包后,请在应用的 `ios` 目录执行 `pod install --repo-update` 并重新编译原生工程;不要添加本地 `MeshStreamKit` Pod 路径,也不需要手动嵌入 XCFramework。
|
|
35
|
+
|
|
36
|
+
## 基础接入
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import Video from 'react-native-video';
|
|
40
|
+
import { MeshStream } from 'react-native-meshstream';
|
|
41
|
+
|
|
42
|
+
const client = await MeshStream.create({ key: 'key_your_android_key' });
|
|
43
|
+
const session = await client.createPlaybackSession({
|
|
44
|
+
url: 'https://cdn.example.com/live/playlist.m3u8',
|
|
45
|
+
contentId: 'live-channel-42', // 签名 URL 轮换时保持稳定。
|
|
46
|
+
mimeType: 'm3u8',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// 播放期间保持 session 存活。
|
|
50
|
+
<Video source={{ uri: session.playbackUrl }} controls />;
|
|
51
|
+
|
|
52
|
+
// 播放器销毁时:
|
|
53
|
+
await session.close();
|
|
54
|
+
await client.close();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`createPlaybackSession` 会立即返回 CDN 安全的播放地址;P2P 策略和网络初始化在后台执行。策略、Tracker 或对等连接不可用时会回源 CDN,不会主动硬中断正在播放的会话。
|
|
58
|
+
|
|
59
|
+
## 多播放器与预热
|
|
60
|
+
|
|
61
|
+
一个 client 可管理多个独立 session。每个 session 对应一个播放项,用完必须关闭。
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const next = await client.createPlaybackSession({
|
|
65
|
+
url: nextItem.url,
|
|
66
|
+
contentId: nextItem.id,
|
|
67
|
+
mimeType: 'mp4',
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
await next.preload();
|
|
71
|
+
// 仅在下一条真正播放时,将 next.playbackUrl 交给播放器。
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
请关闭本绑定创建的 `MeshStream` client 或 session,而不是全局关闭原生 SDK;这样不会影响同一进程内的其他 React Native 播放器实例。
|
|
75
|
+
|
|
76
|
+
## 播放器状态上报
|
|
77
|
+
|
|
78
|
+
从当前活跃播放器以低频更新状态。以下调用不会自行发起用量上报,原生 SDK 的统计上报仍由其内部控制。
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
await session.updateBufferedDurationMs(bufferedDurationMs);
|
|
82
|
+
await session.updateCurrentPositionMs(currentPositionMs);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 事件、状态与诊断
|
|
86
|
+
|
|
87
|
+
所有事件都带有 `clientId`、`sessionId`,可安全用于多播放器场景。
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { addMeshStreamEventListener } from 'react-native-meshstream';
|
|
91
|
+
|
|
92
|
+
const subscription = addMeshStreamEventListener((event) => {
|
|
93
|
+
if (event.type === 'p2pUnavailable') {
|
|
94
|
+
console.info('当前会话 P2P 不可用:', event.reason);
|
|
95
|
+
}
|
|
96
|
+
}, { clientId: client.clientId });
|
|
97
|
+
|
|
98
|
+
const status = await client.getStatus();
|
|
99
|
+
const stats = await session.getStats();
|
|
100
|
+
const diagnostics = await session.getDiagnostics();
|
|
101
|
+
|
|
102
|
+
subscription.remove();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
事件类型包括:`peerCountChanged`、`playbackPrepared`、`p2pReady`、`p2pUnavailable`、`statistics`、`cdnFallback`、`trackerError`、`peerConnectError`。
|
|
106
|
+
|
|
107
|
+
## 支持的媒体格式
|
|
108
|
+
|
|
109
|
+
底层调用平台原生 SDK。可通过 `mimeType` 声明 HLS(`m3u8`)、DASH(`mpd`)、MP4、MP3;签名 URL 或播放地址会变化时,应传入稳定的 `contentId`。最终格式支持能力仍以所选 React Native 播放器为准。
|
|
110
|
+
|
|
111
|
+
## 原生依赖
|
|
112
|
+
|
|
113
|
+
这个包是统一的 JavaScript 层,不是将 Android SDK 重新打包:
|
|
114
|
+
|
|
115
|
+
### 版本说明
|
|
116
|
+
|
|
117
|
+
- `react-native-meshstream` 使用独立的 React Native 包版本;当前首发版本为 `1.0.0`。
|
|
118
|
+
- Android 桥接使用独立的原生依赖:`io.meshstream:meshstream-android-sdk:1.0.2`。
|
|
119
|
+
- iOS 桥接使用独立的原生依赖:`MeshStreamKit >= 1.0.0`。
|
|
120
|
+
|
|
121
|
+
升级 React Native 包不会隐式升级任一原生 SDK。
|
|
122
|
+
|
|
123
|
+
- Android 从 MeshStream Maven 仓库解析 `io.meshstream:meshstream-android-sdk:1.0.2`。
|
|
124
|
+
- iOS 通过 CocoaPods 解析公开的 `MeshStreamKit 1.0.2`。
|
|
125
|
+
|
|
126
|
+
两个 bridge 都保证 client/session 隔离。关闭某一个 client 只会关闭其所属会话,不会中断同一进程中的其他 React Native 播放器。
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext {
|
|
3
|
+
kotlinVersion = project.findProperty('kotlinVersion') ?: '1.9.25'
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
apply plugin: 'com.android.library'
|
|
8
|
+
apply plugin: 'kotlin-android'
|
|
9
|
+
|
|
10
|
+
android {
|
|
11
|
+
namespace 'net.meshstream.reactnative'
|
|
12
|
+
compileSdkVersion 35
|
|
13
|
+
|
|
14
|
+
defaultConfig {
|
|
15
|
+
minSdkVersion 24
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
dependencies {
|
|
20
|
+
implementation 'com.facebook.react:react-android'
|
|
21
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
|
22
|
+
implementation 'io.meshstream:meshstream-android-sdk:1.0.2'
|
|
23
|
+
}
|