[test] peer fix
This commit is contained in:
@@ -25,9 +25,14 @@ export async function createMultiuserRoom(){
|
|||||||
roomId + "-risuai-multiuser"
|
roomId + "-risuai-multiuser"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
alertWait("Waiting for peerserver to connect...")
|
||||||
|
let open = false
|
||||||
|
peer.on('open', function(id) {
|
||||||
|
open = true
|
||||||
|
});
|
||||||
peer.on('connection', function(conn) {
|
peer.on('connection', function(conn) {
|
||||||
connections.push(conn)
|
connections.push(conn)
|
||||||
console.log("new connection")
|
console.log("new connection", conn)
|
||||||
function requestChar(){
|
function requestChar(){
|
||||||
const db = get(DataBase)
|
const db = get(DataBase)
|
||||||
const selectedCharId = get(selectedCharID)
|
const selectedCharId = get(selectedCharID)
|
||||||
@@ -41,7 +46,6 @@ export async function createMultiuserRoom(){
|
|||||||
data: char
|
data: char
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
requestChar()
|
|
||||||
|
|
||||||
conn.on('data', function(data:ReciveData) {
|
conn.on('data', function(data:ReciveData) {
|
||||||
if(data.type === 'request-char'){
|
if(data.type === 'request-char'){
|
||||||
@@ -60,6 +64,9 @@ export async function createMultiuserRoom(){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
while(!open){
|
||||||
|
await sleep(100)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
alertNormal("Room ID: " + roomId)
|
alertNormal("Room ID: " + roomId)
|
||||||
@@ -86,12 +93,18 @@ export async function joinMultiuserRoom(){
|
|||||||
v4() + "-risuai-multiuser-join"
|
v4() + "-risuai-multiuser-join"
|
||||||
)
|
)
|
||||||
|
|
||||||
conn = peer.connect(roomId + '-risuai-multiuser');
|
alertWait("Waiting for peerserver to connect...")
|
||||||
|
|
||||||
alertWait("Waiting for host to accept connection")
|
|
||||||
|
|
||||||
let open = false
|
let open = false
|
||||||
conn.on('open', function() {
|
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) {
|
conn.on('data', function(data:ReciveData) {
|
||||||
switch(data.type){
|
switch(data.type){
|
||||||
case 'receive-char':{
|
case 'receive-char':{
|
||||||
@@ -117,7 +130,6 @@ export async function joinMultiuserRoom(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
let waitTime = 0
|
let waitTime = 0
|
||||||
while(!open){
|
while(!open){
|
||||||
@@ -128,6 +140,7 @@ export async function joinMultiuserRoom(){
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
alertNormal("Connected")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
peer, roomId, conn
|
peer, roomId, conn
|
||||||
|
|||||||
Reference in New Issue
Block a user