Skip to content

Commit f036a86

Browse files
committed
android link
1 parent 775c897 commit f036a86

File tree

5 files changed

+66
-50
lines changed

5 files changed

+66
-50
lines changed

README.md

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,54 @@
1-
[![npm](https://img.shields.io/npm/dt/react-native-mqtt.svg)]()
1+
[![npm version](https://badge.fury.io/js/sp-react-native-mqtt.svg)](https://badge.fury.io/js/sp-react-native-mqtt)
22

33
## Description
44

55
[react-native](https://github.com/facebook/react-native) mqtt client module
66

77
## MQTT Features (inherit from native MQTT framework)
8+
89
* Use [MQTT Framework](https://github.com/ckrey/MQTT-Client-Framework) for IOS, [Paho MQTT Client](https://eclipse.org/paho/clients/android/) for Android
910
* Support both IOS and Android
1011
* SSL/TLS
1112
* Native library, support mqtt over tcp
1213

1314
## Warning
15+
1416
This library in progress developing, api may change, SSL/TLS non verify
1517

1618
## Getting started
1719

1820
### Manual install
1921

2022
#### JS
23+
2124
```bash
22-
npm install rusfearuth/react-native-mqtt --save
25+
npm install sp-react-native-mqtt --save
2326
```
27+
2428
or
29+
2530
```bash
26-
yarn add rusfearuth/react-native-mqtt
31+
yarn add sp-react-native-mqtt
2732
```
2833

34+
### Linking
35+
36+
```sh
37+
react-native link sp-react-native-mqtt
38+
```
2939

3040
#### iOS
31-
- In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
32-
- Go to `node_modules``react-native-mqtt` and add `RCTMqtt.xcodeproj`
33-
- In XCode, in the project navigator, select your project. Add `libRCTmqtt.a` and `libicucore.tbd` to your project's `Build Phases``Link Binary With Libraries`
34-
- Click `RCTMqtt.xcodeproj` in the project navigator and go the `Build Settings` tab. Make sure 'All' is toggled on (instead of 'Basic'). In the `Search Paths` section, look for `Header Search Paths` and make sure it contains both `$(SRCROOT)/../../react-native/React` - mark as `recursive`.
35-
Add `pod 'MQTTClient'` to your podfile and `pod install`
36-
- Run your project (`Cmd+R`)
3741

42+
* In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
43+
* Go to `node_modules``react-native-mqtt` and add `RCTMqtt.xcodeproj`
44+
* In XCode, in the project navigator, select your project. Add `libRCTmqtt.a` and `libicucore.tbd` to your project's `Build Phases``Link Binary With Libraries`
45+
* Click `RCTMqtt.xcodeproj` in the project navigator and go the `Build Settings` tab. Make sure 'All' is toggled on (instead of 'Basic'). In the `Search Paths` section, look for `Header Search Paths` and make sure it contains both `$(SRCROOT)/../../react-native/React` - mark as `recursive`.
46+
* Add `pod 'MQTTClient'` to your podfile and `pod install`
47+
* Run your project (`Cmd+R`)
3848

3949
#### Android
40-
- Modify the ReactInstanceManager.builder() calls chain in `android/app/main/java/.../MainActivity.java` to include:
50+
51+
* Modify the ReactInstanceManager.builder() calls chain in `android/app/main/java/.../MainActivity.java` to include:
4152

4253
```java
4354
import com.tuanpm.RCTMqtt.*; // import
@@ -48,30 +59,28 @@ import com.tuanpm.RCTMqtt.*; // import
4859
new RCTMqttPackage() // for newest version of react-native
4960
```
5061

51-
- Append the following lines to `android/settings.gradle` before `include ':app'`:
62+
* Append the following lines to `android/settings.gradle` before `include ':app'`:
5263

53-
```
64+
```gradle
5465
include ':react-native-mqtt'
5566
project(':react-native-mqtt').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mqtt/android')
5667
5768
```
5869

70+
* Insert the following lines inside the dependencies block in `android/app/build.gradle`, don't missing `apply plugin:'java'` on top:
5971

60-
- Insert the following lines inside the dependencies block in `android/app/build.gradle`, don't missing `apply plugin:'java'` on top:
61-
62-
```
72+
```gradle
6373
compile project(':react-native-mqtt')
6474
```
6575

6676
Notes:
6777

68-
```
78+
```gradle
6979
dependencies {
7080
compile project(':react-native-mqtt')
7181
}
7282
```
7383

74-
7584
## Usage
7685

7786
```javascript
@@ -109,42 +118,42 @@ MQTT.createClient({
109118
```
110119

111120
## API
121+
112122
* `mqtt.createClient(options)` create new client instance with `options`, async operation
113-
- `uri`: `protocol://host:port`, protocol is [mqtt | mqtts]
114-
- `host`: ipaddress or host name (override by uri if set)
115-
- `port`: port number (override by uri if set)
116-
- `tls`: true/false (override by uri if set to mqtts or wss)
117-
- `user`: string username
118-
- `pass`: string password
119-
- `auth`: true/false - override = true if `user` or `pass` exist
120-
- `clientId`: string client id
121-
- `keepalive`
123+
* `uri`: `protocol://host:port`, protocol is [mqtt | mqtts]
124+
* `host`: ipaddress or host name (override by uri if set)
125+
* `port`: port number (override by uri if set)
126+
* `tls`: true/false (override by uri if set to mqtts or wss)
127+
* `user`: string username
128+
* `pass`: string password
129+
* `auth`: true/false - override = true if `user` or `pass` exist
130+
* `clientId`: string client id
131+
* `keepalive`
122132

123133
* `client`
124-
- `on(event, callback)`: add event listener for
125-
+ event: `connect` - client connected
126-
+ event: `closed` - client disconnected
127-
+ event: `error` - error
128-
+ event: `message` - message object
129-
- `connect`: begin connection
130-
- `disconnect`: disconnect
131-
- `subscribe(topic, qos)`
132-
- `publish(topic, payload, qos, retain)`
134+
* `on(event, callback)`: add event listener for
135+
* event: `connect` - client connected
136+
* event: `closed` - client disconnected
137+
* event: `error` - error
138+
* event: `message` - message object
139+
* `connect`: begin connection
140+
* `disconnect`: disconnect
141+
* `subscribe(topic, qos)`
142+
* `publish(topic, payload, qos, retain)`
133143

134144
* `message`
135-
- `retain`: *boolean* `false`
136-
- `qos`: *number* `2`
137-
- `data`: *string* `"test message"`
138-
- `topic`: *string* `"/data"`
145+
* `retain`: *boolean* `false`
146+
* `qos`: *number* `2`
147+
* `data`: *string* `"test message"`
148+
* `topic`: *string* `"/data"`
139149

140150
## Todo
141151

142152
* [ ] Use WeakReference for timer
143153
* [ ] Add disconnecting event
144154

145-
146155
## LICENSE
147156

148-
```
157+
```text
149158
INHERIT FROM MQTT LIBRARY (progress)
150159
```

android/build.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
def safeExtGet(prop, fallback) {
2+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
3+
}
4+
15
buildscript {
26
repositories {
37
google()
@@ -12,12 +16,12 @@ buildscript {
1216
apply plugin: 'com.android.library'
1317

1418
android {
15-
compileSdkVersion 28
16-
buildToolsVersion "28.0.3"
19+
compileSdkVersion safeExtGet('compileSdkVersion', 28)
20+
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
1721

1822
defaultConfig {
19-
minSdkVersion 16
20-
targetSdkVersion 26
23+
minSdkVersion safeExtGet('minSdkVersion', 16)
24+
targetSdkVersion safeExtGet('targetSdkVersion', 26)
2125
versionCode 1
2226
versionName "1.0"
2327
}

android/src/main/java/com/tuanpm/RCTMqtt/RCTMqtt.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public RCTMqtt(@NonNull final String ref, final ReactApplicationContext reactCon
6565
defaultOptions.putString("user", "");
6666
defaultOptions.putString("pass", "");
6767
defaultOptions.putBoolean("will", false);
68-
defaultOptions.putInt("protocolLevel", 4);
6968
defaultOptions.putString("willMsg", "");
7069
defaultOptions.putString("willtopic", "");
7170
defaultOptions.putInt("willQos", 0);
@@ -155,7 +154,7 @@ private void createClient(@NonNull final ReadableMap params) {
155154
/*
156155
* http://stackoverflow.com/questions/3761737/https-get-ssl-with-android-and-
157156
* self-signed-server-certificate
158-
*
157+
*
159158
* WARNING: for anybody else arriving at this answer, this is a dirty, horrible
160159
* hack and you must not use it for anything that matters. SSL/TLS without
161160
* authentication is worse than no encryption at all - reading and modifying

android/src/main/java/com/tuanpm/RCTMqtt/RCTMqttPackage.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
import java.util.Collections;
1111
import java.util.List;
1212

13-
public class RCTMqttPackage
14-
implements ReactPackage
13+
public class RCTMqttPackage implements ReactPackage
1514
{
1615

1716
@Override

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"repository": {
1010
"type": "git",
11-
"url": "git+https://github.com/hawkingnetwork/react-native-mqtt.git"
11+
"url": "git+https://github.com/SudoPlz/react-native-mqtt.git"
1212
},
1313
"keywords": [
1414
"mqtt",
@@ -35,6 +35,11 @@
3535
"name": "Tuan PM",
3636
"email": "[email protected]",
3737
"url": "http://tuanpm.net"
38+
},
39+
{
40+
"name": "taoqf",
41+
"email": "[email protected]",
42+
"url": "http://github.com/taoqf"
3843
}
3944
],
4045
"license": "MIT",

0 commit comments

Comments
 (0)