-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
144 lines (127 loc) · 4.9 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* @providesModule Gruveo
*/
'use strict';
import { NativeModules, NativeEventEmitter } from 'react-native';
const { RNGruveo } = NativeModules;
const nativeEventEmitter = new NativeEventEmitter(RNGruveo);
export var InitiateCallError = {
'Unknown': -1, // An unkown error occurred initializing the call
'None': 0, // Сall created successfully
'CodeCallExist': 1, // Curretn call not ended
'MissingClientID': 2, // The clientId value hasn't been set
'InvalidCode': 3, // The code value contains invalid characters
'NetworkUnreachable': 4, // The device is offline
'MicrophoneAccessDenied': 5, // Microphone access denied by user
}
export var CallEndReason = {
'InvalidCredentials': 0, // Invalid token signature provided
'InternalError': 1, // Internal error when creating call
'OutdatedProtocolVersion': 2, // Outdated SDK version
'Busy': 3, // Call room is locked
'HandleUnreachable': 4, // Callee is unreachable
'HandleBusy': 5, // Callee is busy with another call
'HandleNonExist': 6, // Gruveo handle doesn't exist
'FreeDemoEnded': 7, // The 5-minute call limit has been reached (when using the demo client ID)
'RoomLimitReached': 8, // Room limit of 8 participants has been reached
'NoConnection': 9, // Lost connection
'User': 10, // Call ended normally from UI
'OtherParty': 11, // Call ended normally by other party
}
export var CallStatus = {
'initFailed' : 'initFailed', // Failed to initialize the call
'initialized' : 'initialized', // Successfully initialized the call or room
'requestToSignApiAuthToken': 'requestToSignApiAuthToken', // There is a request to sign the authentication token
'callEstablished': 'callEstablished', // Call has established (2 or more people in room)
'callEnd': 'callEnd', // Call has finished for us (we finished or everyone has left)
'recordingStateChanged': 'recordingStateChanged', // The state of recording the current chat has changed
'recordingFilename': 'recordingFilename' // There is a recording filename available
}
var GruveoSDKCallEventListener = null;
/**
* Initialize Gruveo with the specified clientID
* @param {string} clientID The clientID for the current client
*/
export function initialize(clientID) {
RNGruveo.initialize(clientID);
}
/**
* Initiate a call
* @param {string} code The clientID for the current client
* @param {bool} enableVideo Whether to enable video in this call
* @param {bool} enableChat Whether to enable chat in this call
* @param {callback} statusCallback
*/
export function call(code, enableVideo, enableChat, statusCallback) {
if (GruveoSDKCallEventListener != null) {
console.warn("GruveoSDKCallEventListener is not null, did the last call end before you started this call?")
GruveoSDKCallEventListener.remove()
GruveoSDKCallEventListener = null
}
// Register Call event emitter
GruveoSDKCallEventListener = nativeEventEmitter.addListener('RNGruveo', (body) => {
statusCallback(body.name, body.payload)
// If this is a call end event, then remove the listener
if (body.name == 'callEnd') {
GruveoSDKCallEventListener.remove();
GruveoSDKCallEventListener = null;
}
});
RNGruveo.call(code, enableVideo, enableChat)
}
/**
* Set authorization token in Gruveo SDK
* @param {string} signedToken The signedToken to set in the GruveoSDK
*/
export function authorize(signedToken) {
RNGruveo.authorize(signedToken);
}
/**
* Ends the current call.
*/
export function endCall() {
RNGruveo.endCall();
}
/**
* Returns the status of the current call in a promise
* @return {Promise} Resolves to a boolean with the status of the call
*/
export function isCallActive() {
return RNGruveo.isCallActive();
}
/**
* Sets the microphone status.
* @param {bool} enable
*/
export function toggleAudio(enable) {
RNGruveo.toggleAudio(enable);
}
/**
* Sets the camera status.
* @param {bool} enable
*/
export function toggleVideo(enable) {
RNGruveo.toggleVideo(enable);
}
/**
* Sets the source for the outgoing video stream.
* @param {bool} useFront
*/
export function switchCamera(useFront) {
RNGruveo.switchCamera(useFront);
}
/**
* Sets the room lock state.
* @param {bool} enable
*/
export function toggleRoomLock(enable) {
RNGruveo.toggleRoomLock(enable);
}
/**
* Starts or stops call recording.
* @param {bool} enable
* @param {int} layout
*/
export function toggleRecording(enable, layout) {
RNGruveo.toggleRecording(enable, layout);
}