setup notification for kurir pengiriman barang
This commit is contained in:
commit
91607a8c52
|
@ -0,0 +1,175 @@
|
|||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||
|
||||
# Logs
|
||||
|
||||
logs
|
||||
_.log
|
||||
npm-debug.log_
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Caches
|
||||
|
||||
.cache
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
|
||||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||
|
||||
# Runtime data
|
||||
|
||||
pids
|
||||
_.pid
|
||||
_.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
|
||||
.temp
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# IntelliJ based IDEs
|
||||
.idea
|
||||
|
||||
# Finder (MacOS) folder config
|
||||
.DS_Store
|
|
@ -0,0 +1,2 @@
|
|||
{
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "kurir-server-socket-io",
|
||||
"version": "1.0.0",
|
||||
"description": "Socket-io",
|
||||
"main": "./socket.ts",
|
||||
"scripts": {
|
||||
"dev": "nodemon ./socket.ts",
|
||||
"start": "ts-node ./socket.ts",
|
||||
"build": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^5.1.0",
|
||||
"socket.io": "^4.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^5.0.2",
|
||||
"@types/node": "^20.4.2",
|
||||
"nodemon": "^3.0.0",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
import express from 'express';
|
||||
import http from 'http';
|
||||
import { Server, Socket } from 'socket.io';
|
||||
import path from 'path';
|
||||
|
||||
const app = express();
|
||||
const server = http.createServer(app);
|
||||
|
||||
const io = new Server(server, {
|
||||
cors: {
|
||||
origin: "*", // Allow all origins (for development)
|
||||
methods: ["GET", "POST"]
|
||||
}
|
||||
});
|
||||
|
||||
// Socket.IO events
|
||||
io.on('connection', (socket: Socket) => {
|
||||
console.log('✅ A user connected:', socket.id);
|
||||
|
||||
// pengiriman baru ke admin
|
||||
socket.on('pengiriman_baru_server', (data: any) => {
|
||||
|
||||
// Echo the data back to all clients
|
||||
io.emit('pengiriman_baru_client', "coba");
|
||||
});
|
||||
|
||||
// pembatalan paket dari admin ke user
|
||||
socket.on("pembatalan_paket", (data: any) => {
|
||||
console.log(data);
|
||||
io.emit("pembatalan_paket_"+data.id_pengirim, data);
|
||||
})
|
||||
|
||||
// pembatalan paket dari kurir ke user
|
||||
socket.on("pembatalan_paket_kurir", (data: any) => {
|
||||
console.log(data, "pembatalan_paket_kurir");
|
||||
io.emit("pembatalan_paket_kurir", data);
|
||||
io.emit("pembatalan_paket_kurir_"+data.id_pengirim, data);
|
||||
})
|
||||
|
||||
// penugaskan kurir dan notif ke user
|
||||
socket.on("tugaskan_kurir_server", (data: any) => {
|
||||
console.log(data);
|
||||
|
||||
io.emit("kurir_ditugaskan_"+data.id_pengirim, data); // hantar notif kepada user
|
||||
io.emit("kurir_ditugaskan_"+data.id_kurir, data); // hantar notif kepada kurir
|
||||
|
||||
// io.emit("pembatalan_paket_"+data.id_pengirim, data);
|
||||
})
|
||||
|
||||
// kuris ditugaskan dan dalam perjalanan mengambil pake , notif ke user dan admin
|
||||
socket.on("kurir_mengambil_pengiriman", (data: any) => {
|
||||
console.log("kurir_mengambil_pengiriman",data);
|
||||
|
||||
io.emit("kurir_mengambil_pengiriman_"+data.id_pengirim, data); // hantar notif kepada user
|
||||
io.emit("kurir_mengambil_pengiriman_admin", data); // hantar notif kepada admin
|
||||
})
|
||||
|
||||
// kurir mengambil paket dari pengirim dan menghantar ke alamat penerima, notif ke user dan admin
|
||||
socket.on("kurir_menghantar_ke_penerima", (data: any) => {
|
||||
console.log("kurir_menghantar_ke_penerima",data);
|
||||
|
||||
io.emit("kurir_menghantar_ke_penerima_"+data.id_pengirim, data); // hantar notif kepada user
|
||||
io.emit("kurir_menghantar_ke_penerima_admin", data); // hantar notif kepada admin
|
||||
})
|
||||
|
||||
// user verifikasi penerimaan paket, mengirim notifikasi kepada admin
|
||||
socket.on("diterima_terverifikasi", (data: any) => {
|
||||
console.log("diterima_terverifikasi",data);
|
||||
|
||||
io.emit("diterima_terverifikasi_admin", data); // hantar notif kepada admin
|
||||
})
|
||||
|
||||
// user verifikasi penerimaan paket, mengirim notifikasi kepada admin
|
||||
socket.on("delete_kiriman", (data: any) => {
|
||||
console.log("delete_kiriman",data);
|
||||
|
||||
io.emit("delete_kiriman_admin", data); // hantar notif kepada admin
|
||||
})
|
||||
|
||||
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log('❌ User disconnected:', socket.id);
|
||||
});
|
||||
});
|
||||
|
||||
const PORT = 3014;
|
||||
server.listen(PORT, () => {
|
||||
console.log(`🚀 Socket.IO server running on http://localhost:${PORT}`);
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "node",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
// "outDir": "dist",
|
||||
// "rootDir": "src",
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["./**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
Loading…
Reference in New Issue