Skip to content

Commit 1951911

Browse files
committed
used dart2native compiler to generate self-sufficient executable binary, which can run on any machine ( though not platform-agnostic yet )
1 parent a7df401 commit 1951911

File tree

7 files changed

+43
-32
lines changed

7 files changed

+43
-32
lines changed

README.md

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,49 @@ _Recently I wrote an article, explaining how to deploy it using systemd in LAN,
1111
- Frontend, powered by _HTML_, _CSS_ & last but not least _Javascript_ _( yeah not using any UI framework )_
1212
- Audio-Video playing is done using HTML5 **\<video>** element, which can play _mp4_ & _webm_ video(s) generally
1313
## how can I use it ?
14-
- Simply fork this repo & clone it in you machine
15-
- Make sure you've installed _Dart SDK_ & you're on _*nix_ platform
16-
- Because I gonna use _systemd.service_ to keep this streaming service alive in background, always, even after system restarts it'll auto start itself
17-
- You need to make sure, you've _~/Videos/_ directory present on your system, cause we'll read from that directory _( every 30 minutes )_, to ensure all _mp4_ & _webm_
18-
videos, present in aforementioned directory, are listed in movie playlist
19-
- Start streaming server, which will be available via port 8000
14+
- If you're on _Linux_, then I've already compiled **streamZ** into an executable binary _( using dart2native compiler )_, which can be simply run on any Linux Machine, cause that executable binary is one self-sufficient one _( but not yet platform-agnostic, which will change is near future )_.
15+
- Then download [_this_](.) compressed file, and unzip it into a suitable location on your machine.
16+
- You'll get a directory tree like below
2017
```shell script
21-
$ cd bin # assuming you're already at root of project directory
22-
$ dart main.dart
23-
```
24-
- Consider using _Ahead Of Time_-compiled version _( at production )_, for better performance
25-
```shell script
26-
$ dart2aot main.dart main.dart.aot // compilation
27-
$ dartaotruntime main.dart.aot
18+
$ cd
19+
$ unzip streamZ.zip # unzipping it
20+
$ cd streamZ # getting into actual directory
21+
$ tree -h
22+
.
23+
├── [4.0K] final
24+
│   └── [7.8M] streamZ
25+
└── [4.0K] frontend
26+
├── [4.0K] images
27+
│   └── [ 318] favicon.ico
28+
├── [4.0K] pages
29+
│   └── [1.0K] index.html
30+
├── [4.0K] scripts
31+
│   └── [9.7K] index.js
32+
└── [4.0K] styles
33+
└── [2.0K] index.css
34+
35+
6 directories, 5 files
2836
```
29-
- If you're having a lot of traffic, consider using multiple Isolates to handle traffic efficiently
37+
- Now get into `./final` directory & run executable binary, which will start a media streaming server on _http://0.0.0.0:8000_
3038
```shell script
31-
$ dartaotruntime main.dart.aot 2 // using two Isolates
32-
$ dartaotruntime main.dart.aot n // using n Isolates, n >= 1
39+
$ cd final
40+
$ ./streamZ # running movie steaming server
41+
[+]streamZ_v1.0.0 listening ( streamZ0 ) ...
42+
43+
[+]streamZ_v1.0.0 listening ( streamZ1 ) ...
44+
3345
```
34-
- Now you can simply use this streaming service by opening `http://ip-addr-server:8000/`, on any device's browser present in LAN
35-
- For using service from same machine, simply use `http://localhost:8000/` from your favourite browser
36-
- Deploying via _systemd.service_, to be explained in a blog post, to be published soon
46+
- To check, open browser from same machine & type _http://localhost:8000_ into address bar, you'll get a list of all movies present under _~/Videos/_ directory, which is default video storing directory on _Linux_ running machines.
47+
- You can also access this streaming service by opening _http://x.x.x.x:8000/_,on any device's browser, present in LAN
48+
- Where `x.x.x.x` is nothing but Local IP Address of machine, running **streamZ**
49+
---
50+
- If you want to dig deeper, simply fork this repo & clone it in you machine
51+
- Make sure you've installed _Dart SDK_ & you're on _*nix_ platform
52+
- Because I gonna use _systemd.service_ to keep this streaming service alive in background, always, even after system restarts it'll auto start itself
53+
- You need to make sure, you've _~/Videos/_ directory present on your system, cause we'll read from that directory _( every 30 minutes )_, to ensure all _mp4_ & _webm_ videos, present in aforementioned directory, are listed in movie playlist
54+
- If you're having a lot of traffic, consider using multiple Isolates to handle traffic efficiently. Just update `int count = 2;` on line 100 of `./bin/main.dart` to whatever value you intend to use, that many Isolate(s) will be created on boot, they'll distributedly handle whole traffic coming in.
55+
- I've also written one systemd unit file, which can be used for deploying **streamZ**, so that it'll keep running always _( autostart after failure & system boot )_
56+
- Consider using so, by modifying this systemd unit [file](./systemd/streamZ.service)
3757
## how does it look like ?
3858
![screenCapture_1](screencaptures/screenCapture_1.png)
3959

bin/main.dart

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dart:io' show InternetAddress;
22
import 'dart:isolate' show Isolate, ReceivePort, SendPort;
3-
import 'package:streamZ/streamZ.dart' as streamZ;
3+
import 'package:streamZ/streamZ.dart' as streamz;
44
import 'package:streamZ/performance.dart';
55

66
/*
@@ -19,7 +19,7 @@ spawnHandler(SendPort sendPort) {
1919
receivePort.close(); // no more required, so closing it
2020
},
2121
cancelOnError: true,
22-
onDone: () => streamZ.createServer(InternetAddress.anyIPv4, sendPorts),
22+
onDone: () => streamz.createServer(InternetAddress.anyIPv4, sendPorts),
2323
);
2424
sendPort.send(receivePort.sendPort);
2525
}
@@ -97,15 +97,7 @@ requestHandlingStatisticsMaintainer(SendPort sendPort) {
9797
each of them running in a different Isolate
9898
*/
9999
main(List<String> args) {
100-
int count = 1;
101-
if (args.isNotEmpty) {
102-
try {
103-
count = int.parse(args[0], radix: 10);
104-
count = count < 1 ? 1 : count; // just a safeguard
105-
} on Exception {
106-
count = 1;
107-
}
108-
}
100+
int count = 2;
109101
SendPort sendPortToGetPerformance;
110102
SendPort sendPortToSetPerformance;
111103
ReceivePort performanceInfoHolderReceivePort = ReceivePort();

bin/main.dart.aot

-3.27 MB
Binary file not shown.

bin/main.dart.aot.dill

-4.58 MB
Binary file not shown.

final/streamZ

7.76 MB
Binary file not shown.

lib/streamZ.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'dart:isolate';
55
import 'package:path/path.dart' as path;
66
import 'dart:io';
77
import 'dart:math' show Random;
8-
import 'dart:typed_data' show Uint8List;
98

109
import 'package:streamZ/movies.dart';
1110
import 'package:streamZ/playList.dart';

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: streamZ
22
description: A simple video streaming application made with Dart, JS, HTML & CSS
3-
version: 1.0.0
3+
version: 1.0.1
44
homepage: https://github.com/itzmeanjan/streamZ.git
55
author: Anjan Roy <anjanroy@yandex.com>
66

0 commit comments

Comments
 (0)