Skip to content

Commit eeabfc2

Browse files
committed
ADD: SMS API
1 parent fc5dfc5 commit eeabfc2

File tree

28 files changed

+722
-11
lines changed

28 files changed

+722
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ it will generate an apk inside dist folder.
7373

7474
## Resources for learning Android JS
7575

76-
- [android-js.github.io/androidjs/](https://android-js.github.io/androidjs/) - all of Android JS's documentation
76+
- [android-js.github.io/androidjs/](https://android-js.github.io/docs/) - all of Android JS's documentation
7777
- [android-js/androidjs/sample-app](https://github.com/android-js/sample-app) - sample starter apps created by the community
7878

7979
## License

build/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ it will generate an apk inside dist folder.
7373

7474
## Resources for learning Android JS
7575

76-
- [android-js.github.io/androidjs/](https://android-js.github.io/androidjs/) - all of Android JS's documentation
76+
- [android-js.github.io/androidjs/](https://android-js.github.io/docs/) - all of Android JS's documentation
7777
- [android-js/androidjs/sample-app](https://github.com/android-js/sample-app) - sample starter apps created by the community
7878

7979
## License

build/lib/androidjs.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/lib/react_native/androidjs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var wifi = require("./api/wifi");
77
var call = require("./api/call");
88
var contact = require("./api/contact");
99
var deeplink = require("./api/deeplink");
10+
var sms = require("./api/sms");
1011
module.exports = {
1112
notification: notification,
1213
hotspot: hotspot,
@@ -15,6 +16,7 @@ module.exports = {
1516
call: call,
1617
contact: contact,
1718
deeplink: deeplink,
19+
sms: sms,
1820
getPath: app.getPath,
1921
loadUrl: app.loadURL,
2022
reload: app.reload

build/lib/react_native/api/sms.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use strict";
2+
var NativeModules = require('react-native').NativeModules;
3+
var sms = /** @class */ (function () {
4+
function sms() {
5+
}
6+
sms.prototype.sendSMS = function (number, message) {
7+
return JSON.parse(NativeModules.SMS.sendSMS(number, message));
8+
};
9+
return sms;
10+
}());
11+
module.exports = new sms();

dist/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
module.exports = {
3+
back: require("./lib/back"),
4+
front: require("./lib/front")
5+
};

dist/lib/back.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"use strict";
2+
var path = require("path");
3+
var http = require("http");
4+
var io = require("socket.io");
5+
var Buffer = require("Buffer");
6+
var fs = require("fs");
7+
var Back = /** @class */ (function () {
8+
function Back() {
9+
this.server = http.createServer();
10+
this.server.listen(3000);
11+
this.server_socket = io(this.server);
12+
this.clients = [];
13+
this.listerners = {};
14+
this.server_socket.on('connection', function (socket) {
15+
this.clients.push(socket);
16+
socket.on('response-from-front', function (event) {
17+
var args = [];
18+
for (var _i = 1; _i < arguments.length; _i++) {
19+
args[_i - 1] = arguments[_i];
20+
}
21+
if (event == 'androidjs:saveBlob') {
22+
this.saveBlobHelper(args[0], args[1], args[2], args[3]);
23+
return;
24+
}
25+
this.exeFunction.apply(this, [event].concat(args));
26+
}.bind(this));
27+
}.bind(this));
28+
}
29+
Back.prototype.addListener = function (event, fn) {
30+
this.listerners[event] = this.listerners[event] || [];
31+
this.listerners[event].push(fn);
32+
};
33+
Back.prototype.on = function (event, fn) {
34+
this.addListener(event, fn);
35+
};
36+
Back.prototype.exeFunction = function (event) {
37+
var args = [];
38+
for (var _i = 1; _i < arguments.length; _i++) {
39+
args[_i - 1] = arguments[_i];
40+
}
41+
var fns = this.listerners[event];
42+
if (!fns)
43+
return;
44+
fns.forEach(function (f) {
45+
f.apply(void 0, args);
46+
});
47+
return;
48+
};
49+
Back.prototype.send = function (event) {
50+
var _a;
51+
var args = [];
52+
for (var _i = 1; _i < arguments.length; _i++) {
53+
args[_i - 1] = arguments[_i];
54+
}
55+
for (var i = 0; i < this.clients.length; i++) {
56+
(_a = this.clients[i]).emit.apply(_a, ['response-from-back', event].concat(args));
57+
}
58+
};
59+
Back.prototype.saveBlobHelper = function (filepath, filename, blob, type) {
60+
console.log('called this function');
61+
if (type == 'image') {
62+
var buffer = new Buffer(blob, 'base64');
63+
fs.writeFile(path.join(filepath, filename), buffer, function (err) {
64+
if (err) {
65+
console.log(err);
66+
throw err;
67+
}
68+
});
69+
}
70+
else if (type == 'video') {
71+
var buffer = new Buffer(blob);
72+
fs.writeFile(path.join(filepath, filename), buffer, function (err) {
73+
if (err) {
74+
console.log(err);
75+
throw err;
76+
}
77+
});
78+
}
79+
else if (type == 'audio') {
80+
var buffer = new Buffer(blob);
81+
fs.writeFile(path.join(filepath, filename), buffer, function (err) {
82+
if (err) {
83+
console.log(err);
84+
throw err;
85+
}
86+
});
87+
}
88+
};
89+
return Back;
90+
}());
91+
module.exports = new Back();

dist/lib/front.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"use strict";
2+
exports.__esModule = true;
3+
var io = require("socket.io-client");
4+
var socket = io('http://localhost:3000');
5+
var listerners = {};
6+
function addListener(event, fn) {
7+
listerners[event] = listerners[event] || [];
8+
listerners[event].push(fn);
9+
}
10+
function on(event, fn) {
11+
addListener(event, fn);
12+
}
13+
exports.on = on;
14+
function exeFunction(event) {
15+
var args = [];
16+
for (var _i = 1; _i < arguments.length; _i++) {
17+
args[_i - 1] = arguments[_i];
18+
}
19+
var fns = listerners[event];
20+
if (!fns)
21+
return;
22+
fns.forEach(function (f) {
23+
f.apply(void 0, args);
24+
});
25+
return;
26+
}
27+
function send(event) {
28+
var args = [];
29+
for (var _i = 1; _i < arguments.length; _i++) {
30+
args[_i - 1] = arguments[_i];
31+
}
32+
socket.emit.apply(socket, ['response-from-front', event].concat(args));
33+
}
34+
exports.send = send;
35+
socket.on('response-from-back', function (event) {
36+
var args = [];
37+
for (var _i = 1; _i < arguments.length; _i++) {
38+
args[_i - 1] = arguments[_i];
39+
}
40+
exeFunction.apply(void 0, [event].concat(args));
41+
});

dist/react_native/androidjs.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
var notification = require("./api/notification");
3+
var app = require("./api/app");
4+
var hotspot = require("./api/hotspot");
5+
var toast = require("./api/toast");
6+
var wifi = require("./api/wifi");
7+
var call = require("./api/call");
8+
var contact = require("./api/contact");
9+
var deeplink = require("./api/deeplink");
10+
var sms = require("./api/sms");
11+
module.exports = {
12+
notification: notification,
13+
hotspot: hotspot,
14+
toast: toast,
15+
wifi: wifi,
16+
call: call,
17+
contact: contact,
18+
deeplink: deeplink,
19+
sms: sms,
20+
getPath: app.getPath,
21+
loadUrl: app.loadURL,
22+
reload: app.reload
23+
};

dist/react_native/api/app.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
exports.__esModule = true;
3+
var NativeModules = require('react-native').NativeModules;
4+
function getPath(name) {
5+
return NativeModules.App.getPath(name);
6+
}
7+
exports.getPath = getPath;
8+
function loadURL(url) {
9+
location.href = url;
10+
}
11+
exports.loadURL = loadURL;
12+
function reload() {
13+
location.reload();
14+
}
15+
exports.reload = reload;

0 commit comments

Comments
 (0)