Skip to content

Commit c756cfb

Browse files
committed
Echo connection made
1 parent 1196f88 commit c756cfb

File tree

9 files changed

+402
-287
lines changed

9 files changed

+402
-287
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
use Illuminate\Broadcasting\Channel;
5+
use Illuminate\Support\Facades\Notification;
6+
7+
use Illuminate\Http\Request;
8+
9+
class CallController extends Controller
10+
{
11+
//
12+
public function call(Request $request) {
13+
Notification::route('broadcast', [new Channel($request->caller_id)])
14+
->notify(new \App\Notifications\StartCall($request->sdp, $request->callee_id));
15+
return response()->json([
16+
'success' => true
17+
]);
18+
}
19+
20+
public function answer(Request $request) {
21+
Notification::route('broadcast', [new Channel($request->caller_id)])
22+
->notify(new \App\Notifications\AnswerCall($request->sdp));
23+
return response()->json([
24+
'success' => true
25+
]);
26+
}
27+
}

app/Notifications/AnswerCall.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace App\Notifications;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Notifications\Messages\MailMessage;
8+
use Illuminate\Notifications\Notification;
9+
use Illuminate\Notifications\Messages\BroadcastMessage;
10+
class AnswerCall extends Notification implements ShouldQueue
11+
{
12+
use Queueable;
13+
private $sdp;
14+
/**
15+
* Create a new notification instance.
16+
*/
17+
public function __construct($sdp)
18+
{
19+
//
20+
$this->sdp = $sdp;
21+
}
22+
23+
/**
24+
* Get the notification's delivery channels.
25+
*
26+
* @return array<int, string>
27+
*/
28+
public function via(object $notifiable): array
29+
{
30+
return ['broadcast'];
31+
}
32+
33+
/**
34+
* Get the mail representation of the notification.
35+
*/
36+
public function toMail(object $notifiable): MailMessage
37+
{
38+
return (new MailMessage)
39+
->line('The introduction to the notification.')
40+
->action('Notification Action', url('/'))
41+
->line('Thank you for using our application!');
42+
}
43+
44+
/**
45+
* Get the array representation of the notification.
46+
*
47+
* @return array<string, mixed>
48+
*/
49+
public function toArray(object $notifiable): array
50+
{
51+
return [
52+
//
53+
];
54+
}
55+
56+
public function toBroadcast(object $notifiable): BroadcastMessage
57+
{
58+
return new BroadcastMessage([
59+
'sdp' => $this->sdp,
60+
]);
61+
}
62+
}

app/Notifications/StartCall.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace App\Notifications;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Notifications\Messages\MailMessage;
8+
use Illuminate\Notifications\Notification;
9+
use Illuminate\Notifications\Messages\BroadcastMessage;
10+
class StartCall extends Notification implements ShouldQueue
11+
{
12+
use Queueable;
13+
private $sdp, $caller_id;
14+
15+
/**
16+
* Create a new notification instance.
17+
*/
18+
public function __construct($sdp, $caller_id)
19+
{
20+
//
21+
$this->sdp = $sdp;
22+
$this->caller_id = $caller_id;
23+
}
24+
25+
/**
26+
* Get the notification's delivery channels.
27+
*
28+
* @return array<int, string>
29+
*/
30+
public function via(object $notifiable): array
31+
{
32+
return ['broadcast'];
33+
}
34+
35+
/**
36+
* Get the mail representation of the notification.
37+
*/
38+
public function toMail(object $notifiable): MailMessage
39+
{
40+
return (new MailMessage)
41+
->line('The introduction to the notification.')
42+
->action('Notification Action', url('/'))
43+
->line('Thank you for using our application!');
44+
}
45+
46+
/**
47+
* Get the array representation of the notification.
48+
*
49+
* @return array<string, mixed>
50+
*/
51+
public function toArray(object $notifiable): array
52+
{
53+
return [
54+
//
55+
];
56+
}
57+
58+
public function toBroadcast(object $notifiable): BroadcastMessage
59+
{
60+
return new BroadcastMessage([
61+
'sdp' => $this->sdp,
62+
'caller_id' => $this->caller_id
63+
]);
64+
}
65+
}

bootstrap/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
return Application::configure(basePath: dirname(__DIR__))
88
->withRouting(
99
web: __DIR__.'/../routes/web.php',
10+
api: __DIR__.'/../routes/api.php',
1011
commands: __DIR__.'/../routes/console.php',
1112
channels: __DIR__.'/../routes/channels.php',
1213
health: '/up',

config/sanctum.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
use Laravel\Sanctum\Sanctum;
4+
5+
return [
6+
7+
/*
8+
|--------------------------------------------------------------------------
9+
| Stateful Domains
10+
|--------------------------------------------------------------------------
11+
|
12+
| Requests from the following domains / hosts will receive stateful API
13+
| authentication cookies. Typically, these should include your local
14+
| and production domains which access your API via a frontend SPA.
15+
|
16+
*/
17+
18+
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
19+
'%s%s',
20+
'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1',
21+
Sanctum::currentApplicationUrlWithPort()
22+
))),
23+
24+
/*
25+
|--------------------------------------------------------------------------
26+
| Sanctum Guards
27+
|--------------------------------------------------------------------------
28+
|
29+
| This array contains the authentication guards that will be checked when
30+
| Sanctum is trying to authenticate a request. If none of these guards
31+
| are able to authenticate the request, Sanctum will use the bearer
32+
| token that's present on an incoming request for authentication.
33+
|
34+
*/
35+
36+
'guard' => ['web'],
37+
38+
/*
39+
|--------------------------------------------------------------------------
40+
| Expiration Minutes
41+
|--------------------------------------------------------------------------
42+
|
43+
| This value controls the number of minutes until an issued token will be
44+
| considered expired. This will override any values set in the token's
45+
| "expires_at" attribute, but first-party sessions are not affected.
46+
|
47+
*/
48+
49+
'expiration' => null,
50+
51+
/*
52+
|--------------------------------------------------------------------------
53+
| Token Prefix
54+
|--------------------------------------------------------------------------
55+
|
56+
| Sanctum can prefix new tokens in order to take advantage of numerous
57+
| security scanning initiatives maintained by open source platforms
58+
| that notify developers if they commit tokens into repositories.
59+
|
60+
| See: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning
61+
|
62+
*/
63+
64+
'token_prefix' => env('SANCTUM_TOKEN_PREFIX', ''),
65+
66+
/*
67+
|--------------------------------------------------------------------------
68+
| Sanctum Middleware
69+
|--------------------------------------------------------------------------
70+
|
71+
| When authenticating your first-party SPA with Sanctum you may need to
72+
| customize some of the middleware Sanctum uses while processing the
73+
| request. You may change the middleware listed below as required.
74+
|
75+
*/
76+
77+
'middleware' => [
78+
'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class,
79+
'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class,
80+
'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class,
81+
],
82+
83+
];
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('personal_access_tokens', function (Blueprint $table) {
15+
$table->id();
16+
$table->morphs('tokenable');
17+
$table->string('name');
18+
$table->string('token', 64)->unique();
19+
$table->text('abilities')->nullable();
20+
$table->timestamp('last_used_at')->nullable();
21+
$table->timestamp('expires_at')->nullable();
22+
$table->timestamps();
23+
});
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*/
29+
public function down(): void
30+
{
31+
Schema::dropIfExists('personal_access_tokens');
32+
}
33+
};

0 commit comments

Comments
 (0)