2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /*jslint devel: true*/
18 /*global $, tizen, App, app, localStorage*/
20 (function () { // strict mode wrapper
26 * @param {NFCControl} nfc
28 App.NFCPeer = function (nfc) {
32 App.NFCPeer.prototype = {
34 sucSendToTarget: function nfc_peer_sucSendToTarget() {},
36 errSendToTarget: function nfc_peer_errSendToTarget(e) {
37 this.nfc.timeExpired('Send problem! ' + e.message);
40 setReceiveFromTarget: function nfc_peer_setReceiveFromTarget() {
42 if (!this.nfc.nfcTarget) {
43 console.warn("app.nfc.nfcTarget not set");
46 this.nfc.nfcTarget.unsetReceiveNDEFListener();
47 this.nfc.nfcTarget.setReceiveNDEFListener(
48 this.nfc.readMessage.bind(this.nfc)
51 console.error('setReceiveFromTarget error: ' + error.message);
55 sucTargetAttach: function nfc_peer_sucTargetAttach(target) {
56 var newMessage = null,
57 fullContact = this.nfc.prepareForNFC(localStorage);
58 this.nfc.nfcTarget = target;
59 this.setReceiveFromTarget();
62 newMessage = this.nfc.phoneNumber2NDEF(fullContact);
65 this.sucSendToTarget.bind(this),
66 this.errSendToTarget.bind(this)
69 console.error("NDEFMessage problem: " + e.message);
73 setTargetDetect: function nfc_peer_setTargetDetect() {
74 var successCallbacks = {
75 onattach: this.sucTargetAttach.bind(this),
76 ondetach: this.nfc.sucDetach.bind(this.nfc)
80 this.nfc.nfcAdapter.unsetPeerListener();
81 this.nfc.nfcAdapter.setPeerListener(successCallbacks);
83 console.error(error.message);