node-bible-sync 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build.yml +39 -0
- package/API.md +81 -0
- package/COPYING +339 -0
- package/README.md +113 -2
- package/biblesync.js +234 -0
- package/binding.gyp +62 -0
- package/examples/biblesync.js +53 -0
- package/index.js +31 -0
- package/package.json +26 -4
- package/scripts/fetch_biblesync.js +80 -0
- package/scripts/ios_framework_postbuild.sh +85 -0
- package/scripts/prepare_biblesync.js +189 -0
- package/src/biblesync_compat/biblesync-version.hh +29 -0
- package/src/biblesync_compat/libintl.h +24 -0
- package/src/biblesync_compat/unistd.h +29 -0
- package/src/biblesync_compat/uuid/uuid.h +61 -0
- package/src/napi_module/biblesync_session.cpp +433 -0
- package/src/napi_module/biblesync_session.hpp +90 -0
- package/src/napi_module/binding.cpp +26 -0
- package/test/biblesync.test.js +142 -0
- package/test/biblesync_example.test.js +59 -0
- package/test/biblesync_fetch.test.js +86 -0
- package/test/biblesync_integration.test.js +267 -0
- package/test/biblesync_native.test.js +162 -0
- package/test/biblesync_prepare.test.js +81 -0
- package/test/fixtures/biblesync_fail_send.c +61 -0
- package/test/fixtures/biblesync_peer.js +53 -0
- package/test/fixtures/biblesync_system_peer.cpp +62 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* This file is part of node-bible-sync.
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2026 Tobias Klein <contact@tklein.info>
|
|
4
|
+
|
|
5
|
+
node-bible-sync is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 2 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
node-bible-sync is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License
|
|
16
|
+
along with node-bible-sync. See the file COPYING.
|
|
17
|
+
If not, see <http://www.gnu.org/licenses/>. */
|
|
18
|
+
|
|
19
|
+
#define _GNU_SOURCE
|
|
20
|
+
#include <dlfcn.h>
|
|
21
|
+
#include <errno.h>
|
|
22
|
+
#include <stddef.h>
|
|
23
|
+
#include <stdlib.h>
|
|
24
|
+
#include <sys/socket.h>
|
|
25
|
+
#include <unistd.h>
|
|
26
|
+
|
|
27
|
+
int bind(int fd, const struct sockaddr *address, socklen_t address_length)
|
|
28
|
+
{
|
|
29
|
+
if (getenv("BIBLESYNC_FAIL_BIND")) {
|
|
30
|
+
errno = EADDRINUSE;
|
|
31
|
+
return -1;
|
|
32
|
+
}
|
|
33
|
+
typedef int (*bind_fn)(int, const struct sockaddr *, socklen_t);
|
|
34
|
+
bind_fn real_bind = (bind_fn)dlsym(RTLD_NEXT, "bind");
|
|
35
|
+
if (!real_bind) {
|
|
36
|
+
errno = ENOSYS;
|
|
37
|
+
return -1;
|
|
38
|
+
}
|
|
39
|
+
return real_bind(fd, address, address_length);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
ssize_t sendto(int fd, const void *buffer, size_t length, int flags,
|
|
43
|
+
const struct sockaddr *address, socklen_t address_length)
|
|
44
|
+
{
|
|
45
|
+
static int calls;
|
|
46
|
+
if (getenv("BIBLESYNC_FAIL_BIND")) {
|
|
47
|
+
const char message[] = "unexpected sendto after bind failure\n";
|
|
48
|
+
(void)write(STDERR_FILENO, message, sizeof(message) - 1);
|
|
49
|
+
}
|
|
50
|
+
if (++calls == 3) {
|
|
51
|
+
errno = ENETUNREACH;
|
|
52
|
+
return -1;
|
|
53
|
+
}
|
|
54
|
+
typedef ssize_t (*sendto_fn)(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
|
|
55
|
+
sendto_fn real_sendto = (sendto_fn)dlsym(RTLD_NEXT, "sendto");
|
|
56
|
+
if (!real_sendto) {
|
|
57
|
+
errno = ENOSYS;
|
|
58
|
+
return -1;
|
|
59
|
+
}
|
|
60
|
+
return real_sendto(fd, buffer, length, flags, address, address_length);
|
|
61
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* This file is part of node-bible-sync.
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2026 Tobias Klein <contact@tklein.info>
|
|
4
|
+
|
|
5
|
+
node-bible-sync is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 2 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
node-bible-sync is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License
|
|
16
|
+
along with node-bible-sync. See the file COPYING.
|
|
17
|
+
If not, see <http://www.gnu.org/licenses/>. */
|
|
18
|
+
|
|
19
|
+
const BibleSync = require('../..');
|
|
20
|
+
|
|
21
|
+
const session = new BibleSync({
|
|
22
|
+
application: 'Integration test',
|
|
23
|
+
version: '1',
|
|
24
|
+
user: process.argv[3],
|
|
25
|
+
passphrase: process.argv[4] || 'BibleSync'
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
for (const type of ['speaker', 'speakerRemoved', 'presence', 'navigation', 'diagnostic']) {
|
|
29
|
+
session.on(type, data => process.send({ type, data }));
|
|
30
|
+
}
|
|
31
|
+
session.on('error', error => process.send({ type: 'error', message: error.message }));
|
|
32
|
+
|
|
33
|
+
process.on('message', async command => {
|
|
34
|
+
try {
|
|
35
|
+
if (command.type === 'start') await session.start(command.mode);
|
|
36
|
+
else if (command.type === 'send') await session.sendNavigation(command.data);
|
|
37
|
+
else if (command.type === 'listen') await session.setSpeakerListening(command.speakerId, command.listening);
|
|
38
|
+
else if (command.type === 'stop') await session.stop();
|
|
39
|
+
else throw new Error('Unknown command');
|
|
40
|
+
process.send({ type: 'result', id: command.id });
|
|
41
|
+
} catch (error) {
|
|
42
|
+
process.send({ type: 'result', id: command.id, error: error.message });
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
session.start(process.argv[2]).then(async () => {
|
|
47
|
+
if (process.argv[5] === 'immediate') {
|
|
48
|
+
await session.sendNavigation({ bible: 'KJV', reference: 'John.3.15' });
|
|
49
|
+
}
|
|
50
|
+
process.send({ type: 'ready' });
|
|
51
|
+
}).catch(error => {
|
|
52
|
+
process.send({ type: 'startupError', message: error.message }, () => process.exit(1));
|
|
53
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* This file is part of node-bible-sync.
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2026 Tobias Klein <contact@tklein.info>
|
|
4
|
+
|
|
5
|
+
node-bible-sync is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 2 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
node-bible-sync is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License
|
|
16
|
+
along with node-bible-sync. See the file COPYING.
|
|
17
|
+
If not, see <http://www.gnu.org/licenses/>. */
|
|
18
|
+
|
|
19
|
+
#include <iostream>
|
|
20
|
+
#include <string>
|
|
21
|
+
#include <sys/select.h>
|
|
22
|
+
#include <unistd.h>
|
|
23
|
+
#include <biblesync.hh>
|
|
24
|
+
#undef min
|
|
25
|
+
|
|
26
|
+
static void onEvent(char command, std::string, std::string bible, std::string reference,
|
|
27
|
+
std::string alternate, std::string group, std::string domain,
|
|
28
|
+
std::string, std::string)
|
|
29
|
+
{
|
|
30
|
+
if (command == 'S') std::cout << "speaker" << std::endl;
|
|
31
|
+
if (command == 'N')
|
|
32
|
+
std::cout << "navigation|" << bible << "|" << reference << "|"
|
|
33
|
+
<< alternate << "|" << group << "|" << domain << std::endl;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
int main(int argc, char **argv)
|
|
37
|
+
{
|
|
38
|
+
if (argc != 2 && argc != 3) return 2;
|
|
39
|
+
BibleSync sync("Xiphos system library test", "1", "system-peer");
|
|
40
|
+
BibleSync_mode mode = argc == 3 && std::string(argv[2]) == "audience"
|
|
41
|
+
? BSP_MODE_AUDIENCE : BSP_MODE_SPEAKER;
|
|
42
|
+
if (sync.setMode(mode, onEvent, argv[1]) != mode) return 1;
|
|
43
|
+
std::cout << "ready" << std::endl;
|
|
44
|
+
for (;;) {
|
|
45
|
+
fd_set readSet;
|
|
46
|
+
FD_ZERO(&readSet);
|
|
47
|
+
FD_SET(STDIN_FILENO, &readSet);
|
|
48
|
+
struct timeval timeout = {1, 0};
|
|
49
|
+
int ready = select(STDIN_FILENO + 1, &readSet, nullptr, nullptr, &timeout);
|
|
50
|
+
if (ready < 0) return 1;
|
|
51
|
+
if (ready > 0) {
|
|
52
|
+
std::string command;
|
|
53
|
+
if (!std::getline(std::cin, command) || command == "stop") break;
|
|
54
|
+
if (command == "send") {
|
|
55
|
+
if (sync.Transmit("KJV", "John.3.16", "", "1", "BIBLE-VERSE") != BSP_XMIT_OK) return 1;
|
|
56
|
+
std::cout << "sent" << std::endl;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
BibleSync::Receive(&sync);
|
|
60
|
+
}
|
|
61
|
+
sync.setMode(BSP_MODE_DISABLE);
|
|
62
|
+
}
|