[test] p2p
This commit is contained in:
@@ -85,7 +85,6 @@ type ReciveData = ReciveFirst|RequestFirst
|
|||||||
|
|
||||||
export async function joinMultiuserRoom(){
|
export async function joinMultiuserRoom(){
|
||||||
|
|
||||||
const roomId = await alertInput("Enter room id")
|
|
||||||
//join a room with webrtc
|
//join a room with webrtc
|
||||||
alertWait("Loading...")
|
alertWait("Loading...")
|
||||||
const peerJS = await importPeerJS();
|
const peerJS = await importPeerJS();
|
||||||
@@ -93,58 +92,57 @@ export async function joinMultiuserRoom(){
|
|||||||
v4() + "-risuai-multiuser-join"
|
v4() + "-risuai-multiuser-join"
|
||||||
)
|
)
|
||||||
|
|
||||||
alertWait("Waiting for peerserver to connect...")
|
peer.on('open', async (id) => {
|
||||||
|
const roomId = await alertInput("Enter room id")
|
||||||
let open = false
|
alertWait("Waiting for peerserver to connect...")
|
||||||
conn.on('open', function() {
|
|
||||||
alertWait("Waiting for host to accept connection")
|
|
||||||
conn = peer.connect(roomId + '-risuai-multiuser');
|
|
||||||
open = true
|
|
||||||
conn.send({
|
|
||||||
type: 'request-char'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
conn.on('data', function(data:ReciveData) {
|
let open = false
|
||||||
switch(data.type){
|
conn.on('open', function() {
|
||||||
case 'receive-char':{
|
alertWait("Waiting for host to accept connection")
|
||||||
//create temp character
|
conn = peer.connect(roomId + '-risuai-multiuser');
|
||||||
const db = get(DataBase)
|
open = true
|
||||||
const cha = data.data
|
conn.send({
|
||||||
cha.chaId = '§temp'
|
type: 'request-char'
|
||||||
cha.chatPage = 0
|
})
|
||||||
const ind = findCharacterIndexbyId('§temp')
|
});
|
||||||
const selectedcharIndex = get(selectedCharID)
|
|
||||||
if(ind === -1){
|
conn.on('data', function(data:ReciveData) {
|
||||||
db.characters.push(cha)
|
switch(data.type){
|
||||||
|
case 'receive-char':{
|
||||||
|
//create temp character
|
||||||
|
const db = get(DataBase)
|
||||||
|
const cha = data.data
|
||||||
|
cha.chaId = '§temp'
|
||||||
|
cha.chatPage = 0
|
||||||
|
const ind = findCharacterIndexbyId('§temp')
|
||||||
|
const selectedcharIndex = get(selectedCharID)
|
||||||
|
if(ind === -1){
|
||||||
|
db.characters.push(cha)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
db.characters[ind] = cha
|
||||||
|
}
|
||||||
|
const tempInd = findCharacterIndexbyId('§temp')
|
||||||
|
if(selectedcharIndex !== tempInd){
|
||||||
|
selectedCharID.set(tempInd)
|
||||||
|
}
|
||||||
|
setDatabase(db)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
db.characters[ind] = cha
|
|
||||||
}
|
|
||||||
const tempInd = findCharacterIndexbyId('§temp')
|
|
||||||
if(selectedcharIndex !== tempInd){
|
|
||||||
selectedCharID.set(tempInd)
|
|
||||||
}
|
|
||||||
setDatabase(db)
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
let waitTime = 0
|
||||||
|
while(!open){
|
||||||
|
await sleep(100)
|
||||||
|
waitTime += 100
|
||||||
|
if(waitTime > 10000){
|
||||||
|
alertError("Connection timed out")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alertNormal("Connected")
|
||||||
});
|
});
|
||||||
|
|
||||||
let waitTime = 0
|
|
||||||
while(!open){
|
|
||||||
await sleep(100)
|
|
||||||
waitTime += 100
|
|
||||||
if(waitTime > 10000){
|
|
||||||
alertError("Connection timed out")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
alertNormal("Connected")
|
|
||||||
|
|
||||||
return {
|
|
||||||
peer, roomId, conn
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user