| author | Stephen Paul Weber
<singpolyma@singpolyma.net> 2023-09-12 17:45:37 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2023-09-12 17:45:37 UTC |
| parent | 6bff5aa3992955c3d885bdc532002be1a0494444 |
| Makefile | +5 | -0 |
| xmpp/Client.hx | +1 | -0 |
| xmpp/ID.hx | +6 | -0 |
| xmpp/streams/XmppJsStream.hx | +3 | -3 |
diff --git a/Makefile b/Makefile index ab0385e..0b72460 100644 --- a/Makefile +++ b/Makefile @@ -10,3 +10,8 @@ test.node.js: xmpp/*.hx xmpp/queries/*.hx xmpp/streams/*.hx run-nodejs: test.node.js nodejs "$<" +browser.js: + haxe browser.hxml + echo "var exports = {};" > browser.js + sed -e 's/hxEnums\["xmpp.EventResult"\] = {/hxEnums["xmpp.EventResult"] = $$hx_exports.xmpp.EventResult = {/'< browser.haxe.js >> browser.js + echo "export const { xmpp } = exports;" >> browser.js diff --git a/xmpp/Client.hx b/xmpp/Client.hx index ce38ac5..8d0e388 100644 --- a/xmpp/Client.hx +++ b/xmpp/Client.hx @@ -7,6 +7,7 @@ import xmpp.queries.GenericQuery; typedef ChatList = Array<Chat>; +@:expose class Client extends xmpp.EventEmitter { private var stream:GenericStream; private var chatMessageHandlers: Array<(ChatMessage)->Void> = []; diff --git a/xmpp/ID.hx b/xmpp/ID.hx index c6ca3be..9167fa5 100644 --- a/xmpp/ID.hx +++ b/xmpp/ID.hx @@ -28,6 +28,12 @@ class ID { private static function getRandomBytes(n:Int):Bytes { return Crypto.randomBytes(n).hxToBytes(); } +#elseif js + private static function getRandomBytes(n:Int):Bytes { + var array = new js.lib.Uint8Array(n); + js.Browser.window.crypto.getRandomValues(array); + return Bytes.ofData(array.buffer); + } #end } diff --git a/xmpp/streams/XmppJsStream.hx b/xmpp/streams/XmppJsStream.hx index 7d42339..570afdb 100644 --- a/xmpp/streams/XmppJsStream.hx +++ b/xmpp/streams/XmppJsStream.hx @@ -16,7 +16,7 @@ extern class XmppJsClient { function send(stanza:XmppJsXml):Void; } -@:jsRequire("@xmpp/jid", "jid") +@:jsRequire("@xmpp/jid", "JID") extern class XmppJsJID { function new(jid:String); @@ -95,7 +95,6 @@ class XmppJsStream extends GenericStream { try { var parsed:HostMetaJson = Json.parse(data); for(entry in parsed.links) { - trace("ENTRY"); if(entry.href.substr(0, 6) == "wss://") { callback(entry.href); return; @@ -114,7 +113,8 @@ class XmppJsStream extends GenericStream { private function connectWithURI(uri:String) { trace("Got connection URI: "+uri); if(uri == null) { - this.state.event("connection-error"); + // What if first is null and next is fine?? + //this.state.event("connection-error"); return; } connectionURI = uri;