@@ -26,24 +26,8 @@ data JSWebSocket = JSWebSocket { wsValue :: JSValueRef
26 , wsContext :: JSContextRef
26 , wsContext :: JSContextRef
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'
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'
45−newWebSocket :: WebView -> String -> (ByteString -> IO ()) -> IO () -> IO JSWebSocket
29+newWebSocket :: WebView -> String -> (ByteString -> IO ()) -> IO () -> IO () -> IO JSWebSocket
46−newWebSocket wv url onMessage onClose = do
30+newWebSocket wv url onMessage onOpen onClose = do
47 c <- webFrameGetGlobalContext =<< webViewGetMainFrame wv
31 c <- webFrameGetGlobalContext =<< webViewGetMainFrame wv
48 url' <- jsvaluemakestring c =<< jsstringcreatewithutf8cstring url
32 url' <- jsvaluemakestring c =<< jsstringcreatewithutf8cstring url
49 newWSArgs <- toJSObject c [url']
33 newWSArgs <- toJSObject c [url']
@@ -59,12 +43,16 @@ newWebSocket wv url onMessage onClose = do
59 Just m -> onMessage $ encodeUtf8 $ T.pack m
43 Just m -> onMessage $ encodeUtf8 $ T.pack m
60 jsvaluemakeundefined c
44 jsvaluemakeundefined c
61 onMessageCb <- jsobjectmakefunctionwithcallback c nullPtr onMessage'
45 onMessageCb <- jsobjectmakefunctionwithcallback c nullPtr onMessage'
46+ onOpen' <- wrapper $ \_ _ _ _ _ _ -> do
48+ jsvaluemakeundefined c
49+ onOpenCb <- jsobjectmakefunctionwithcallback c nullPtr onOpen'
62 onClose' <- wrapper $ \_ _ _ _ _ _ -> do
50 onClose' <- wrapper $ \_ _ _ _ _ _ -> do
64 jsvaluemakeundefined c
52 jsvaluemakeundefined c
65 onCloseCb <- jsobjectmakefunctionwithcallback c nullPtr onClose'
53 onCloseCb <- jsobjectmakefunctionwithcallback c nullPtr onClose'
66− o <- toJSObject c [ws, onMessageCb, onCloseCb]
54+ o <- toJSObject c [ws, onMessageCb, onOpenCb, onCloseCb]
67− addCbs <- jsstringcreatewithutf8cstring "this[0]['onmessage'] = this[1]; this[0]['onclose'] = this[2];"
55+ addCbs <- jsstringcreatewithutf8cstring "this[0]['onmessage'] = this[1]; this[0]['onopen'] = this[2]; this[0]['onclose'] = this[3];"
68 _ <- jsevaluatescript c addCbs o nullPtr 1 nullPtr
56 _ <- jsevaluatescript c addCbs o nullPtr 1 nullPtr
69 return $ JSWebSocket ws c
57 return $ JSWebSocket ws c