Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
export function requestJoinOptions (i) { | ||
return { requestNumber: i }; | ||
} | ||
import { Client } from "colyseus.js"; | ||
|
||
export function onJoin () { | ||
console.log(this.sessionId, "joined."); | ||
|
||
this.onMessage("*", (type, message) => { | ||
console.log(this.sessionId, "received:", type, message); | ||
export async function main(options) { | ||
const client = new Client(options.endpoint); | ||
const room = await client.joinOrCreate(options.roomName, { | ||
// your join options here... | ||
}); | ||
} | ||
|
||
export function onLeave () { | ||
console.log(this.sessionId, "left."); | ||
} | ||
console.log("joined successfully!"); | ||
|
||
export function onError (err) { | ||
console.log(this.sessionId, "!! ERROR !!", err.message); | ||
} | ||
room.onMessage("message-type", (payload) => { | ||
// logic | ||
}); | ||
|
||
export function onStateChange (state) { | ||
console.log(this.sessionId, "new state:", state); | ||
} | ||
room.onStateChange((state) => { | ||
console.log("state change:", state); | ||
}); | ||
|
||
room.onLeave((code) => { | ||
console.log("left"); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
exports.requestJoinOptions = function (i) { | ||
return { requestNumber: i }; | ||
} | ||
const Colyseus = require("colyseus.js"); | ||
|
||
exports.onJoin = function () { | ||
console.log(this.sessionId, "joined."); | ||
|
||
this.onMessage("*", (type, message) => { | ||
console.log(this.sessionId, "received:", type, message); | ||
export async function main(options) { | ||
const client = new Colyseus.Client(options.endpoint); | ||
const room = await client.joinOrCreate(options.roomName, { | ||
// your join options here... | ||
}); | ||
} | ||
|
||
exports.onLeave = function () { | ||
console.log(this.sessionId, "left."); | ||
} | ||
console.log("joined successfully!"); | ||
|
||
exports.onError = function (err) { | ||
console.log(this.sessionId, "!! ERROR !!", err.message); | ||
} | ||
room.onMessage("message-type", (payload) => { | ||
// logic | ||
}); | ||
|
||
exports.onStateChange = function (state) { | ||
console.log(this.sessionId, "new state:", state); | ||
} | ||
room.onStateChange((state) => { | ||
console.log("state change:", state); | ||
}); | ||
|
||
room.onLeave((code) => { | ||
console.log("left"); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
exports.requestJoinOptions = function (i) { | ||
return { requestNumber: i }; | ||
} | ||
const Colyseus = require("colyseus.js"); | ||
|
||
exports.onJoin = function () { | ||
console.log(this.sessionId, "joined."); | ||
|
||
this.onMessage("*", (type, message) => { | ||
console.log(this.sessionId, "received:", type, message); | ||
export async function main(options) { | ||
const client = new Colyseus.Client(options.endpoint); | ||
const room = await client.joinOrCreate(options.roomName, { | ||
// your join options here... | ||
}); | ||
} | ||
|
||
exports.onLeave = function () { | ||
console.log(this.sessionId, "left."); | ||
} | ||
console.log("joined successfully!"); | ||
|
||
exports.onError = function (err) { | ||
console.log(this.sessionId, "!! ERROR !!", err.message); | ||
} | ||
room.onMessage("message-type", (payload) => { | ||
// logic | ||
}); | ||
|
||
exports.onStateChange = function (state) { | ||
console.log(this.sessionId, "new state:", state); | ||
} | ||
room.onStateChange((state) => { | ||
console.log("state change:", state); | ||
}); | ||
|
||
room.onLeave((code) => { | ||
console.log("left"); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,23 @@ | ||
import { Room, Client } from "colyseus.js"; | ||
import { Client, Room } from "colyseus.js"; | ||
import { Options } from "@colyseus/loadtest"; | ||
|
||
export function requestJoinOptions (this: Client, i: number) { | ||
return { requestNumber: i }; | ||
} | ||
export async function main(options: Options) { | ||
const client = new Client(options.endpoint); | ||
const room: Room = await client.joinOrCreate(options.roomName, { | ||
// your join options here... | ||
}); | ||
|
||
export function onJoin(this: Room) { | ||
console.log(this.sessionId, "joined."); | ||
console.log("joined successfully!"); | ||
|
||
this.onMessage("*", (type, message) => { | ||
console.log(this.sessionId, "received:", type, message); | ||
room.onMessage("message-type", (payload) => { | ||
// logic | ||
}); | ||
} | ||
|
||
export function onLeave(this: Room) { | ||
console.log(this.sessionId, "left."); | ||
} | ||
|
||
export function onError(this: Room, err: any) { | ||
console.log(this.sessionId, "!! ERROR !!", err.message); | ||
} | ||
room.onStateChange((state) => { | ||
console.log("state change:", state); | ||
}); | ||
|
||
export function onStateChange(this: Room, state: any) { | ||
console.log(this.sessionId, "new state:", state); | ||
} | ||
room.onLeave((code) => { | ||
console.log("left"); | ||
}); | ||
} |