-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
193 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import xs from '../lib/xstream/index' | ||
|
||
let file = {} | ||
|
||
file.save = (tempFilePath) => { | ||
const producer = { | ||
start: listener => { | ||
wx.saveFile({ | ||
tempFilePath: tempFilePath, | ||
success: function(res) { | ||
listener.next(res) | ||
}, | ||
fail: () => listener.error('file cannot be saved'), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
module.exports = { | ||
file: file | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import xs from '../lib/xstream/index' | ||
|
||
let image = {} | ||
|
||
image.choose = (count=9, size=['original', 'compressed'], soure=['album', 'camera']) => { | ||
const producer = { | ||
start: listener => { | ||
wx.chooseImage({ | ||
count: count, | ||
sizeType: size, | ||
sourceType: soure, | ||
success: res => listener.next(res), | ||
fail: () => listener.error('image choosing failed'), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
image.preview = (urls=[], current='') => { | ||
const producer = { | ||
start: listener => { | ||
wx.previewImage({ | ||
current: current, | ||
urls: urls, | ||
success: res => listener.next(res), | ||
fail: () => listener.error('image preview failed'), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
image.info = (src='') => { | ||
const producer = { | ||
start: listener => { | ||
wx.getImageInfo({ | ||
src: src, | ||
success: res => listener.next(res), | ||
fail: () => listener.error('image preview failed'), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
module.exports = { | ||
image: image | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import xs from '../lib/xstream/index' | ||
|
||
const CONN_METHOD = { | ||
OPTIONS: 'OPTIONS', | ||
GET: 'GET', | ||
HEAD: 'HEAD', | ||
POST: 'POST', | ||
PUT: 'PUT', | ||
DELETE: 'DELETE', | ||
TRACE: 'TRACE', | ||
CONNECT: 'CONNECT' | ||
} | ||
|
||
let socket = { | ||
CONN_METHOD: CONN_METHOD | ||
} | ||
|
||
socket.connect = (url, data={}, header={}, method=CONN_METHOD.GET) => { | ||
const producer = { | ||
start: listener => { | ||
wx.connectSocket({ | ||
url: url, | ||
data: data, | ||
header: header, | ||
method: method, | ||
success: () => { | ||
wx.onSocketOpen(res => { | ||
listener.next(res) | ||
}) | ||
wx.onSocketError(res => { | ||
listener.error('socket connection cannot open and response is: ' + res) | ||
}) | ||
}, | ||
fail: () => listener.error('connect failed'), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
|
||
socket.sendMsg = (data) => { | ||
const producer = { | ||
start: listener => { | ||
const isArray = Array.isArray(data) | ||
if(isArray){ | ||
data.map(element => wx.sendSocketMessage({ | ||
element, | ||
success: () => listener.next(element), | ||
fail: () => listener.error('sending ' + element + ' failed'), | ||
complete: () => listener.complete() | ||
})) | ||
} else { | ||
wx.sendSocketMessage({ | ||
data, | ||
success: () => listener.next(data), | ||
fail: () => listener.error('sending ' + data + ' failed'), | ||
complete: () => listener.complete() | ||
}) | ||
} | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
socket.onMsg = () => { | ||
const producer = { | ||
start: listener => { | ||
wx.onSocketMessage(res => { | ||
listener.next(res) | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
socket.close = () => { | ||
const producer = { | ||
start: listener => { | ||
wx.closeSocket() | ||
wx.onSocketClose(res => { | ||
listener.next(res) | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
module.exports = { | ||
socket: socket | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters