@@ -103,14 +103,17 @@ interface TransportInitOptions {
103103
104104export const dialDirect = async (
105105 address : string ,
106- opts ?: DialOptions
106+ opts ?: DialOptions ,
107+ transportCredentialsInclude = false
107108) : Promise < Transport > => {
108109 validateDialOptions ( opts ) ;
109110 const createTransport =
110111 globalThis . VIAM ?. GRPC_TRANSPORT_FACTORY ?? createGrpcWebTransport ;
111112
112113 const transportOpts = {
113114 baseUrl : address ,
115+ // Default is "same-origin", which does not include localhost:*.
116+ credentials : 'same-origin' as RequestCredentials ,
114117 } ;
115118
116119 // Client already has access token with no external auth, skip Authenticate process.
@@ -133,6 +136,10 @@ export const dialDirect = async (
133136 opts === undefined ||
134137 ( opts . credentials === undefined && opts . accessToken === undefined )
135138 ) {
139+ // With same-origin, services running on other ports that expect cookies from App would otherwise not receive them.
140+ if ( transportCredentialsInclude ) {
141+ transportOpts . credentials = 'include' ;
142+ }
136143 return createTransport ( transportOpts ) ;
137144 }
138145
@@ -305,10 +312,15 @@ export interface WebRTCConnection {
305312const getOptionalWebRTCConfig = async (
306313 signalingAddress : string ,
307314 callOpts : CallOptions ,
308- dialOpts ?: DialOptions
315+ dialOpts ?: DialOptions ,
316+ transportCredentialsInclude = false
309317) : Promise < WebRTCConfig > => {
310318 const optsCopy = { ...dialOpts } as DialOptions ;
311- const directTransport = await dialDirect ( signalingAddress , optsCopy ) ;
319+ const directTransport = await dialDirect (
320+ signalingAddress ,
321+ optsCopy ,
322+ transportCredentialsInclude
323+ ) ;
312324
313325 const signalingClient = createClient ( SignalingService , directTransport ) ;
314326 try {
@@ -333,7 +345,8 @@ const getOptionalWebRTCConfig = async (
333345export const dialWebRTC = async (
334346 signalingAddress : string ,
335347 host : string ,
336- dialOpts ?: DialOptions
348+ dialOpts ?: DialOptions ,
349+ transportCredentialsInclude = false
337350) : Promise < WebRTCConnection > => {
338351 const usableSignalingAddress = signalingAddress . replace ( / \/ $ / u, '' ) ;
339352 validateDialOptions ( dialOpts ) ;
@@ -356,7 +369,8 @@ export const dialWebRTC = async (
356369 const webrtcOpts = await processWebRTCOpts (
357370 usableSignalingAddress ,
358371 callOpts ,
359- dialOpts
372+ dialOpts ,
373+ transportCredentialsInclude
360374 ) ;
361375 // then derive options specifically for signaling against our target.
362376 const exchangeOpts = processSignalingExchangeOpts (
@@ -373,7 +387,11 @@ export const dialWebRTC = async (
373387
374388 let directTransport : Transport ;
375389 try {
376- directTransport = await dialDirect ( usableSignalingAddress , exchangeOpts ) ;
390+ directTransport = await dialDirect (
391+ usableSignalingAddress ,
392+ exchangeOpts ,
393+ transportCredentialsInclude
394+ ) ;
377395 } catch ( error ) {
378396 pc . close ( ) ;
379397 throw error ;
@@ -429,13 +447,15 @@ export const dialWebRTC = async (
429447const processWebRTCOpts = async (
430448 signalingAddress : string ,
431449 callOpts : CallOptions ,
432- dialOpts ?: DialOptions
450+ dialOpts ?: DialOptions ,
451+ transportCredentialsInclude = false
433452) : Promise < DialWebRTCOptions > => {
434453 // Get TURN servers, if any.
435454 const config = await getOptionalWebRTCConfig (
436455 signalingAddress ,
437456 callOpts ,
438- dialOpts
457+ dialOpts ,
458+ transportCredentialsInclude
439459 ) ;
440460 const additionalIceServers : RTCIceServer [ ] = config . additionalIceServers . map (
441461 ( ice ) => {
0 commit comments