-
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
10 changed files
with
492 additions
and
13 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
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,122 @@ | ||
import xs from '../lib/xstream/index' | ||
|
||
let audio = {} | ||
|
||
audio.state = () => { | ||
const producer = { | ||
start: listener => { | ||
wx.getBackgroundAudioPlayerState({ | ||
success: res => listener.next(res), | ||
fail: res => listener.error(res), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
audio.play = (dataUrl, title, coverImageUrl) => { | ||
const producer = { | ||
start: listener => { | ||
wx.playBackgroundAudio({ | ||
dataUrl: dataUrl, | ||
title: title, | ||
coverImageUrl: coverImageUrl, | ||
success: res => listener.next(res), | ||
fail: res => listener.error(res), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
audio.pause = () => { | ||
const producer = { | ||
start: listener => { | ||
wx.pauseBackgroundAudio() | ||
listener.next(null) //just need a signal | ||
listener.complete() | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
audio.seek = (position) => { | ||
const producer = { | ||
start: listener => { | ||
wx.playBackgroundAudio({ | ||
position: position, | ||
success: res => listener.next(res), | ||
fail: res => listener.error(res), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
audio.stop = () => { | ||
const producer = { | ||
start: listener => { | ||
wx.stopBackgroundAudio() | ||
listener.next(null) //just need a signal | ||
listener.complete() | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
audio.createContext = (audioId) => { | ||
const producer = { | ||
start: listener => { | ||
let ctx = wx.createAudioContext(audioId) | ||
listener.next(ctx) | ||
listener.complete() | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
audio.onPlay = (callback) => { | ||
const producer = { | ||
start: listener => { | ||
wx.onBackgroundAudioPlay(callback) | ||
listener.next(null) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
audio.onPause = (callback) => { | ||
const producer = { | ||
start: listener => { | ||
wx.onBackgroundAudioPause(callback) | ||
listener.next(null) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
audio.onStop = (callback) => { | ||
const producer = { | ||
start: listener => { | ||
wx.onBackgroundAudioStop(callback) | ||
listener.next(null) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
module.exports = { | ||
audio: audio | ||
} |
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,88 @@ | ||
import xs from '../lib/xstream/index' | ||
|
||
let device = {} | ||
|
||
device.sysInfo = () => { | ||
const producer = { | ||
start: listener => { | ||
wx.getSystemInfo({ | ||
success: res => listener.next(res), | ||
fail: res => listener.error(res), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
device.network = () => { | ||
const producer = { | ||
start: listener => { | ||
wx.getNetworkType({ | ||
success: res => listener.next(res), | ||
fail: res => listener.error(res), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
device.onAccChange = () => { | ||
const producer = { | ||
start: listener => { | ||
wx.onAccelerometerChange(res => { | ||
listener.next(res) //it seems an infinite stream so it never ends | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
device.onCompChange = () => { | ||
const producer = { | ||
start: listener => { | ||
wx.onAccelerometerChange(res => { | ||
listener.next(res) //it seems an infinite stream so it never ends | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
device.dial = (phoneNumber) => { | ||
const producer = { | ||
start: listener => { | ||
wx.makePhoneCall({ | ||
phoneNumber: phoneNumber, | ||
success: res => listener.next(res), | ||
fail: res => listener.error(res), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
device.scan = () => { | ||
const producer = { | ||
start: listener => { | ||
wx.scanCode({ | ||
success: res => listener.next(res), | ||
fail: res => listener.error(res), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
module.exports = { | ||
device: device | ||
} |
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
Empty 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import xs from '../lib/xstream/index' | ||
|
||
let record = {} | ||
|
||
record.start = () => { | ||
const producer = { | ||
start: listener => { | ||
wx.startRecord({ | ||
success: res => listener.next(res), | ||
fail: res => listener.error(res), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
record.stop = () => { | ||
const producer = { | ||
start: listener => { | ||
wx.stopRecord({ | ||
success: res => listener.next(res), | ||
fail: res => listener.error(res), | ||
complete: () => listener.complete() | ||
}) | ||
}, | ||
stop: () => {} | ||
} | ||
return xs.create(producer) | ||
} | ||
|
||
module.exports = { | ||
record: record | ||
} |
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
Oops, something went wrong.