Skip to content

Commit 923d401

Browse files
committed
add vibration support android
1 parent b714171 commit 923d401

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

index.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
'use strict';
22
var _InCallManager = require('react-native').NativeModules.InCallManager;
3+
import {
4+
Platform,
5+
Vibration,
6+
} from 'react-native';
37

48
class InCallManager {
59
constructor() {
10+
this.vibrate = false;
611
this.recordPermission = 'unknow';
712
this.caeraPermission = 'unknow';
813
this.checkRecordPermission = this.checkRecordPermission.bind(this);
@@ -55,12 +60,23 @@ class InCallManager {
5560
_InCallManager.setMicrophoneMute(enable);
5661
}
5762

58-
startRingtone(ringtone) {
63+
startRingtone(ringtone, vibrate=false) {
5964
ringtone = (typeof ringtone === 'string') ? ringtone : "_DEFAULT_";
6065
_InCallManager.startRingtone(ringtone);
66+
this.vibrate = vibrate;
67+
if (this.vibrate) {
68+
if (Platform.OS === 'android') {
69+
Vibration.vibrate([0, 1000, 3000], true);
70+
} else {
71+
this.vibrate = false;
72+
}
73+
}
6174
}
6275

6376
stopRingtone() {
77+
if (this.vibrate) {
78+
Vibration.cancel();
79+
}
6480
_InCallManager.stopRingtone();
6581
}
6682

@@ -69,28 +85,28 @@ class InCallManager {
6985
}
7086

7187
async checkRecordPermission() {
72-
// --- on android which api < 23, it will always be "granted"
88+
// --- on android which api < 23, it will always be "granted"
7389
let result = await _InCallManager.checkRecordPermission();
7490
this.recordPermission = result;
7591
return result;
7692
}
7793

7894
async requestRecordPermission() {
79-
// --- on android which api < 23, it will always be "granted"
95+
// --- on android which api < 23, it will always be "granted"
8096
let result = await _InCallManager.requestRecordPermission();
8197
this.recordPermission = result;
8298
return result;
8399
}
84100

85101
async checkCameraPermission() {
86-
// --- on android which api < 23, it will always be "granted"
102+
// --- on android which api < 23, it will always be "granted"
87103
let result = await _InCallManager.checkCameraPermission();
88104
this.cameraPermission = result;
89105
return result;
90106
}
91107

92108
async requestCameraPermission() {
93-
// --- on android which api < 23, it will always be "granted"
109+
// --- on android which api < 23, it will always be "granted"
94110
let result = await _InCallManager.requestCameraPermission();
95111
this.cameraPermission = result;
96112
return result;

0 commit comments

Comments
 (0)