@@ -26,24 +26,8 @@ data JSWebSocket = JSWebSocket { wsValue :: JSValueRef
2626 , wsContext :: JSContextRef
2727 }
2828
29−getLocationHost :: WebView -> IO String
30−getLocationHost wv = do
31− c <- webFrameGetGlobalContext =<< webViewGetMainFrame wv
32− script <- jsstringcreatewithutf8cstring "location.host"
33− lh <- jsevaluatescript c script nullPtr nullPtr 1 nullPtr
34− lh' <- fromJSStringMaybe c lh
35− return $ maybe "" id lh'
36−
37−getLocationProtocol :: WebView -> IO String
38−getLocationProtocol wv = do
39− c <- webFrameGetGlobalContext =<< webViewGetMainFrame wv
40− script <- jsstringcreatewithutf8cstring "location.protocol"
41− lp <- jsevaluatescript c script nullPtr nullPtr 1 nullPtr
42− lp' <- fromJSStringMaybe c lp
43− return $ maybe "" id lp'
44−
45−newWebSocket :: WebView -> String -> (ByteString -> IO ()) -> IO () -> IO JSWebSocket
46−newWebSocket wv url onMessage onClose = do
29+newWebSocket :: WebView -> String -> (ByteString -> IO ()) -> IO () -> IO () -> IO JSWebSocket
30+newWebSocket wv url onMessage onOpen onClose = do
4731 c <- webFrameGetGlobalContext =<< webViewGetMainFrame wv
4832 url' <- jsvaluemakestring c =<< jsstringcreatewithutf8cstring url
4933 newWSArgs <- toJSObject c [url']
@@ -59,12 +43,16 @@ newWebSocket wv url onMessage onClose = do
5943 Just m -> onMessage $ encodeUtf8 $ T.pack m
6044 jsvaluemakeundefined c
6145 onMessageCb <- jsobjectmakefunctionwithcallback c nullPtr onMessage'
46+ onOpen' <- wrapper $ \_ _ _ _ _ _ -> do
47+ onOpen
48+ jsvaluemakeundefined c
49+ onOpenCb <- jsobjectmakefunctionwithcallback c nullPtr onOpen'
6250 onClose' <- wrapper $ \_ _ _ _ _ _ -> do
6351 onClose
6452 jsvaluemakeundefined c
6553 onCloseCb <- jsobjectmakefunctionwithcallback c nullPtr onClose'
66− o <- toJSObject c [ws, onMessageCb, onCloseCb]
67− addCbs <- jsstringcreatewithutf8cstring "this[0]['onmessage'] = this[1]; this[0]['onclose'] = this[2];"
54+ o <- toJSObject c [ws, onMessageCb, onOpenCb, onCloseCb]
55+ addCbs <- jsstringcreatewithutf8cstring "this[0]['onmessage'] = this[1]; this[0]['onopen'] = this[2]; this[0]['onclose'] = this[3];"
6856 _ <- jsevaluatescript c addCbs o nullPtr 1 nullPtr
6957 return $ JSWebSocket ws c
7058