MWSE/docs/readme.md

46 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## Kurulum
Proje ortamına kurulumu
```html
<script src="https://ws.saqut.com/script"></script>
```
Geliştirme ortamına kurulumu
```javascript
const wsjs = new MWSE({
endpoint: "https://ws.saqut.com/" // Bağlanılacak sunucuyu belirtir
});
wsjs.scope(async () => {
// Bağlantı sağlandığında burası tetiklenir
})
```
Kendi bağlantı kimliğini öğrenme
```
wsjs.scope(async () => {
let me = wsjs.peer('me'); // kendimizden bahsederken 'me' anahtar kelimesini kullanırız
console.log(me.socketId); // her peerin socketId'si olması gerekir
})
```
Farklı bir eş ile iletişime geçme
```
wsjs.scope(async () => {
let peer = wsjs.peer('325a8f7f-eaaf-4c21-855e-9e965c0d5ac9') // Diğer eşin socketId'sini belirtiyoruz
peer.on('message',(payload) => {
// Eş eğer mesaj gönderirse burası tetiklenecek ve gönderdiği mesaj payload değişkeni ile iletilir
})
// Mesaj göndermek için send fonksiyonunu kullanabilirsiniz
peer.send('Merhaba');
peer.send([29, true]);
peer.send({
type: 'notification',
value: "Hi!"
});
})
```