Skip to content

Commit

Permalink
chore: Tidy up the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Aug 4, 2022
1 parent e4fd32a commit 93a4856
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 73 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

A webrtc interface wrapped in dart language.


Use the [dart/js](https://pub.dev/packages/js) library to re-wrap the [webrtc](https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API) js interface of the browser, to adapted common browsers.

This library will be used for [flutter-webrtc](https://github.com/flutter-webrtc/flutter-webrtc) for [flutter web](https://flutter.dev/web) plugin.



## How to develop

* `git clone https://github.com/flutter-webrtc/dart-webrtc && cd dart-webrtc`
Expand Down
2 changes: 0 additions & 2 deletions lib/src/media_devices.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:webrtc_interface/webrtc_interface.dart';
import '../dart_webrtc.dart';
import 'factory_impl.dart';

class MediaDevices {
@Deprecated(
Expand Down
2 changes: 0 additions & 2 deletions lib/src/media_recorder.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:webrtc_interface/src/media_recorder.dart' as _interface;
import 'package:webrtc_interface/webrtc_interface.dart';

import '../dart_webrtc.dart';
import 'factory_impl.dart';

class MediaRecorder extends _interface.MediaRecorder {
MediaRecorder() : _delegate = mediaRecorder();
Expand Down
1 change: 0 additions & 1 deletion lib/src/mediadevices_impl.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:html' as html;
import 'dart:html_common';
import 'dart:js' as js;
import 'dart:js_util' as jsutil;
import 'package:webrtc_interface/webrtc_interface.dart';
Expand Down
2 changes: 1 addition & 1 deletion web/p2p/p2p.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:html' as html;
import 'package:test/test.dart';

import 'package:dart_webrtc/dart_webrtc.dart';
import 'package:js/js.dart';
import 'package:test/test.dart';

import 'signaling.dart';

Expand Down
52 changes: 26 additions & 26 deletions web/test_media_stream.dart
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import 'package:dart_webrtc/dart_webrtc.dart';
import 'package:test/test.dart';

late MediaStream mediaStream;
MediaStream? mediaStream;

List<void Function()> testFunctions = <void Function()>[
() => test('MediaStream.constructor()', () async {
() => test('mediaStream?.constructor()', () async {
mediaStream = await navigator.mediaDevices
.getUserMedia({'audio': true, 'video': true});

expect(mediaStream.id != null, true);
expect(mediaStream?.id != null, true);
}),
() => test('MediaStream.active()', () {
expect(mediaStream.active, true);
() => test('mediaStream?.active()', () {
expect(mediaStream?.active, true);
}),
() => test('MediaStream.getTracks()', () {
expect(mediaStream.getTracks().length, 2);
() => test('mediaStream?.getTracks()', () {
expect(mediaStream?.getTracks().length, 2);
}),
() => test('MediaStream.getAudioTracks()', () {
expect(mediaStream.getAudioTracks().length, 1);
var track =
mediaStream.getTrackById(mediaStream.getAudioTracks()[0].id!);
expect(track?.id, mediaStream.getAudioTracks()[0].id);
() => test('mediaStream?.getAudioTracks()', () {
expect(mediaStream?.getAudioTracks().length, 1);
var track = mediaStream
?.getTrackById(mediaStream?.getAudioTracks()[0].id ?? '');
expect(track?.id, mediaStream?.getAudioTracks()[0].id);
}),
() => test('MediaStream.getVideoTracks()', () {
expect(mediaStream.getVideoTracks().length, 1);
var track =
mediaStream.getTrackById(mediaStream.getVideoTracks()[0].id!);
expect(track!.id, mediaStream.getVideoTracks()[0].id);
() => test('mediaStream?.getVideoTracks()', () {
expect(mediaStream?.getVideoTracks().length, 1);
var track = mediaStream
?.getTrackById(mediaStream?.getVideoTracks()[0].id ?? '');
expect(track!.id, mediaStream?.getVideoTracks()[0].id);
}),
() => test('MediaStream.removeTrack()', () {
var track =
mediaStream.getTrackById(mediaStream.getVideoTracks()[0].id!);
mediaStream.removeTrack(track!);
expect(mediaStream.getVideoTracks().length, 0);
() => test('mediaStream?.removeTrack()', () {
var track = mediaStream
?.getTrackById(mediaStream?.getVideoTracks()[0].id ?? '');
mediaStream?.removeTrack(track!);
expect(mediaStream?.getVideoTracks().length, 0);
}),
() => test('MediaStream.close()', () {
mediaStream.getTracks().forEach((element) {
() => test('mediaStream?.close()', () {
mediaStream?.getTracks().forEach((element) {
element.stop();
mediaStream.removeTrack(element);
mediaStream?.removeTrack(element);
});
expect(mediaStream.getTracks().isEmpty, true);
expect(mediaStream?.getTracks().isEmpty, true);
})
];
48 changes: 23 additions & 25 deletions web/test_media_stream_track.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'dart:html';

import 'package:dart_webrtc/dart_webrtc.dart';
import 'package:test/test.dart';

late MediaStreamTrack audioTrack, videoTrack;
MediaStreamTrack? audioTrack, videoTrack;

List<void Function()> testFunctions = <void Function()>[
() => test('MediaStreamTrack.constructor()', () async {
Expand All @@ -13,43 +11,43 @@ List<void Function()> testFunctions = <void Function()>[
audioTrack = stream.getAudioTracks()[0];
expect(audioTrack != null, true);

expect(audioTrack.kind, 'audio');
expect(audioTrack?.kind, 'audio');

videoTrack = stream.getVideoTracks()[0];
expect(videoTrack != null, true);

expect(videoTrack.kind, 'video');
expect(videoTrack?.kind, 'video');
}),
() => test('MediaStreamTrack.id()', () {
expect(audioTrack.id is String, true);
expect(audioTrack.id?.isNotEmpty, true);
expect(videoTrack.id is String, true);
expect(videoTrack.id?.isNotEmpty, true);
expect(audioTrack?.id is String, true);
expect(audioTrack?.id?.isNotEmpty, true);
expect(videoTrack?.id is String, true);
expect(videoTrack?.id?.isNotEmpty, true);
}),
() => test('MediaStreamTrack.label()', () {
expect(audioTrack.label is String, true);
expect(audioTrack.id?.isNotEmpty, true);
expect(videoTrack.id is String, true);
expect(videoTrack.id?.isNotEmpty, true);
expect(audioTrack?.label is String, true);
expect(audioTrack?.id?.isNotEmpty, true);
expect(videoTrack?.id is String, true);
expect(videoTrack?.id?.isNotEmpty, true);
}),
() => test('MediaStreamTrack.enabled()', () {
expect(audioTrack.enabled, true);
audioTrack.enabled = false;
expect(audioTrack.enabled, false);
expect(audioTrack?.enabled, true);
audioTrack?.enabled = false;
expect(audioTrack?.enabled, false);

expect(videoTrack.enabled, true);
videoTrack.enabled = false;
expect(videoTrack.enabled, false);
expect(videoTrack?.enabled, true);
videoTrack?.enabled = false;
expect(videoTrack?.enabled, false);
}),
() => test('MediaStreamTrack.readyState() | MediaStreamTrack.stop()', () {
/*
expect(audioTrack.readyState, 'live');
audioTrack.stop();
expect(audioTrack.readyState, 'ended');
expect(audioTrack?.readyState, 'live');
audioTrack?.stop();
expect(audioTrack?.readyState, 'ended');
expect(videoTrack.readyState, 'live');
videoTrack.stop();
expect(videoTrack.readyState, 'ended');
expect(videoTrack?.readyState, 'live');
videoTrack?.stop();
expect(videoTrack?.readyState, 'ended');
*/
})
];
26 changes: 13 additions & 13 deletions web/test_video_element.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import 'package:dart_webrtc/dart_webrtc.dart';
import 'package:test/test.dart';

late RTCVideoElement localVideo;
late RTCVideoElement? localVideo;

List<void Function()> testFunctions = <void Function()>[
() => test('RTCVideoElement.constructor()', () {
localVideo = RTCVideoElement();
expect(localVideo != null, true);
}),
() => test('RTCVideoElement.muted()', () {
localVideo.muted = true;
expect(localVideo.muted, true);
localVideo.muted = false;
expect(localVideo.muted, false);
localVideo?.muted = true;
expect(localVideo?.muted, true);
localVideo?.muted = false;
expect(localVideo?.muted, false);
}),
() => test('RTCVideoElement.controls()', () {
localVideo.controls = false;
expect(localVideo.controls, false);
localVideo.controls = true;
expect(localVideo.controls, true);
localVideo?.controls = false;
expect(localVideo?.controls, false);
localVideo?.controls = true;
expect(localVideo?.controls, true);
}),
() => test('RTCVideoElement.autoplay()', () {
localVideo.autoplay = false;
expect(localVideo.autoplay, false);
localVideo.autoplay = true;
expect(localVideo.autoplay, true);
localVideo?.autoplay = false;
expect(localVideo?.autoplay, false);
localVideo?.autoplay = true;
expect(localVideo?.autoplay, true);
})
];

0 comments on commit 93a4856

Please sign in to comment.