Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
M
mangala-pardusacikhack
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Tuğba Fıçıcı
mangala-pardusacikhack
Commits
d393a461
Kaydet (Commit)
d393a461
authored
May 05, 2021
tarafından
Abdülkerim AKSAK
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
oda olusturma ve odaya giris yapma eklendi
üst
186f6db8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
clientApp.js
pages/clientApp.js
+32
-0
server.js
socketIOServer/server.js
+22
-0
No files found.
pages/clientApp.js
Dosyayı görüntüle @
d393a461
...
...
@@ -4,6 +4,38 @@ const io = require("socket.io-client");
//Connect
let
game
=
io
.
connect
(
"http://localhost:3030/game"
);
const
username
=
"Kerim"
;
// server kontrol
game
.
on
(
"welcome"
,
(
data
)
=>
{
console
.
log
(
data
);
});
// ODA OLUSTUR
let
randomKey
=
Math
.
random
().
toString
(
36
).
substr
(
2
,
5
);
// odalar için random key
const
odaOlusturContainer
=
document
.
getElementById
(
"odaOlustur"
);
const
odaOlusturBtn
=
document
.
getElementById
(
"odaOlusturBtn"
);
odaOlusturBtn
.
onclick
=
()
=>
{
let
elemt
=
document
.
createElement
(
"p"
);
//Server kısmında key adında oda olustur.
game
.
emit
(
"odaOlustur"
,
randomKey
);
game
.
on
(
"odaBasariliSekildeOlusturuldu"
,
(
odaninKeyDegeri
)
=>
{
elemt
.
textContent
=
odaninKeyDegeri
+
" odası oluşturuldu."
;
});
odaOlusturContainer
.
appendChild
(
elemt
);
let
elemt2
=
document
.
createElement
(
"p"
);
game
.
emit
(
"joinRoom"
,
randomKey
,
username
);
game
.
on
(
"success"
,
(
key
)
=>
{
elemt2
.
textContent
=
key
+
" odasına giriş yapıldı."
;
});
game
.
on
(
"err"
,
(
key
)
=>
{
elemt2
.
textContent
=
key
+
" odasına giriş yapılamadı."
;
});
odaOlusturContainer
.
appendChild
(
elemt2
);
let
elemt3
=
document
.
createElement
(
"p"
);
game
.
on
(
"newUser"
,
(
username
)
=>
{
elemt3
.
textContent
=
username
+
" odaya katıldı."
;
});
odaOlusturContainer
.
appendChild
(
elemt3
);
};
socketIOServer/server.js
Dosyayı görüntüle @
d393a461
...
...
@@ -6,8 +6,30 @@ const http = require("http").createServer();
const
io
=
require
(
"socket.io"
)(
http
);
var
gameRooms
=
[];
// Kullanıcıların oluşturmuş oldukları odalar
io
.
of
(
"/game"
).
on
(
"connection"
,
(
socket
)
=>
{
socket
.
emit
(
"welcome"
,
"hello to <namespcaess>"
);
// Oda Oluşturma
socket
.
on
(
"odaOlustur"
,
function
(
roomKey
)
{
gameRooms
.
push
(
roomKey
);
//oda için oluşturulan key
console
.
log
(
`"
${
roomKey
}
" odasi olusturuldu.`
);
return
socket
.
emit
(
"odaBasariliSekildeOlusturuldu"
,
roomKey
);
});
// Odaya katılma
socket
.
on
(
"joinRoom"
,
(
roomKey
,
username
)
=>
{
if
(
gameRooms
.
includes
(
roomKey
))
{
socket
.
join
(
roomKey
);
io
.
of
(
"/chat"
).
in
(
roomKey
).
emit
(
"newUser"
,
username
);
//odaya biri girdiğinde tetiklenir
console
.
log
(
`"
${
roomKey
}
" odasina "
${
username
}
giris yapti.`
);
return
socket
.
emit
(
"success"
,
roomKey
);
//eğer gameRooms içinde oda varsa (1)
}
else
{
console
.
log
(
`"
${
roomKey
}
" odasina "
${
username
}
" giris yapilamadi.`
);
return
socket
.
emit
(
"err"
,
roomKey
);
}
});
});
http
.
listen
(
port
,
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment