@adeeliore/p2p-lan-signaling 0.1.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/API_REFERENCE.md +158 -0
- package/CHANGELOG.md +9 -0
- package/LICENSE +12 -0
- package/README.md +118 -0
- package/app.plugin.js +1 -0
- package/dist/constants.d.ts +17 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +19 -0
- package/dist/discovery.d.ts +3 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +10 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +16 -0
- package/dist/host.d.ts +5 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +23 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/messageValidation.d.ts +3 -0
- package/dist/messageValidation.d.ts.map +1 -0
- package/dist/messageValidation.js +90 -0
- package/dist/nativeModule.d.ts +7 -0
- package/dist/nativeModule.d.ts.map +1 -0
- package/dist/nativeModule.js +39 -0
- package/dist/provider.d.ts +20 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +91 -0
- package/dist/providerUtils.d.ts +3 -0
- package/dist/providerUtils.d.ts.map +1 -0
- package/dist/providerUtils.js +18 -0
- package/dist/roomUtils.d.ts +3 -0
- package/dist/roomUtils.d.ts.map +1 -0
- package/dist/roomUtils.js +15 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/package.json +54 -0
- package/plugin/templates/android/OfflineSignalingPackage.kt +609 -0
- package/plugin/templates/ios/OfflineSignalingHost.swift +703 -0
- package/plugin/templates/ios/OfflineSignalingHostBridge.m +22 -0
- package/plugin/withP2PLanSignaling.js +144 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
|
|
3
|
+
@interface RCT_EXTERN_MODULE(OfflineSignalingHost, NSObject)
|
|
4
|
+
|
|
5
|
+
RCT_EXTERN_METHOD(startHost:(nonnull NSNumber *)port
|
|
6
|
+
roomId:(NSString *)roomId
|
|
7
|
+
displayName:(NSString *)displayName
|
|
8
|
+
roomSecret:(NSString *)roomSecret
|
|
9
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
10
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
11
|
+
|
|
12
|
+
RCT_EXTERN_METHOD(stopHost:(RCTPromiseResolveBlock)resolve
|
|
13
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
14
|
+
|
|
15
|
+
RCT_EXTERN_METHOD(getStatus:(RCTPromiseResolveBlock)resolve
|
|
16
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
17
|
+
|
|
18
|
+
RCT_EXTERN_METHOD(discoverHosts:(nonnull NSNumber *)timeoutMs
|
|
19
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
20
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
21
|
+
|
|
22
|
+
@end
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
const {
|
|
2
|
+
withAndroidManifest,
|
|
3
|
+
withDangerousMod,
|
|
4
|
+
withInfoPlist,
|
|
5
|
+
withMainApplication,
|
|
6
|
+
withXcodeProject,
|
|
7
|
+
} = require('@expo/config-plugins');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
const ANDROID_PACKAGE_ADD = 'add(OfflineSignalingPackage())';
|
|
12
|
+
const ANDROID_MULTICAST_PERMISSION = 'android.permission.CHANGE_WIFI_MULTICAST_STATE';
|
|
13
|
+
const ANDROID_OFFLINE_PACKAGE_NAME = 'offline';
|
|
14
|
+
const DEFAULT_ANDROID_PACKAGE = 'com.anonymous.DrawingApp';
|
|
15
|
+
const IOS_BRIDGE_FILE = 'OfflineSignalingHostBridge.m';
|
|
16
|
+
const IOS_SWIFT_FILE = 'OfflineSignalingHost.swift';
|
|
17
|
+
const LOCAL_NETWORK_USAGE_DESCRIPTION =
|
|
18
|
+
'Drawin uses the local network to host and discover offline collaboration sessions on nearby devices.';
|
|
19
|
+
const SERVICE_TYPE = '_drawin._tcp';
|
|
20
|
+
|
|
21
|
+
const TEMPLATE_FILES = {
|
|
22
|
+
androidPackage: path.join(__dirname, 'templates/android/OfflineSignalingPackage.kt'),
|
|
23
|
+
iosBridge: path.join(__dirname, 'templates/ios/OfflineSignalingHostBridge.m'),
|
|
24
|
+
iosSwift: path.join(__dirname, 'templates/ios/OfflineSignalingHost.swift'),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function withP2PLanSignaling(config) {
|
|
28
|
+
config = withInfoPlist(config, ensureIosLocalNetworkPermissions);
|
|
29
|
+
config = withAndroidManifest(config, ensureAndroidLanPermissions);
|
|
30
|
+
config = withMainApplication(config, registerAndroidReactPackage);
|
|
31
|
+
config = withXcodeProject(config, registerIosSources);
|
|
32
|
+
config = withDangerousMod(config, ['android', writeAndroidSources]);
|
|
33
|
+
return withDangerousMod(config, ['ios', writeIosSources]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function ensureIosLocalNetworkPermissions(config) {
|
|
37
|
+
const plist = config.modResults;
|
|
38
|
+
plist.NSLocalNetworkUsageDescription =
|
|
39
|
+
plist.NSLocalNetworkUsageDescription || LOCAL_NETWORK_USAGE_DESCRIPTION;
|
|
40
|
+
plist.NSBonjourServices = Array.from(new Set([...(plist.NSBonjourServices || []), SERVICE_TYPE]));
|
|
41
|
+
plist.NSAppTransportSecurity = {
|
|
42
|
+
...(plist.NSAppTransportSecurity || {}),
|
|
43
|
+
NSAllowsLocalNetworking: true,
|
|
44
|
+
};
|
|
45
|
+
return config;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function ensureAndroidLanPermissions(config) {
|
|
49
|
+
const manifest = config.modResults.manifest;
|
|
50
|
+
manifest['uses-permission'] = manifest['uses-permission'] || [];
|
|
51
|
+
const permissions = manifest['uses-permission'];
|
|
52
|
+
const exists = permissions.some(
|
|
53
|
+
(permission) => permission.$?.['android:name'] === ANDROID_MULTICAST_PERMISSION
|
|
54
|
+
);
|
|
55
|
+
if (!exists) {
|
|
56
|
+
permissions.push({ $: { 'android:name': ANDROID_MULTICAST_PERMISSION } });
|
|
57
|
+
}
|
|
58
|
+
return config;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function registerAndroidReactPackage(config) {
|
|
62
|
+
let contents = config.modResults.contents;
|
|
63
|
+
const packageImport = `import ${getAndroidPackageName(config)}.${ANDROID_OFFLINE_PACKAGE_NAME}.OfflineSignalingPackage`;
|
|
64
|
+
|
|
65
|
+
if (!contents.includes(packageImport)) {
|
|
66
|
+
contents = contents.replace(
|
|
67
|
+
'import com.facebook.react.PackageList',
|
|
68
|
+
`${packageImport}\nimport com.facebook.react.PackageList`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!contents.includes(ANDROID_PACKAGE_ADD)) {
|
|
73
|
+
contents = contents.replace('// add(MyReactNativePackage())', ANDROID_PACKAGE_ADD);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
config.modResults.contents = contents;
|
|
77
|
+
return config;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function registerIosSources(config) {
|
|
81
|
+
const project = config.modResults;
|
|
82
|
+
const groupKey = findPbxGroupKey(project, config.modRequest.projectName);
|
|
83
|
+
addIosSourceFile(project, groupKey, IOS_SWIFT_FILE, 'sourcecode.swift');
|
|
84
|
+
addIosSourceFile(project, groupKey, IOS_BRIDGE_FILE, 'sourcecode.c.objc');
|
|
85
|
+
return config;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function writeAndroidSources(config) {
|
|
89
|
+
const androidPackageName = getAndroidPackageName(config);
|
|
90
|
+
const offlineDir = path.join(
|
|
91
|
+
config.modRequest.platformProjectRoot,
|
|
92
|
+
'app/src/main/java',
|
|
93
|
+
...androidPackageName.split('.'),
|
|
94
|
+
ANDROID_OFFLINE_PACKAGE_NAME
|
|
95
|
+
);
|
|
96
|
+
fs.rmSync(offlineDir, { recursive: true, force: true });
|
|
97
|
+
fs.mkdirSync(offlineDir, { recursive: true });
|
|
98
|
+
fs.writeFileSync(
|
|
99
|
+
path.join(offlineDir, 'OfflineSignalingPackage.kt'),
|
|
100
|
+
createAndroidSource(androidPackageName)
|
|
101
|
+
);
|
|
102
|
+
return config;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function writeIosSources(config) {
|
|
106
|
+
const appDir = path.join(config.modRequest.platformProjectRoot, config.modRequest.projectName);
|
|
107
|
+
fs.mkdirSync(appDir, { recursive: true });
|
|
108
|
+
fs.writeFileSync(path.join(appDir, IOS_SWIFT_FILE), readTemplate(TEMPLATE_FILES.iosSwift));
|
|
109
|
+
fs.writeFileSync(path.join(appDir, IOS_BRIDGE_FILE), readTemplate(TEMPLATE_FILES.iosBridge));
|
|
110
|
+
return config;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function createAndroidSource(androidPackageName) {
|
|
114
|
+
return readTemplate(TEMPLATE_FILES.androidPackage).replace(
|
|
115
|
+
'package com.anonymous.DrawingApp.offline',
|
|
116
|
+
`package ${androidPackageName}.${ANDROID_OFFLINE_PACKAGE_NAME}`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function getAndroidPackageName(config) {
|
|
121
|
+
return config.android?.package || config.ios?.bundleIdentifier || DEFAULT_ANDROID_PACKAGE;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function readTemplate(filePath) {
|
|
125
|
+
return fs.readFileSync(filePath, 'utf8');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function findPbxGroupKey(project, groupName) {
|
|
129
|
+
const groups = project.hash.project.objects.PBXGroup || {};
|
|
130
|
+
const match = Object.entries(groups).find(([key, group]) => {
|
|
131
|
+
return !key.endsWith('_comment') && (group.name === groupName || group.path === groupName);
|
|
132
|
+
});
|
|
133
|
+
if (!match) {
|
|
134
|
+
throw new Error(`Unable to find iOS PBXGroup for ${groupName}`);
|
|
135
|
+
}
|
|
136
|
+
return match[0];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function addIosSourceFile(project, groupKey, fileName, lastKnownFileType) {
|
|
140
|
+
if (project.hasFile(fileName)) return;
|
|
141
|
+
project.addSourceFile(fileName, { lastKnownFileType }, groupKey);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
module.exports = withP2PLanSignaling;
|