Skip to content

Commit 438d60b

Browse files
move the accessToken to header (#891)
Move the access_token to header in the format of 'Authorization': 'Bearer $token' --------- Co-authored-by: Hiroshi Horie <[email protected]>
1 parent 01e8415 commit 438d60b

22 files changed

+119
-121
lines changed

analysis_options.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ analyzer:
2020
constant_identifier_names: ignore
2121
no_wildcard_variable_uses: ignore
2222
use_super_parameters: ignore
23+
avoid_print: ignore
24+
use_build_context_synchronously: ignore
25+
discarded_futures: ignore
26+
prefer_final_locals: ignore
27+
depend_on_referenced_packages: ignore
28+
29+
# Suppress noisy or harmless warnings
30+
deprecated_member_use_from_same_package: ignore
31+
unused_element_parameter: ignore
32+
unintended_html_in_doc_comment: ignore
33+
implementation_imports: ignore
34+
invalid_runtime_check_with_js_interop_types: ignore
35+
unnecessary_import: ignore
2336

2437
# Exclude protobuf files
2538
exclude:

example/analysis_options.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ analyzer:
3131
constant_identifier_names: ignore
3232
no_wildcard_variable_uses: ignore
3333
use_super_parameters: ignore
34+
avoid_print: ignore
35+
use_build_context_synchronously: ignore
36+
# TODO, fix the discarded_futures problems and re-enable the warnings
37+
discarded_futures: ignore
38+
prefer_final_locals: ignore
39+
depend_on_referenced_packages: ignore
3440

3541
# Exclude protobuf files
3642
exclude:

lib/src/core/room.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
466466
for (final info in event.response.otherParticipants) {
467467
logger.fine('Creating RemoteParticipant: sid = ${info.sid}(identity:${info.identity}) '
468468
'tracks:${info.tracks.map((e) => e.sid)}');
469-
_getOrCreateRemoteParticipant(info.identity, info);
469+
await _getOrCreateRemoteParticipant(info.identity, info);
470470
}
471471

472472
if (e2eeManager != null && event.response.sifTrailer.isNotEmpty) {

lib/src/core/signal_client.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,14 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
142142
// Attempt to connect
143143
var future = _wsConnector(
144144
rtcUri,
145-
WebSocketEventHandlers(
145+
options: WebSocketEventHandlers(
146146
onData: _onSocketData,
147147
onDispose: _onSocketDispose,
148148
onError: _onSocketError,
149149
),
150+
headers: {
151+
'Authorization': 'Bearer $token',
152+
},
150153
);
151154
future = future.timeout(connectOptions.timeouts.connection);
152155
_ws = await future;
@@ -170,7 +173,12 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
170173
forceSecure: rtcUri.isSecureScheme,
171174
);
172175

173-
final validateResponse = await http.get(validateUri);
176+
final validateResponse = await http.get(
177+
validateUri,
178+
headers: {
179+
'Authorization': 'Bearer $token',
180+
},
181+
);
174182
if (validateResponse.statusCode != 200) {
175183
finalError = ConnectException(validateResponse.body,
176184
reason: validateResponse.statusCode >= 400

lib/src/options.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class RoomOptions {
152152
bool? dynacast,
153153
bool? stopLocalTrackOnUnpublish,
154154
E2EEOptions? e2eeOptions,
155+
E2EEOptions? encryption,
155156
bool? fastPublish,
156157
}) {
157158
return RoomOptions(

lib/src/participant/local.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ import '../types/other.dart';
5353
import '../types/participant_permissions.dart';
5454
import '../types/rpc.dart';
5555
import '../types/video_dimensions.dart';
56-
import 'participant.dart';
57-
5856
import '../utils.dart' show buildStreamId, mimeTypeToVideoCodecString, Utils, compareVersions, isSVCCodec;
57+
import 'participant.dart';
5958

6059
/// Represents the current participant in the room. Instance of [LocalParticipant] is automatically
6160
/// created after successfully connecting to a [Room] and will be accessible from [Room.localParticipant].

lib/src/publication/track_publication.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ abstract class TrackPublication<T extends Track> extends Disposable {
119119
void _attachTrackListener(T track) {
120120
// listen for Track's muted events
121121
final listener = track.createListener()
122-
..on<InternalTrackMuteUpdatedEvent>(
123-
(event) => _onTrackMuteUpdatedEvent(event));
122+
..on<InternalTrackMuteUpdatedEvent>((event) => _onTrackMuteUpdatedEvent(event));
124123
// dispose listener when the track is disposed
125124
track.onDispose(() => listener.dispose());
126125
}

lib/src/support/websocket.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@ class WebSocketEventHandlers {
3737
});
3838
}
3939

40-
typedef WebSocketConnector = Future<LiveKitWebSocket> Function(Uri uri, [WebSocketEventHandlers? options]);
40+
typedef WebSocketConnector = Future<LiveKitWebSocket> Function(
41+
Uri uri, {
42+
WebSocketEventHandlers? options,
43+
Map<String, String>? headers,
44+
});
4145

4246
abstract class LiveKitWebSocket extends Disposable {
4347
void send(List<int> data);
4448

45-
static Future<LiveKitWebSocket> connect(Uri uri, [WebSocketEventHandlers? options]) =>
46-
lkWebSocketConnect(uri, options);
49+
static Future<LiveKitWebSocket> connect(
50+
Uri uri, {
51+
WebSocketEventHandlers? options,
52+
Map<String, String>? headers,
53+
}) =>
54+
lkWebSocketConnect(uri, options: options, headers: headers);
4755
}

lib/src/support/websocket/io.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import '../../logger.dart';
2020
import '../websocket.dart';
2121

2222
Future<LiveKitWebSocketIO> lkWebSocketConnect(
23-
Uri uri, [
23+
Uri uri, {
2424
WebSocketEventHandlers? options,
25-
]) =>
26-
LiveKitWebSocketIO.connect(uri, options);
25+
Map<String, String>? headers,
26+
}) =>
27+
LiveKitWebSocketIO.connect(uri, options: options, headers: headers);
2728

2829
class LiveKitWebSocketIO extends LiveKitWebSocket {
2930
final io.WebSocket _ws;
@@ -70,12 +71,13 @@ class LiveKitWebSocketIO extends LiveKitWebSocket {
7071
}
7172

7273
static Future<LiveKitWebSocketIO> connect(
73-
Uri uri, [
74+
Uri uri, {
7475
WebSocketEventHandlers? options,
75-
]) async {
76+
Map<String, String>? headers,
77+
}) async {
7678
logger.fine('[WebSocketIO] Connecting(uri: ${uri.toString()})...');
7779
try {
78-
final ws = await io.WebSocket.connect(uri.toString());
80+
final ws = await io.WebSocket.connect(uri.toString(), headers: headers);
7981
logger.fine('[WebSocketIO] Connected');
8082
return LiveKitWebSocketIO._(ws, options);
8183
} catch (err) {

lib/src/support/websocket/web.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ import '../websocket.dart';
2525
// ignore: avoid_web_libraries_in_flutter
2626

2727
Future<LiveKitWebSocketWeb> lkWebSocketConnect(
28-
Uri uri, [
28+
Uri uri, {
2929
WebSocketEventHandlers? options,
30-
]) =>
30+
Map<String, String>? headers, // |headers| will be ignored on web
31+
}) =>
3132
LiveKitWebSocketWeb.connect(uri, options);
3233

3334
class LiveKitWebSocketWeb extends LiveKitWebSocket {
@@ -39,6 +40,7 @@ class LiveKitWebSocketWeb extends LiveKitWebSocket {
3940
LiveKitWebSocketWeb._(
4041
this._ws, [
4142
this.options,
43+
Map<String, String>? headers,
4244
]) {
4345
_ws.binaryType = 'arraybuffer';
4446
_messageSubscription = _ws.onMessage.listen((_) {

0 commit comments

Comments
 (0)