@xmcl/client
Advanced tools
Comparing version 3.0.2 to 3.1.0
@@ -43,2 +43,3 @@ "use strict"; | ||
LAN_MULTICAST_ADDR: () => LAN_MULTICAST_ADDR, | ||
LAN_MULTICAST_ADDR_V6: () => LAN_MULTICAST_ADDR_V6, | ||
LAN_MULTICAST_PORT: () => LAN_MULTICAST_PORT, | ||
@@ -729,2 +730,3 @@ Long: () => Long, | ||
var LAN_MULTICAST_ADDR = "224.0.2.60"; | ||
var LAN_MULTICAST_ADDR_V6 = "FF75:230::60"; | ||
var LAN_MULTICAST_PORT = 4445; | ||
@@ -734,11 +736,13 @@ var MinecraftLanDiscover = class extends import_events2.EventEmitter { | ||
#ready = false; | ||
#group; | ||
get isReady() { | ||
return this.#ready; | ||
} | ||
constructor() { | ||
constructor(type = "udp4") { | ||
super(); | ||
const sock = (0, import_dgram.createSocket)({ type: "udp4", reuseAddr: true }); | ||
const sock = (0, import_dgram.createSocket)({ type, reuseAddr: true }); | ||
this.#group = type === "udp4" ? LAN_MULTICAST_ADDR : LAN_MULTICAST_ADDR_V6; | ||
sock.on("listening", () => { | ||
const address = sock.address(); | ||
sock.addMembership(LAN_MULTICAST_ADDR, address.address); | ||
sock.addMembership(this.#group, address.address); | ||
sock.setMulticastTTL(128); | ||
@@ -765,3 +769,3 @@ sock.setBroadcast(true); | ||
return new Promise((resolve, reject) => { | ||
this.socket.send(`[MOTD]${inf.motd}[/MOTD][AD]${inf.port}[/AD]`, LAN_MULTICAST_PORT, LAN_MULTICAST_ADDR, (err, bytes) => { | ||
this.socket.send(`[MOTD]${inf.motd}[/MOTD][AD]${inf.port}[/AD]`, LAN_MULTICAST_PORT, this.#group, (err, bytes) => { | ||
if (err) | ||
@@ -802,2 +806,3 @@ reject(err); | ||
LAN_MULTICAST_ADDR, | ||
LAN_MULTICAST_ADDR_V6, | ||
LAN_MULTICAST_PORT, | ||
@@ -804,0 +809,0 @@ Long, |
@@ -6,2 +6,3 @@ /// <reference types="node" /> | ||
export declare const LAN_MULTICAST_ADDR = "224.0.2.60"; | ||
export declare const LAN_MULTICAST_ADDR_V6 = "FF75:230::60"; | ||
export declare const LAN_MULTICAST_PORT = 4445; | ||
@@ -26,3 +27,3 @@ export interface MinecraftLanDiscover { | ||
get isReady(): boolean; | ||
constructor(); | ||
constructor(type?: 'udp4' | 'udp6'); | ||
broadcast(inf: LanServerInfo): Promise<number>; | ||
@@ -29,0 +30,0 @@ bind(): Promise<void>; |
{ | ||
"name": "@xmcl/client", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"main": "./dist/index.js", | ||
@@ -5,0 +5,0 @@ "description": "Minecraft socket pipeline utilities. Support Minecraft lan server discovery.", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
151912
1921