Skip to content

Commit

Permalink
used dart2native compiler to generate self-sufficient executable bina…
Browse files Browse the repository at this point in the history
…ry, which can run on any machine ( though not platform-agnostic yet )
  • Loading branch information
itzmeanjan committed Nov 18, 2019
1 parent a7df401 commit 1951911
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 32 deletions.
58 changes: 39 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,49 @@ _Recently I wrote an article, explaining how to deploy it using systemd in LAN,
- Frontend, powered by _HTML_, _CSS_ & last but not least _Javascript_ _( yeah not using any UI framework )_
- Audio-Video playing is done using HTML5 **\<video>** element, which can play _mp4_ & _webm_ video(s) generally
## how can I use it ?
- Simply fork this repo & clone it in you machine
- Make sure you've installed _Dart SDK_ & you're on _*nix_ platform
- Because I gonna use _systemd.service_ to keep this streaming service alive in background, always, even after system restarts it'll auto start itself
- 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
- Start streaming server, which will be available via port 8000
- 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 )_.
- Then download [_this_](.) compressed file, and unzip it into a suitable location on your machine.
- You'll get a directory tree like below
```shell script
$ cd bin # assuming you're already at root of project directory
$ dart main.dart
```
- Consider using _Ahead Of Time_-compiled version _( at production )_, for better performance
```shell script
$ dart2aot main.dart main.dart.aot // compilation
$ dartaotruntime main.dart.aot
$ cd
$ unzip streamZ.zip # unzipping it
$ cd streamZ # getting into actual directory
$ tree -h
.
├── [4.0K] final
│   └── [7.8M] streamZ
└── [4.0K] frontend
├── [4.0K] images
│   └── [ 318] favicon.ico
├── [4.0K] pages
│   └── [1.0K] index.html
├── [4.0K] scripts
│   └── [9.7K] index.js
└── [4.0K] styles
└── [2.0K] index.css

6 directories, 5 files
```
- If you're having a lot of traffic, consider using multiple Isolates to handle traffic efficiently
- Now get into `./final` directory & run executable binary, which will start a media streaming server on _http://0.0.0.0:8000_
```shell script
$ dartaotruntime main.dart.aot 2 // using two Isolates
$ dartaotruntime main.dart.aot n // using n Isolates, n >= 1
$ cd final
$ ./streamZ # running movie steaming server
[+]streamZ_v1.0.0 listening ( streamZ0 ) ...

[+]streamZ_v1.0.0 listening ( streamZ1 ) ...

```
- Now you can simply use this streaming service by opening `http://ip-addr-server:8000/`, on any device's browser present in LAN
- For using service from same machine, simply use `http://localhost:8000/` from your favourite browser
- Deploying via _systemd.service_, to be explained in a blog post, to be published soon
- 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.
- You can also access this streaming service by opening _http://x.x.x.x:8000/_,on any device's browser, present in LAN
- Where `x.x.x.x` is nothing but Local IP Address of machine, running **streamZ**
---
- If you want to dig deeper, simply fork this repo & clone it in you machine
- Make sure you've installed _Dart SDK_ & you're on _*nix_ platform
- Because I gonna use _systemd.service_ to keep this streaming service alive in background, always, even after system restarts it'll auto start itself
- 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
- 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.
- 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 )_
- Consider using so, by modifying this systemd unit [file](./systemd/streamZ.service)
## how does it look like ?
![screenCapture_1](screencaptures/screenCapture_1.png)

Expand Down
14 changes: 3 additions & 11 deletions bin/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:io' show InternetAddress;
import 'dart:isolate' show Isolate, ReceivePort, SendPort;
import 'package:streamZ/streamZ.dart' as streamZ;
import 'package:streamZ/streamZ.dart' as streamz;
import 'package:streamZ/performance.dart';

/*
Expand All @@ -19,7 +19,7 @@ spawnHandler(SendPort sendPort) {
receivePort.close(); // no more required, so closing it
},
cancelOnError: true,
onDone: () => streamZ.createServer(InternetAddress.anyIPv4, sendPorts),
onDone: () => streamz.createServer(InternetAddress.anyIPv4, sendPorts),
);
sendPort.send(receivePort.sendPort);
}
Expand Down Expand Up @@ -97,15 +97,7 @@ requestHandlingStatisticsMaintainer(SendPort sendPort) {
each of them running in a different Isolate
*/
main(List<String> args) {
int count = 1;
if (args.isNotEmpty) {
try {
count = int.parse(args[0], radix: 10);
count = count < 1 ? 1 : count; // just a safeguard
} on Exception {
count = 1;
}
}
int count = 2;
SendPort sendPortToGetPerformance;
SendPort sendPortToSetPerformance;
ReceivePort performanceInfoHolderReceivePort = ReceivePort();
Expand Down
Binary file removed bin/main.dart.aot
Binary file not shown.
Binary file removed bin/main.dart.aot.dill
Binary file not shown.
Binary file added final/streamZ
Binary file not shown.
1 change: 0 additions & 1 deletion lib/streamZ.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'dart:isolate';
import 'package:path/path.dart' as path;
import 'dart:io';
import 'dart:math' show Random;
import 'dart:typed_data' show Uint8List;

import 'package:streamZ/movies.dart';
import 'package:streamZ/playList.dart';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: streamZ
description: A simple video streaming application made with Dart, JS, HTML & CSS
version: 1.0.0
version: 1.0.1
homepage: https://github.com/itzmeanjan/streamZ.git
author: Anjan Roy <anjanroy@yandex.com>

Expand Down

0 comments on commit 1951911

Please sign in to comment.