2019-06-28 01:14:59 +02:00
|
|
|
const socketCluster = require("socketcluster-client")
|
|
|
|
const EventEmitter = require("events").EventEmitter;
|
|
|
|
class PRClient extends EventEmitter {
|
|
|
|
constructor(credentials, options) {
|
|
|
|
super()
|
|
|
|
EventEmitter.call(this);
|
|
|
|
this.options = options;
|
|
|
|
this.socket;
|
|
|
|
this.channels = {};
|
|
|
|
this.credentials = credentials
|
|
|
|
}
|
|
|
|
connect() {
|
|
|
|
if (!this.options) {
|
|
|
|
this.options = {
|
|
|
|
path: "/socketcluster/",
|
|
|
|
hostname: "www.pianorhythm.me",
|
|
|
|
port: 443,
|
|
|
|
secure: true,
|
|
|
|
autoReconnect: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Initiate the connection to the server
|
|
|
|
this.socket = socketCluster.connect(this.options);
|
|
|
|
this.socket.connect();
|
|
|
|
this.socket.on("error", (msg) => {
|
2022-01-04 05:40:43 +01:00
|
|
|
handleError(msg, "pr socket");
|
2019-06-28 01:14:59 +02:00
|
|
|
})
|
|
|
|
this.socket.on("connect", () => {
|
|
|
|
console.log("Connected!")
|
|
|
|
this.socket.emit("enableAuthLogin", {
|
|
|
|
enable: true,
|
|
|
|
roomName: this.credentials.roomName
|
|
|
|
});
|
|
|
|
this.socket.emit("enableCursor", {
|
|
|
|
enable: true
|
|
|
|
});
|
|
|
|
this.socket.emit("login", {
|
|
|
|
password: this.credentials.password,
|
|
|
|
roomName: this.credentials.roomName,
|
|
|
|
username: this.credentials.username
|
|
|
|
});
|
|
|
|
this.socket.emit("getPlayerStats", {
|
|
|
|
"username": this.credentials.username
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = PRClient;
|