diff --git a/api/stream-relay/api.js b/api/stream-relay/api.js index 32dc5d87a4..cc2c8dd061 100644 --- a/api/stream-relay/api.js +++ b/api/stream-relay/api.js @@ -1,4 +1,4 @@ -import { Peer, Encryption, sha256 } from './index.js' +import { Peer, Encryption, sha256, NAT, RemotePeer } from './index.js' import { PeerWorkerProxy } from './worker.js' import { sodium } from '../crypto.js' import { Buffer } from '../buffer.js' @@ -16,6 +16,7 @@ import { Packet, CACHE_TTL } from './packets.js' * @returns {Promise} - A promise that resolves to the initialized network bus. */ async function api (options = {}, events, dgram) { + let _peer await sodium.ready const bus = new events.EventEmitter() bus._on = bus.on @@ -37,7 +38,7 @@ async function api (options = {}, events, dgram) { if (clusterId) clusterId = Buffer.from(clusterId) // some peers don't have clusters const Ctor = globalThis.isSocketRuntime ? PeerWorkerProxy : Peer - const _peer = new Ctor(options, dgram) + _peer = new Ctor(options, dgram) _peer.onJoin = (packet, ...args) => { if (!packet.clusterId.equals(clusterId)) return @@ -197,6 +198,7 @@ async function api (options = {}, events, dgram) { const args = await pack(eventName, value, opts) if (!options.sharedKey) { throw new Error('Can\'t emit to the top level cluster, a shared key was not provided in the constructor or the arguments options') + return } return await _peer.publish(options.sharedKey || opts.sharedKey, args) } diff --git a/api/stream-relay/index.js b/api/stream-relay/index.js index 14be03ac53..b37469721d 100644 --- a/api/stream-relay/index.js +++ b/api/stream-relay/index.js @@ -578,7 +578,7 @@ export class Peer { }) return { - peers, + peers, config: this.config, data: [...this.cache.data.entries()], unpublished: this.unpublished @@ -592,6 +592,7 @@ export class Peer { clock: this.clock, uptime: this.uptime, natType: this.natType, + natName: NAT.toString(this.natType), peerId: this.peerId } } @@ -1042,7 +1043,7 @@ export class Peer { for (const packet of packets) { this.cacheInsert(packet) - if (this.onPacket) this.onPacket(packet, this.port, this.address, true) + if (this.onPacket) this.onPacket(p, this.port, this.address, true) this.unpublished[packet.packetId.toString('hex')] = Date.now() if (globalThis.navigator && !globalThis.navigator.onLine) continue diff --git a/api/stream-relay/worker.js b/api/stream-relay/worker.js index 9a9bb5fb51..865d777f4c 100644 --- a/api/stream-relay/worker.js +++ b/api/stream-relay/worker.js @@ -167,7 +167,7 @@ export class PeerWorkerProxy { return await this.callWorkerThread('reconnect') } - async disconnect () { + async reconnect () { return await this.callWorkerThread('disconnect') } @@ -335,7 +335,6 @@ if (isWorkerThread) { } case 'compileCachePredicate': { - // eslint-disable-next-line let predicate = new Function(`return ${data.toString()}`)() predicate = predicate.bind(peer) peer.cachePredicate = packet => predicate(packet) diff --git a/src/cli/cli.cc b/src/cli/cli.cc index f1bb35fc9f..4d39ba3343 100644 --- a/src/cli/cli.cc +++ b/src/cli/cli.cc @@ -4502,7 +4502,7 @@ int main (const int argc, const char* argv[]) { compileExtensionObjectCommand << "xcrun -sdk " << (flagBuildForSimulator ? "iphonesimulator" : "iphoneos") << " " << compiler - << " -I" << Path(paths.platformSpecificOutputPath / "include").string() + << " -I\"" << Path(paths.platformSpecificOutputPath / "include").string() << "\"" << " -I" << prefixFile() << " -I" << prefixFile("include") << " -DIOS=1" @@ -4580,7 +4580,7 @@ int main (const int argc, const char* argv[]) { fs::create_directories(lib.parent_path()); compileExtensionWASMCommand << compiler - << " -I" + Path(paths.platformSpecificOutputPath / "include").string() + << " -I\"" + Path(paths.platformSpecificOutputPath / "include").string() << "\"" << (" -I" + quote + trim(prefixFile("include")) + quote) << (" -I" + quote + trim(prefixFile("include/socket/webassembly")) + quote) << (" -I" + quote + trim(prefixFile("src")) + quote)