mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 06:28:51 +00:00
feat(camera): refactor to new promise event format
This commit is contained in:
1 parent
1566bb0fdb
commit
4e8c57492b
15 files changed
+274
-141
No files matched your search
@@ -105,6 +105,14 @@ export class AnimationService {
|
||||
this.setPhoneState(AnimationState.ON_CALL, false);
|
||||
}
|
||||
|
||||
async openCamera() {
|
||||
this.setPhoneState(AnimationState.ON_CAMERA, true);
|
||||
}
|
||||
|
||||
async closeCamera() {
|
||||
this.setPhoneState(AnimationState.ON_CAMERA, false);
|
||||
}
|
||||
|
||||
private async loadAnimDict(dict: any) {
|
||||
//-- Loads the animation dict. Used in the anim functions.
|
||||
RequestAnimDict(dict);
|
||||
@@ -190,5 +198,5 @@ export class AnimationService {
|
||||
await this.loadAnimDict(DICT);
|
||||
TaskPlayAnim(playerPed, DICT, ANIM, 2.5, 8.0, -1, 50, 0, false, false, false);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -139,12 +139,6 @@ on(`__cfx_nui:${PhoneEvents.OPEN_APP_BANK}`, (data: any, cb: Function) => {
|
||||
cb();
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(PhoneEvents.OPEN_APP_CAMERA);
|
||||
on(`__cfx_nui:${PhoneEvents.OPEN_APP_CAMERA}`, (data: any, cb: Function) => {
|
||||
emitNet(PhotoEvents.FETCH_PHOTOS);
|
||||
cb();
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(PhoneEvents.OPEN_APP_DAILER);
|
||||
on(`__cfx_nui:${PhoneEvents.OPEN_APP_DAILER}`, (data: any, cb: Function) => {
|
||||
emitNet(CallEvents.FETCH_CALLS);
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { GalleryPhoto, PhotoEvents } from '../../typings/photo';
|
||||
import { Delay } from '../utils/fivem';
|
||||
import { sendMessage, sendCameraEvent } from '../utils/messages';
|
||||
import { sendCameraEvent, sendMessage } from '../utils/messages';
|
||||
import { PhoneEvents } from '../../typings/phone';
|
||||
import { ClUtils } from './client';
|
||||
import { animationService } from './animations/animation.controller';
|
||||
import { RegisterNuiProxy } from './cl_utils';
|
||||
|
||||
const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none');
|
||||
|
||||
const exp = (global as any).exports;
|
||||
@@ -29,10 +33,10 @@ const displayHelperText = () => {
|
||||
EndTextCommandDisplayHelp(0, true, false, -1);
|
||||
};
|
||||
|
||||
|
||||
RegisterNuiCallbackType(PhotoEvents.TAKE_PHOTO);
|
||||
on(`__cfx_nui:${PhotoEvents.TAKE_PHOTO}`, async (data: any, cb: Function) => {
|
||||
cb();
|
||||
/*cb();*/
|
||||
await animationService.openCamera();
|
||||
emit('npwd:disableControlActions', false);
|
||||
// Create Phone Prop
|
||||
let frontCam = false;
|
||||
@@ -52,27 +56,31 @@ on(`__cfx_nui:${PhotoEvents.TAKE_PHOTO}`, async (data: any, cb: Function) => {
|
||||
frontCam = !frontCam;
|
||||
CellFrontCamActivate(frontCam);
|
||||
} else if (IsControlJustPressed(1, 176)) {
|
||||
await handleTakePicture();
|
||||
const resp = await handleTakePicture();
|
||||
|
||||
cb(resp);
|
||||
} else if (IsControlJustPressed(1, 177)) {
|
||||
handleCameraExit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
displayHelperText();
|
||||
}
|
||||
ClearHelp(true);
|
||||
emit('npwd:disableControlActions', true);
|
||||
await animationService.closeCamera();
|
||||
});
|
||||
|
||||
const handleTakePicture = async () => {
|
||||
// Wait a frame so we don't draw the display helper text
|
||||
await Delay(0);
|
||||
takePhoto();
|
||||
const resp = await takePhoto();
|
||||
await Delay(200);
|
||||
DestroyMobilePhone();
|
||||
CellCamActivate(false, false);
|
||||
openPhoneTemp();
|
||||
sendCameraEvent(PhotoEvents.UPLOAD_PHOTO, true);
|
||||
inCameraMode = false;
|
||||
|
||||
return resp;
|
||||
};
|
||||
|
||||
const handleCameraExit = () => {
|
||||
@@ -87,46 +95,41 @@ onNet(PhotoEvents.SEND_PHOTOS, (photos: string[]) => {
|
||||
sendCameraEvent(PhotoEvents.SEND_PHOTOS, photos);
|
||||
});
|
||||
|
||||
function takePhoto() {
|
||||
// Return and log error if screenshot basic token not found
|
||||
if (SCREENSHOT_BASIC_TOKEN === 'none') {
|
||||
return console.error('Screenshot basic token not found. Please set in server.cfg');
|
||||
}
|
||||
exp['screenshot-basic'].requestScreenshotUpload(
|
||||
'https://api.imgur.com/3/image',
|
||||
'imgur',
|
||||
{
|
||||
headers: {
|
||||
authorization: `Client-ID ${SCREENSHOT_BASIC_TOKEN}`,
|
||||
'content-type': 'multipart/form-data',
|
||||
const takePhoto = () =>
|
||||
new Promise((res, rej) => {
|
||||
// Return and log error if screenshot basic token not found
|
||||
if (SCREENSHOT_BASIC_TOKEN === 'none') {
|
||||
return console.error('Screenshot basic token not found. Please set in server.cfg');
|
||||
}
|
||||
exp['screenshot-basic'].requestScreenshotUpload(
|
||||
'https://api.imgur.com/3/image',
|
||||
'imgur',
|
||||
{
|
||||
headers: {
|
||||
authorization: `Client-ID ${SCREENSHOT_BASIC_TOKEN}`,
|
||||
'content-type': 'multipart/form-data',
|
||||
},
|
||||
},
|
||||
},
|
||||
(data: string) => {
|
||||
try {
|
||||
const imageLink = JSON.parse(data).data.link;
|
||||
emitNet(PhotoEvents.UPLOAD_PHOTO, imageLink);
|
||||
} catch (e) {
|
||||
sendCameraEvent(PhotoEvents.TAKE_PHOTO_ERROR, 'APPS_CAMERA_FAILED_TO_TAKE_PHOTO');
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
async (data: any) => {
|
||||
try {
|
||||
const imageLink = JSON.parse(data).data.link;
|
||||
|
||||
onNet(PhotoEvents.UPLOAD_PHOTO_SUCCESS, (photo: GalleryPhoto) => {
|
||||
if (photo && photo.image) {
|
||||
return sendCameraEvent(PhotoEvents.TAKE_PHOTO_SUCCESS, photo);
|
||||
}
|
||||
sendCameraEvent(PhotoEvents.TAKE_PHOTO_ERROR, 'APPS_CAMERA_FAILED_TO_TAKE_PHOTO');
|
||||
});
|
||||
const resp = await ClUtils.emitNetPromise(PhotoEvents.UPLOAD_PHOTO, imageLink);
|
||||
console.log('export shit', resp);
|
||||
res(resp);
|
||||
} catch (e) {
|
||||
rej(e.message);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
// delete photo
|
||||
RegisterNuiProxy(PhotoEvents.FETCH_PHOTOS);
|
||||
|
||||
RegisterNuiCallbackType(PhotoEvents.DELETE_PHOTO);
|
||||
on(`__cfx_nui:${PhotoEvents.DELETE_PHOTO}`, (data: any, cb: Function) => {
|
||||
emitNet(PhotoEvents.DELETE_PHOTO, data);
|
||||
cb();
|
||||
});
|
||||
|
||||
onNet(PhotoEvents.DELETE_PHOTO_SUCCESS, () => {
|
||||
emitNet(PhotoEvents.FETCH_PHOTOS);
|
||||
on(`__cfx_nui:${PhotoEvents.DELETE_PHOTO}`, async (data: GalleryPhoto, cb: Function) => {
|
||||
console.log('my data', data);
|
||||
/*emitNet(PhotoEvents.DELETE_PHOTO, data);*/
|
||||
const resp = await ClUtils.emitNetPromise(PhotoEvents.DELETE_PHOTO, data);
|
||||
cb(resp);
|
||||
});
|
||||
Reference in new issue
Block a user