P2: Add multiplayer session

This commit is contained in:
LoveEevee
2018-11-02 01:05:18 +03:00
parent b85f879ba0
commit 426bc160c6
14 changed files with 635 additions and 61 deletions

View File

@@ -4,7 +4,6 @@ class Loader{
this.loadedAssets = 0
this.assetsDiv = document.getElementById("assets")
this.canvasTest = new CanvasTest()
p2 = new P2Connection()
this.startTime = +new Date
this.ajax("src/views/loader.html").then(this.run.bind(this))
@@ -97,6 +96,24 @@ class Loader{
}
}))
if(location.hash.length === 6){
this.promises.push(new Promise(resolve => {
p2.open()
pageEvents.add(p2, "message", response => {
if(response.type === "session"){
resolve()
}else if(response.type === "gameend"){
p2.hash("")
p2.hashLock = false
resolve()
}
})
p2.send("invite", location.hash.slice(1).toLowerCase())
}).then(() => {
pageEvents.remove(p2, "message")
}))
}
this.promises.forEach(promise => {
promise.then(this.assetLoaded.bind(this))
})