Skip to content

Commit

Permalink
Soup 3: Try to fix node-gtk example
Browse files Browse the repository at this point in the history
  • Loading branch information
JumpLink committed Sep 19, 2023
1 parent f3ea529 commit c6c177f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 6 additions & 2 deletions examples/node-gtk/soup-3-http/http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
// https://developer.gnome.org/libsoup/stable/libsoup-client-howto.html
// https://gitlab.gnome.org/GNOME/gjs/-/blob/master/examples/http-client.js

import './@types/node-gtk.js';
// TODO callbacks not working in node-gtk?

import gi from './@types/node-gtk.js';
import GLib from './@types/node-glib-2.0.js';
import Soup from './@types/node-soup-3.0.js';
import Gio from './@types/node-gio-2.0.js';

const loop = GLib.MainLoop.new(null, false);

gi.startLoop();

const gBytesToString = (data: GLib.Bytes) => {
return Buffer.from(data.getData() || []).toString()
}

const session = new Soup.Session();
const message = new Soup.Message({
method: 'GET',
uri: GLib.Uri.parse('http://localhost:1080/hello?myname=gjs', GLib.UriFlags.NONE),
uri: GLib.Uri.parse('http://localhost:1080/hello?myname=node-gtk', GLib.UriFlags.NONE),
});

const readBytesAsyncCallback: Gio.AsyncReadyCallback = (inputStream, res) => {
Expand Down
12 changes: 8 additions & 4 deletions examples/node-gtk/soup-3-http/http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// This is a simple example of a HTTP server in Gjs using libsoup 3
// https://gitlab.gnome.org/GNOME/gjs/-/blob/master/examples/http-server.js

import './@types/node-gtk.js';
// TODO callbacks not working in node-gtk?

import gi from './@types/node-gtk.js';
import GLib from './@types/node-glib-2.0.js';
import Soup from './@types/node-soup-3.0.js';

Expand All @@ -15,6 +17,8 @@ interface GjsHashTable {
[key: symbol | string | number]: string | number | boolean;
}

gi.startLoop();

const loop = GLib.MainLoop.new(null, false);

const handler: Soup.ServerCallback = (server, msg, path, query) => {
Expand All @@ -32,7 +36,7 @@ const handler: Soup.ServerCallback = (server, msg, path, query) => {
</html>
`);

msg.setResponse('text/html; charset=utf-8', Soup.MemoryUse.COPY, body)
msg.setResponse('text/html; charset=utf-8', Soup.MemoryUse.COPY, [...body])
}

const helloHandler: Soup.ServerCallback = (server, msg, path, query) => {
Expand All @@ -54,7 +58,7 @@ const helloHandler: Soup.ServerCallback = (server, msg, path, query) => {
</html>
`);

msg.setResponse('text/html; charset=utf-8', Soup.MemoryUse.COPY, body)
msg.setResponse('text/html; charset=utf-8', Soup.MemoryUse.COPY, [...body])
}

function main() {
Expand All @@ -66,4 +70,4 @@ function main() {
loop.run();
}

main();
main();

0 comments on commit c6c177f

Please sign in to comment.