DialWebsocket establishes a SockJS session over a websocket connection. Requires cfg.Websocket to be a valid client.
(uri string, cfg *config.Config)
| 134 | // |
| 135 | // Requires cfg.Websocket to be a valid client. |
| 136 | func DialWebsocket(uri string, cfg *config.Config) (*WebsocketSession, error) { |
| 137 | u, err := url.Parse(uri) |
| 138 | if err != nil { |
| 139 | return nil, err |
| 140 | } |
| 141 | |
| 142 | h := http.Header{ |
| 143 | "Origin": {u.Scheme + "://" + u.Host}, |
| 144 | } |
| 145 | |
| 146 | serverID := threeDigits() |
| 147 | sessionID := utils.RandomString(20) |
| 148 | |
| 149 | u = makeWebsocketURL(u, serverID, sessionID) |
| 150 | |
| 151 | conn, _, err := cfg.Websocket.Dial(u.String(), h) |
| 152 | if err != nil { |
| 153 | return nil, err |
| 154 | } |
| 155 | |
| 156 | session := NewWebsocketSession(conn) |
| 157 | session.id = sessionID |
| 158 | session.req = &http.Request{ |
| 159 | URL: u, |
| 160 | Header: h, |
| 161 | } |
| 162 | |
| 163 | return session, nil |
| 164 | } |
| 165 | |
| 166 | // ConnectWebsocketSession dials the remote specified in the opts and |
| 167 | // creates new websocket session. |
no test coverage detected