Skip to content

Commit b330deb

Browse files
authored
Merge pull request #248 from rescript-lang/issue-243-media-device
refactor: simplify media and device module surfaces
2 parents 4542085 + a780ab4 commit b330deb

11 files changed

Lines changed: 87 additions & 43 deletions

File tree

src/NotificationAPI/Notification.res

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
open NotificationTypes
22

3+
type t = notification = {...notification}
4+
5+
type notificationDirection = NotificationTypes.notificationDirection
6+
type notificationPermission = NotificationTypes.notificationPermission
7+
type notificationAction = NotificationTypes.notificationAction = {
8+
...NotificationTypes.notificationAction,
9+
}
10+
type notificationOptions = NotificationTypes.notificationOptions = {
11+
...NotificationTypes.notificationOptions,
12+
}
13+
type getNotificationOptions = NotificationTypes.getNotificationOptions = {
14+
...NotificationTypes.getNotificationOptions,
15+
}
16+
type notificationPermissionCallback = NotificationTypes.notificationPermissionCallback
17+
type notificationEvent = NotificationTypes.notificationEvent = {
18+
...NotificationTypes.notificationEvent,
19+
}
20+
321
/**
422
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Notification)
523
*/
624
@new
7-
external make: (~title: string, ~options: notificationOptions=?) => notification = "Notification"
25+
external make: (~title: string, ~options: notificationOptions=?) => t = "Notification"
826

9-
include EventTarget.Impl({type t = notification})
27+
include EventTarget.Impl({type t = t})
1028

1129
/**
1230
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Notification/requestPermission_static)
@@ -20,7 +38,7 @@ external requestPermission: (
2038
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Notification/close)
2139
*/
2240
@send
23-
external close: notification => unit = "close"
41+
external close: t => unit = "close"
2442

2543
/**
2644
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notification/permission_static)

src/PictureInPicture.res

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
open PictureInPictureTypes
2+
3+
type t = pictureInPictureWindow = {...pictureInPictureWindow}
4+
5+
include EventTarget.Impl({type t = t})

src/WebAudioAPI/AudioContext.res

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,62 @@ open WebAudioTypes
22
open DOMTypes
33
open MediaCaptureAndStreamsTypes
44

5-
include BaseAudioContext.Impl({type t = audioContext})
5+
type t = audioContext = {...audioContext}
6+
type baseAudioContext = WebAudioTypes.baseAudioContext = {...WebAudioTypes.baseAudioContext}
7+
type audioContextOptions = WebAudioTypes.audioContextOptions = {
8+
...WebAudioTypes.audioContextOptions,
9+
}
10+
type audioTimestamp = WebAudioTypes.audioTimestamp = {...WebAudioTypes.audioTimestamp}
11+
12+
include BaseAudioContext.Impl({type t = t})
613

714
/**
815
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AudioContext)
916
*/
1017
@new
11-
external make: (~contextOptions: audioContextOptions=?) => audioContext = "AudioContext"
18+
external make: (~contextOptions: audioContextOptions=?) => t = "AudioContext"
1219

1320
/**
1421
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AudioContext/getOutputTimestamp)
1522
*/
1623
@send
17-
external getOutputTimestamp: audioContext => audioTimestamp = "getOutputTimestamp"
24+
external getOutputTimestamp: t => audioTimestamp = "getOutputTimestamp"
1825

1926
/**
2027
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AudioContext/resume)
2128
*/
2229
@send
23-
external resume: audioContext => promise<unit> = "resume"
30+
external resume: t => promise<unit> = "resume"
2431

2532
/**
2633
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AudioContext/suspend)
2734
*/
2835
@send
29-
external suspend: audioContext => promise<unit> = "suspend"
36+
external suspend: t => promise<unit> = "suspend"
3037

3138
/**
3239
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AudioContext/close)
3340
*/
3441
@send
35-
external close: audioContext => promise<unit> = "close"
42+
external close: t => promise<unit> = "close"
3643

3744
/**
3845
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AudioContext/createMediaElementSource)
3946
*/
4047
@send
41-
external createMediaElementSource: (audioContext, htmlMediaElement) => mediaElementAudioSourceNode =
48+
external createMediaElementSource: (t, htmlMediaElement) => mediaElementAudioSourceNode =
4249
"createMediaElementSource"
4350

