Commit b8c0ce73 by Takatoshi Miura

iosローカルdb連携中

parent fc5eb4c0
......@@ -2,20 +2,6 @@
var CHAT_DB = {};
// ios用
var iosKey = "objc-processing";
function watchValue(obj, propName, func) {
let value = obj[propName];
Object.defineProperty(obj, propName, {
get: () => value,
set: newValue => {
const oldValue = value;
value = newValue;
func(oldValue, newValue);
},
configurable: true
});
}
const iosData = {
iosRoomList: "",
iosMyInfo: "",
......@@ -34,16 +20,19 @@ const iosData = {
iosArchiveDetail: ""
};
function onChange(v1, v2) {
console.log(v1);
console.log(' =>', v2);
console.log('');
var webClient = {
id: 1,
handlers: {},
};
Object.getOwnPropertyNames(iosData).forEach(propName => watchValue(iosData, propName, onChange));
iosData.iosRoomList = "roomList";
webClient.onMessageReceive = (handle, error, data) => {
if (error && webClient.handlers[handle].reject) {
webClient.handlers[handle].reject(data);
} else if (webClient.handlers[handle].resolve){
webClient.handlers[handle].resolve(data);
}
delete webClient.handlers[handle];
};
//ロカールDBからルーム一覧情報を取得
......@@ -70,16 +59,20 @@ CHAT_DB.getIosRoomList = function(roomList) {
iosRoomList = roomList;
};
//ロカールDBからログインしたユーザのデータを取得する。
CHAT_DB.getMyInfo = function() {
if (CHAT_UTIL.isIOS()) {
iosMyInfo = "";
webkit.messageHandlers.getMyInfo.postMessage();
// JavascriptからObjective-cのメソッドを指定してコールバックを受ける方法がないため、
// 値が入るまで待たせている。値の変更を検知してreturn。
return watchValue(iosMyInfo);
// iosMyInfo = "";
// webkit.messageHandlers.getMyInfo.postMessage();
// return watchValue(iosData, iosMyInfo, onChange);
webClient.sendMessage = (data) => {
return new Promise((resolve, reject) => {
const handle = 'm' + webClient.id++;
webClient.handlers[handle] = { resolve, reject };
window.webkit.messageHandlers.getMyInfo.postMessage({data: data, id: handle});
});
}
} else if (CHAT_UTIL.isAndroid()) {
//String形式をJsonに変更してReturn
return JSON.parse(android.getMyInfo());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment