@ai-vyumi/livecall 0.1.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.
@@ -0,0 +1,225 @@
1
+ "use strict";
2
+ // CallService.ts
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ const route_1 = require("../network/route");
17
+ const SessionManager_1 = __importDefault(require("../session/SessionManager"));
18
+ const Logger_1 = __importDefault(require("../utils/Logger"));
19
+ const utils_1 = require("../utils/utils");
20
+ const WebSocketService_1 = __importDefault(require("./WebSocketService"));
21
+ const ZegoServices_1 = __importDefault(require("./ZegoServices"));
22
+ class CallService {
23
+ constructor() {
24
+ this.sessionCallback = null;
25
+ this.queueInterval = null;
26
+ }
27
+ startCheckingQueueUpdate() {
28
+ if (this.queueInterval !== null)
29
+ return;
30
+ this.queueInterval = setInterval(() => __awaiter(this, void 0, void 0, function* () {
31
+ var _a, _b, _c, _d, _e, _f, _g;
32
+ try {
33
+ const result = yield (0, route_1.getQueueStatus)((_a = SessionManager_1.default.getCurrentCall()) === null || _a === void 0 ? void 0 : _a.call_session_id);
34
+ const position = (_c = (_b = result === null || result === void 0 ? void 0 : result.data) === null || _b === void 0 ? void 0 : _b.position) !== null && _c !== void 0 ? _c : 0;
35
+ (_e = (_d = this.sessionCallback) === null || _d === void 0 ? void 0 : _d.onQueueUpdate) === null || _e === void 0 ? void 0 : _e.call(_d, `You are at position ${position} in the queue.`, position);
36
+ }
37
+ catch (error) {
38
+ (_f = this.sessionCallback) === null || _f === void 0 ? void 0 : _f.onError((_g = error === null || error === void 0 ? void 0 : error.message) !== null && _g !== void 0 ? _g : 'Queue check failed');
39
+ }
40
+ }), 5000);
41
+ }
42
+ stopCheckingQueueUpdate() {
43
+ if (this.queueInterval !== null) {
44
+ clearInterval(this.queueInterval);
45
+ this.queueInterval = null;
46
+ }
47
+ }
48
+ createUser(payload) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ var _a, _b;
51
+ payload.company_id = SessionManager_1.default.getCompanyId();
52
+ try {
53
+ const response = yield (0, route_1.postUserInfo)(payload);
54
+ if (response.valid) {
55
+ SessionManager_1.default.setUser((_a = response.data) === null || _a === void 0 ? void 0 : _a.user);
56
+ return true;
57
+ }
58
+ else {
59
+ Logger_1.default.error('Failed to create user', response.code, response.data, payload);
60
+ (_b = this.sessionCallback) === null || _b === void 0 ? void 0 : _b.onError(`${response.data}`);
61
+ return false;
62
+ }
63
+ }
64
+ catch (_c) {
65
+ return false;
66
+ }
67
+ });
68
+ }
69
+ initiateCall(payload, media_type, sessionCallback) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ var _a, _b, _c, _d, _e;
72
+ this.sessionCallback = sessionCallback;
73
+ SessionManager_1.default.product_url = payload === null || payload === void 0 ? void 0 : payload.product_url;
74
+ const user = yield this.createUser(payload);
75
+ if (!user) {
76
+ return;
77
+ }
78
+ try {
79
+ const callPayload = Object.assign({ customer_uuid: (_a = SessionManager_1.default.getUser()) === null || _a === void 0 ? void 0 : _a.uuid, customer_name: (_b = SessionManager_1.default.getUser()) === null || _b === void 0 ? void 0 : _b.name, customer_mobile_no: (_c = SessionManager_1.default.getUser()) === null || _c === void 0 ? void 0 : _c.mobile_no, source: 'app', media_type }, payload);
80
+ const response = yield (0, route_1.postInitiateCall)(callPayload);
81
+ SessionManager_1.default.currentCallMediaType = media_type;
82
+ if (!response.valid) {
83
+ (_d = this.sessionCallback) === null || _d === void 0 ? void 0 : _d.onError(`${response === null || response === void 0 ? void 0 : response.data}`);
84
+ return;
85
+ }
86
+ // Save call session
87
+ SessionManager_1.default.setCurrentCall((_e = response.data) === null || _e === void 0 ? void 0 : _e.data);
88
+ // Start websocket
89
+ this.initializeSocket();
90
+ this.startCheckingQueueUpdate();
91
+ }
92
+ catch (_f) {
93
+ sessionCallback === null || sessionCallback === void 0 ? void 0 : sessionCallback.onError('Something went wrong');
94
+ }
95
+ });
96
+ }
97
+ joinCall(_a) {
98
+ return __awaiter(this, arguments, void 0, function* ({ remoteViewHandle, localViewHandle, interactionCallback, }) {
99
+ SessionManager_1.default.interactionCallback = interactionCallback;
100
+ yield ZegoServices_1.default.initZegoEngine({ remoteViewHandle, localViewHandle });
101
+ });
102
+ }
103
+ initializeSocket() {
104
+ var _a;
105
+ const wsUrl = (_a = SessionManager_1.default.getCurrentCall()) === null || _a === void 0 ? void 0 : _a.ws_url;
106
+ if (!wsUrl) {
107
+ return;
108
+ }
109
+ WebSocketService_1.default.onConnect(() => {
110
+ Logger_1.default.log('WebSocket Connected');
111
+ WebSocketService_1.default.startHeartbeat();
112
+ });
113
+ WebSocketService_1.default.onMessage(data => {
114
+ Logger_1.default.log('Socket Message:', data);
115
+ this.handleSocketMessage(data);
116
+ });
117
+ WebSocketService_1.default.onError(error => {
118
+ Logger_1.default.log('Socket Error:', error);
119
+ });
120
+ WebSocketService_1.default.onDisconnect(() => {
121
+ Logger_1.default.log('Socket Disconnected');
122
+ });
123
+ WebSocketService_1.default.connect(wsUrl);
124
+ }
125
+ handleSocketMessage(data) {
126
+ var _a, _b, _c;
127
+ switch (data === null || data === void 0 ? void 0 : data.type) {
128
+ case 'agent_ringing':
129
+ (_a = this.sessionCallback) === null || _a === void 0 ? void 0 : _a.onConnectingToAgent('Connecting to agent');
130
+ this.stopCheckingQueueUpdate();
131
+ break;
132
+ case 'retrying':
133
+ this.stopCheckingQueueUpdate();
134
+ break;
135
+ case 'agent_found':
136
+ this.stopCheckingQueueUpdate();
137
+ (_b = this.sessionCallback) === null || _b === void 0 ? void 0 : _b.onAgentAssigned(`{${data === null || data === void 0 ? void 0 : data.user_name}`);
138
+ this.generateZegoToken();
139
+ break;
140
+ case 'no_agent':
141
+ this.stopCheckingQueueUpdate();
142
+ this.onNoAgentFound();
143
+ break;
144
+ case 'call_ended':
145
+ this.stopCheckingQueueUpdate();
146
+ (_c = SessionManager_1.default.interactionCallback) === null || _c === void 0 ? void 0 : _c.onCallEnded();
147
+ this.endCall();
148
+ break;
149
+ default:
150
+ Logger_1.default.log('Unhandled socket event', data);
151
+ }
152
+ }
153
+ onNoAgentFound() {
154
+ return __awaiter(this, void 0, void 0, function* () {
155
+ var _a;
156
+ WebSocketService_1.default.disconnect();
157
+ WebSocketService_1.default.stopHeartbeat();
158
+ (_a = this.sessionCallback) === null || _a === void 0 ? void 0 : _a.onAgentNotAvailable('Agent not available');
159
+ this.endCall();
160
+ });
161
+ }
162
+ generateZegoToken() {
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ var _a, _b, _c, _d, _e;
165
+ SessionManager_1.default.localStreamId = (0, utils_1.generateUniqueId)();
166
+ const payload = {
167
+ call_session_id: (_a = SessionManager_1.default.getCurrentCall()) === null || _a === void 0 ? void 0 : _a.call_session_id,
168
+ role: 'customer',
169
+ customer_uuid: (_b = SessionManager_1.default.getUser()) === null || _b === void 0 ? void 0 : _b.uuid,
170
+ };
171
+ const response = yield (0, route_1.getZegoToken)(payload);
172
+ if (response.valid) {
173
+ SessionManager_1.default.setCurrentZegoCall((_c = response.data) === null || _c === void 0 ? void 0 : _c.data);
174
+ (_d = this.sessionCallback) === null || _d === void 0 ? void 0 : _d.onRoomReady('Room is ready please call joinCall function to join the call');
175
+ }
176
+ else {
177
+ (_e = this.sessionCallback) === null || _e === void 0 ? void 0 : _e.onError(`${response.data}`);
178
+ }
179
+ });
180
+ }
181
+ scheduleCall(payload) {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ var _a;
184
+ payload.company_id = SessionManager_1.default.getCompanyId();
185
+ const response = yield (0, route_1.postUserInfo)(payload);
186
+ if (response.valid) {
187
+ const user = (_a = response.data) === null || _a === void 0 ? void 0 : _a.user;
188
+ payload.uuid, user === null || user === void 0 ? void 0 : user.uuid;
189
+ payload.mobileNumber, user.mobile_no;
190
+ payload.userName, user.name;
191
+ payload.ext, user === null || user === void 0 ? void 0 : user.country_code;
192
+ const scheduleCall = yield (0, route_1.postScheduleCall)(payload);
193
+ return scheduleCall;
194
+ }
195
+ });
196
+ }
197
+ getCallTimeSlots(queryParams) {
198
+ return __awaiter(this, void 0, void 0, function* () {
199
+ return (0, route_1.getScheduleTimeSlots)(queryParams);
200
+ });
201
+ }
202
+ cancelCall() {
203
+ return __awaiter(this, void 0, void 0, function* () {
204
+ var _a;
205
+ const payload = {
206
+ action: 'cancel_call',
207
+ call_session_id: (_a = SessionManager_1.default.getCurrentCall()) === null || _a === void 0 ? void 0 : _a.call_session_id,
208
+ };
209
+ WebSocketService_1.default.sendMessage(payload);
210
+ yield ZegoServices_1.default.endCall();
211
+ SessionManager_1.default.clear();
212
+ SessionManager_1.default.clearUser();
213
+ });
214
+ }
215
+ endCall() {
216
+ return __awaiter(this, void 0, void 0, function* () {
217
+ WebSocketService_1.default.disconnect();
218
+ yield ZegoServices_1.default.endCall();
219
+ SessionManager_1.default.clear();
220
+ SessionManager_1.default.clearUser();
221
+ });
222
+ }
223
+ }
224
+ const callService = new CallService();
225
+ exports.default = callService;
@@ -0,0 +1 @@
1
+ export declare const initializeVyumiService: (brandId: string, debug?: boolean) => Promise<void>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.initializeVyumiService = void 0;
16
+ const route_1 = require("../network/route");
17
+ const SessionManager_1 = __importDefault(require("../session/SessionManager"));
18
+ const Logger_1 = __importDefault(require("../utils/Logger"));
19
+ const initializeVyumiService = (brandId_1, ...args_1) => __awaiter(void 0, [brandId_1, ...args_1], void 0, function* (brandId, debug = false) {
20
+ var _a;
21
+ const config = { companyId: brandId, debug: debug };
22
+ SessionManager_1.default.initialize(config);
23
+ const response = yield (0, route_1.getConfiguration)();
24
+ if (response.valid) {
25
+ SessionManager_1.default.setBrandConfig((_a = response.data) === null || _a === void 0 ? void 0 : _a.data);
26
+ Logger_1.default.info('Init successful');
27
+ }
28
+ else {
29
+ Logger_1.default.error('Init is unsuccessful', response === null || response === void 0 ? void 0 : response.code, response.data);
30
+ }
31
+ });
32
+ exports.initializeVyumiService = initializeVyumiService;
@@ -0,0 +1 @@
1
+ export declare const postReview: (review: any) => Promise<import("../network/axios").ApiResult<any>>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.postReview = void 0;
16
+ const route_1 = require("../network/route");
17
+ const SessionManager_1 = __importDefault(require("../session/SessionManager"));
18
+ const postReview = (review) => __awaiter(void 0, void 0, void 0, function* () {
19
+ var _a;
20
+ return (0, route_1.postRating)(((_a = SessionManager_1.default.getCurrentCall()) === null || _a === void 0 ? void 0 : _a.call_session_id) || '', review);
21
+ });
22
+ exports.postReview = postReview;
@@ -0,0 +1,24 @@
1
+ type MessageListener = (data: any) => void;
2
+ type ErrorListener = (error: any) => void;
3
+ type ConnectListener = () => void;
4
+ type DisconnectListener = () => void;
5
+ declare class WebSocketService {
6
+ private socket;
7
+ private onMessageListener?;
8
+ private onErrorListener?;
9
+ private onConnectListener?;
10
+ private onDisconnectListener?;
11
+ private heartbeatInterval;
12
+ connect(url: string): void;
13
+ sendMessage(data: any): boolean;
14
+ disconnect(): void;
15
+ onMessage(listener: MessageListener): void;
16
+ onError(listener: ErrorListener): void;
17
+ onConnect(listener: ConnectListener): void;
18
+ onDisconnect(listener: DisconnectListener): void;
19
+ isConnected(): boolean;
20
+ startHeartbeat(): void;
21
+ stopHeartbeat(): void;
22
+ }
23
+ declare const webSocketService: WebSocketService;
24
+ export default webSocketService;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ // WebSocketService.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ class WebSocketService {
5
+ constructor() {
6
+ this.socket = null;
7
+ this.heartbeatInterval = null;
8
+ }
9
+ connect(url) {
10
+ if (this.socket &&
11
+ (this.socket.readyState === WebSocket.OPEN || this.socket.readyState === WebSocket.CONNECTING)) {
12
+ return;
13
+ }
14
+ this.socket = new WebSocket(url);
15
+ this.socket.onopen = () => {
16
+ var _a;
17
+ (_a = this.onConnectListener) === null || _a === void 0 ? void 0 : _a.call(this);
18
+ this.startHeartbeat();
19
+ };
20
+ this.socket.onmessage = event => {
21
+ var _a, _b;
22
+ try {
23
+ const parsedData = JSON.parse(event.data);
24
+ (_a = this.onMessageListener) === null || _a === void 0 ? void 0 : _a.call(this, parsedData);
25
+ }
26
+ catch (_c) {
27
+ (_b = this.onMessageListener) === null || _b === void 0 ? void 0 : _b.call(this, event.data);
28
+ }
29
+ };
30
+ this.socket.onerror = error => {
31
+ var _a;
32
+ (_a = this.onErrorListener) === null || _a === void 0 ? void 0 : _a.call(this, error);
33
+ };
34
+ this.socket.onclose = () => {
35
+ var _a;
36
+ this.stopHeartbeat();
37
+ (_a = this.onDisconnectListener) === null || _a === void 0 ? void 0 : _a.call(this);
38
+ };
39
+ }
40
+ sendMessage(data) {
41
+ if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
42
+ return false;
43
+ }
44
+ this.socket.send(JSON.stringify(data));
45
+ return true;
46
+ }
47
+ disconnect() {
48
+ if (this.socket) {
49
+ this.socket.close();
50
+ this.socket = null;
51
+ }
52
+ }
53
+ onMessage(listener) {
54
+ this.onMessageListener = listener;
55
+ }
56
+ onError(listener) {
57
+ this.onErrorListener = listener;
58
+ }
59
+ onConnect(listener) {
60
+ this.onConnectListener = listener;
61
+ }
62
+ onDisconnect(listener) {
63
+ this.onDisconnectListener = listener;
64
+ }
65
+ isConnected() {
66
+ var _a;
67
+ return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN;
68
+ }
69
+ startHeartbeat() {
70
+ this.stopHeartbeat();
71
+ this.heartbeatInterval = setInterval(() => {
72
+ this.sendMessage({
73
+ action: 'heartbeat',
74
+ });
75
+ }, 2000);
76
+ }
77
+ stopHeartbeat() {
78
+ if (this.heartbeatInterval) {
79
+ clearInterval(this.heartbeatInterval);
80
+ this.heartbeatInterval = null;
81
+ }
82
+ }
83
+ }
84
+ const webSocketService = new WebSocketService();
85
+ exports.default = webSocketService;
@@ -0,0 +1,19 @@
1
+ declare class ZegoServices {
2
+ private remoteViewHandle;
3
+ private localViewHandle;
4
+ initZegoEngine({ remoteViewHandle, localViewHandle, }: {
5
+ remoteViewHandle: number;
6
+ localViewHandle: number;
7
+ }): Promise<void>;
8
+ loginToRoom(): Promise<void>;
9
+ startPublishingLocalStream(): Promise<void>;
10
+ addZegoListener(): Promise<void>;
11
+ muteMicrophone(mute: boolean): Promise<void>;
12
+ flipCamera(flip: boolean): Promise<void>;
13
+ enableCamera(enable: boolean): Promise<void>;
14
+ muteSpeaker(mute: boolean): Promise<void>;
15
+ sendMessage(message: string): Promise<void>;
16
+ endCall(): Promise<void>;
17
+ }
18
+ declare const zegoService: ZegoServices;
19
+ export default zegoService;
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ const zego_express_engine_reactnative_1 = __importStar(require("zego-express-engine-reactnative"));
49
+ const SessionManager_1 = __importDefault(require("../session/SessionManager"));
50
+ class ZegoServices {
51
+ constructor() {
52
+ this.remoteViewHandle = 0;
53
+ this.localViewHandle = 0;
54
+ }
55
+ initZegoEngine(_a) {
56
+ return __awaiter(this, arguments, void 0, function* ({ remoteViewHandle, localViewHandle, }) {
57
+ var _b, _c, _d;
58
+ this.remoteViewHandle = remoteViewHandle;
59
+ this.localViewHandle = localViewHandle;
60
+ const profile = {
61
+ appID: Number((_b = SessionManager_1.default.getCurrentZegoCall()) === null || _b === void 0 ? void 0 : _b.app_id),
62
+ appSign: '',
63
+ scenario: SessionManager_1.default.currentCallMediaType === 'video'
64
+ ? zego_express_engine_reactnative_1.ZegoScenario.HighQualityVideoCall
65
+ : zego_express_engine_reactnative_1.ZegoScenario.StandardVideoCall,
66
+ };
67
+ yield zego_express_engine_reactnative_1.default.createEngineWithProfile(profile);
68
+ let enableCamera = true;
69
+ if (SessionManager_1.default.currentCallMediaType === 'audio') {
70
+ enableCamera = false;
71
+ }
72
+ else if (SessionManager_1.default.currentCallMediaType === 'video' &&
73
+ ((_d = (_c = SessionManager_1.default.getBrandConfig()) === null || _c === void 0 ? void 0 : _c.behavior) === null || _d === void 0 ? void 0 : _d.defaultCameraCustomer) === false) {
74
+ enableCamera = false;
75
+ }
76
+ yield zego_express_engine_reactnative_1.default.instance().enableCamera(enableCamera, undefined);
77
+ yield this.loginToRoom();
78
+ });
79
+ }
80
+ loginToRoom() {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ var _a, _b, _c, _d, _e;
83
+ const roomConfig = {
84
+ token: ((_a = SessionManager_1.default.getCurrentZegoCall()) === null || _a === void 0 ? void 0 : _a.token) || '',
85
+ isUserStatusNotify: true,
86
+ maxMemberCount: 2,
87
+ };
88
+ const zegoUser = {
89
+ userID: ((_b = SessionManager_1.default.getUser()) === null || _b === void 0 ? void 0 : _b.uuid) || '',
90
+ userName: ((_c = SessionManager_1.default.getUser()) === null || _c === void 0 ? void 0 : _c.name) || 'User',
91
+ };
92
+ const loginResult = yield zego_express_engine_reactnative_1.default.instance().loginRoom(((_d = SessionManager_1.default.getCurrentZegoCall()) === null || _d === void 0 ? void 0 : _d.room_id) || '', zegoUser, roomConfig);
93
+ if (loginResult.errorCode !== 0) {
94
+ (_e = SessionManager_1.default.interactionCallback) === null || _e === void 0 ? void 0 : _e.onError('Failed to join the room');
95
+ return;
96
+ }
97
+ else {
98
+ this.addZegoListener();
99
+ this.startPublishingLocalStream();
100
+ }
101
+ });
102
+ }
103
+ startPublishingLocalStream() {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ try {
106
+ yield zego_express_engine_reactnative_1.default.instance().startPreview({
107
+ reactTag: this.localViewHandle,
108
+ viewMode: 1,
109
+ backgroundColor: 0,
110
+ }, zego_express_engine_reactnative_1.ZegoPublishChannel.Main);
111
+ yield zego_express_engine_reactnative_1.default.instance().startPublishingStream(SessionManager_1.default.localStreamId, undefined, undefined);
112
+ }
113
+ catch (_a) { }
114
+ });
115
+ }
116
+ addZegoListener() {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ const engine = zego_express_engine_reactnative_1.default.instance();
119
+ engine.on('IMRecvBroadcastMessage', (roomId, messageList) => {
120
+ var _a;
121
+ if (Array.isArray(messageList) && messageList.length > 0) {
122
+ const incomingMessage = messageList[0];
123
+ const messageData = {
124
+ messageText: incomingMessage.message,
125
+ name: incomingMessage.fromUser.userName,
126
+ };
127
+ (_a = SessionManager_1.default.interactionCallback) === null || _a === void 0 ? void 0 : _a.onReceivingMessage(messageData);
128
+ }
129
+ });
130
+ engine.on('roomUserUpdate', (roomID, updateType, userList) => {
131
+ var _a;
132
+ if (updateType === zego_express_engine_reactnative_1.ZegoUpdateType.Delete && userList.length <= 1) {
133
+ (_a = SessionManager_1.default.interactionCallback) === null || _a === void 0 ? void 0 : _a.onCallEnded();
134
+ }
135
+ });
136
+ engine.on('roomStreamUpdate', (roomID, updateType, streamList) => __awaiter(this, void 0, void 0, function* () {
137
+ var _a, _b;
138
+ if (updateType === zego_express_engine_reactnative_1.ZegoUpdateType.Add) {
139
+ const stream = streamList === null || streamList === void 0 ? void 0 : streamList[0];
140
+ const remoteStreamID = stream === null || stream === void 0 ? void 0 : stream.streamID;
141
+ if (remoteStreamID === SessionManager_1.default.localStreamId) {
142
+ return;
143
+ }
144
+ try {
145
+ yield engine.startPlayingStream(remoteStreamID, {
146
+ reactTag: this.remoteViewHandle,
147
+ viewMode: 1,
148
+ backgroundColor: 0,
149
+ }, undefined);
150
+ }
151
+ catch (e) {
152
+ (_a = SessionManager_1.default.interactionCallback) === null || _a === void 0 ? void 0 : _a.onError(`${e}`);
153
+ }
154
+ }
155
+ if (updateType === zego_express_engine_reactnative_1.ZegoUpdateType.Delete && streamList.length <= 1) {
156
+ (_b = SessionManager_1.default.interactionCallback) === null || _b === void 0 ? void 0 : _b.onCallEnded();
157
+ }
158
+ }));
159
+ engine.on('networkQuality', (userID, upstreamQuality) => {
160
+ var _a;
161
+ if (userID.trim() !== '') {
162
+ (_a = SessionManager_1.default.interactionCallback) === null || _a === void 0 ? void 0 : _a.onAgentNetworkQuality(upstreamQuality);
163
+ }
164
+ });
165
+ engine.on('remoteCameraStateUpdate', (streamID, state) => {
166
+ var _a;
167
+ const status = state === zego_express_engine_reactnative_1.ZegoRemoteDeviceState.Open;
168
+ (_a = SessionManager_1.default.interactionCallback) === null || _a === void 0 ? void 0 : _a.onRemoteCameraUpdate(status);
169
+ });
170
+ engine.on('remoteMicStateUpdate', (streamID, state) => {
171
+ var _a;
172
+ const status = state !== zego_express_engine_reactnative_1.ZegoRemoteDeviceState.Open;
173
+ (_a = SessionManager_1.default.interactionCallback) === null || _a === void 0 ? void 0 : _a.onRemoteMicUpdate(status);
174
+ });
175
+ });
176
+ }
177
+ muteMicrophone(mute) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ yield zego_express_engine_reactnative_1.default.instance().muteMicrophone(mute);
180
+ });
181
+ }
182
+ flipCamera(flip) {
183
+ return __awaiter(this, void 0, void 0, function* () {
184
+ yield zego_express_engine_reactnative_1.default.instance().useFrontCamera(flip, undefined);
185
+ });
186
+ }
187
+ enableCamera(enable) {
188
+ return __awaiter(this, void 0, void 0, function* () {
189
+ yield zego_express_engine_reactnative_1.default.instance().enableCamera(enable, undefined);
190
+ });
191
+ }
192
+ muteSpeaker(mute) {
193
+ return __awaiter(this, void 0, void 0, function* () {
194
+ yield zego_express_engine_reactnative_1.default.instance().muteSpeaker(mute);
195
+ });
196
+ }
197
+ sendMessage(message) {
198
+ return __awaiter(this, void 0, void 0, function* () {
199
+ var _a;
200
+ yield zego_express_engine_reactnative_1.default.instance().sendBroadcastMessage(((_a = SessionManager_1.default.getCurrentZegoCall()) === null || _a === void 0 ? void 0 : _a.room_id) || '', message);
201
+ });
202
+ }
203
+ endCall() {
204
+ return __awaiter(this, void 0, void 0, function* () {
205
+ var _a;
206
+ try {
207
+ const engine = zego_express_engine_reactnative_1.default.instance();
208
+ yield engine.logoutRoom(((_a = SessionManager_1.default.getCurrentZegoCall()) === null || _a === void 0 ? void 0 : _a.room_id) || '');
209
+ yield zego_express_engine_reactnative_1.default.destroyEngine();
210
+ }
211
+ catch (_b) { }
212
+ });
213
+ }
214
+ }
215
+ const zegoService = new ZegoServices();
216
+ exports.default = zegoService;
@@ -0,0 +1,36 @@
1
+ import { CallInteractionCallback } from '../callbacks/callbacks';
2
+ import { Call, MediaType, User, ZegoCall } from '../types/types';
3
+ declare class SessionManager {
4
+ private static instance;
5
+ private user;
6
+ private currentCall;
7
+ private currentZegoCall;
8
+ currentCallMediaType: MediaType;
9
+ localStreamId: string;
10
+ private companyId;
11
+ private debug;
12
+ private brandConfig;
13
+ interactionCallback: CallInteractionCallback | null;
14
+ product_url: string | null;
15
+ private constructor();
16
+ static getInstance(): SessionManager;
17
+ setUser(user: User): void;
18
+ getUser(): User | null;
19
+ clearUser(): void;
20
+ setCurrentCall(call: Call): void;
21
+ getCurrentCall(): Call | null;
22
+ setCurrentZegoCall(call: ZegoCall): void;
23
+ getCurrentZegoCall(): ZegoCall | null;
24
+ clearCall(): void;
25
+ initialize(config: {
26
+ companyId: string;
27
+ debug?: boolean;
28
+ }): void;
29
+ getCompanyId(): string;
30
+ isDebug(): boolean;
31
+ setBrandConfig(data: Record<string, any>): void;
32
+ getBrandConfig(): Record<string, any>;
33
+ clear(): void;
34
+ }
35
+ declare const _default: SessionManager;
36
+ export default _default;