4451
/**
4552
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AudioContext/createMediaStreamSource)
4653
*/
4754
@send
48-
external createMediaStreamSource: (audioContext, mediaStream) => mediaStreamAudioSourceNode =
55+
external createMediaStreamSource: (t, mediaStream) => mediaStreamAudioSourceNode =
4956
"createMediaStreamSource"
5057

5158
/**
5259
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AudioContext/createMediaStreamDestination)
5360
*/
5461
@send
55-
external createMediaStreamDestination: audioContext => mediaStreamAudioDestinationNode =
62+
external createMediaStreamDestination: t => mediaStreamAudioDestinationNode =
5663
"createMediaStreamDestination"
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
open WebAudioTypes
22

3-
include AudioNode.Impl({type t = audioDestinationNode})
3+
type t = audioDestinationNode = {...audioDestinationNode}
4+
5+
include AudioNode.Impl({type t = t})

src/WebAudioAPI/AudioNode.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
open WebAudioTypes
22

3+
type t = audioNode = {...audioNode}
4+
35
module Impl = (
46
T: {
57
type t
@@ -71,3 +73,5 @@ module Impl = (
7173
external disconnectParamOutput: (T.t, ~destinationParam: audioParam, ~output: int) => unit =
7274
"disconnect"
7375
}
76+
77+
include Impl({type t = t})

src/WebAudioAPI/AudioScheduledSourceNode.res

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
open WebAudioTypes
22

3+
type t = audioScheduledSourceNode = {...audioScheduledSourceNode}
4+
35
module Impl = (
46
T: {
57
type t
@@ -22,4 +24,4 @@ module Impl = (
2224
external stop: (T.t, ~when_: float=?) => unit = "stop"
2325
}
2426

25-
include Impl({type t = audioScheduledSourceNode})
27+
include Impl({type t = t})

src/WebAudioAPI/GainNode.res

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
open WebAudioTypes
22

3-
include AudioNode.Impl({type t = gainNode})
3+
type t = gainNode = {...gainNode}
4+
type gainOptions = WebAudioTypes.gainOptions = {...WebAudioTypes.gainOptions}
5+
6+
include AudioNode.Impl({type t = t})
47

58
/**
69
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/GainNode)
710
*/
811
@new
9-
external make: (~context: baseAudioContext, ~options: gainOptions=?) => gainNode = "GainNode"
12+
external make: (~context: baseAudioContext, ~options: gainOptions=?) => t = "GainNode"

src/WebAudioAPI/OscillatorNode.res

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
open WebAudioTypes
22

3-
include AudioScheduledSourceNode.Impl({type t = oscillatorNode})
3+
type t = oscillatorNode = {...oscillatorNode}
4+
type oscillatorOptions = WebAudioTypes.oscillatorOptions = {...WebAudioTypes.oscillatorOptions}
5+
type oscillatorType = WebAudioTypes.oscillatorType
6+
type periodicWave = WebAudioTypes.periodicWave = {...WebAudioTypes.periodicWave}
7+
8+
include AudioScheduledSourceNode.Impl({type t = t})
49

510
/**
611
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/OscillatorNode)
712
*/
813
@new
9-
external make: (~context: baseAudioContext, ~options: oscillatorOptions=?) => oscillatorNode =
10-
"OscillatorNode"
14+
external make: (~context: baseAudioContext, ~options: oscillatorOptions=?) => t = "OscillatorNode"
1115

1216
/**
1317
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/OscillatorNode/setPeriodicWave)
1418
*/
1519
@send
16-
external setPeriodicWave: (oscillatorNode, periodicWave) => unit = "setPeriodicWave"
20+
external setPeriodicWave: (t, periodicWave) => unit = "setPeriodicWave"

src/WebMIDI.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
open WebMIDITypes
2+
3+
type t = midiAccess = {...midiAccess}
4+
type midiOptions = WebMIDITypes.midiOptions = {...WebMIDITypes.midiOptions}

tests/NotificationsAPI/Notification__test.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
open WebAPI.NotificationTypes
1+
let current: Notification.notificationPermission = Notification.permission
22

3-
let current = Notification.permission
3+
let _notification: Notification.t = Notification.make(~title="Testing notifications")
44

55
Notification.requestPermission()
6-
->Promise.thenResolve(notificationPermission => {
6+
->Promise.thenResolve((notificationPermission: Notification.notificationPermission) => {
77
switch notificationPermission {
88
| Granted => Console.log("Permission granted")
99
| Denied => Console.log("Permission denied")

0 commit comments

Comments
 (0)