项目作者: wqqas1

项目描述 :
laravel video chat using webrtc compatible with laravel 5.7
高级语言: PHP
项目地址: git://github.com/wqqas1/laravel-video-chat.git
创建时间: 2018-10-14T20:25:42Z
项目社区:https://github.com/wqqas1/laravel-video-chat

开源协议:MIT License

下载


Laravel Video Chat

Laravel Video Chat using Socket.IO and WebRTC

Installation

  1. composer require wqqas1/laravel-video-chat

Laravel 5.5 uses Package Auto-Discovery, so doesn’t require you to manually add the ServiceProvider.

If you don’t use auto-discovery, add the ServiceProvider to the providers array in config/app.php

  1. Wqqas1\LaravelVideoChat\LaravelVideoChatServiceProvider::class,
  1. php artisan vendor:publish --provider="Wqqas1\LaravelVideoChat\LaravelVideoChatServiceProvider"

And

  1. php artisan migrate
  2. php artisan storage:link
  3. change APP_URL in .env

This is the contents of the published config file:

  1. return [
  2. 'relation' => [
  3. 'conversations' => Wqqas1\LaravelVideoChat\Models\Conversation\Conversation::class,
  4. 'group_conversations' => Wqqas1\LaravelVideoChat\Models\Group\Conversation\GroupConversation::class
  5. ],
  6. 'user' => [
  7. 'model' => App\User::class,
  8. 'table' => 'users' // Existing user table name
  9. ],
  10. 'table' => [
  11. 'conversations_table' => 'conversations',
  12. 'messages_table' => 'messages',
  13. 'group_conversations_table' => 'group_conversations',
  14. 'group_users_table' => 'group_users',
  15. 'files_table' => 'files'
  16. ],
  17. 'channel' => [
  18. 'new_conversation_created' => 'new-conversation-created',
  19. 'chat_room' => 'chat-room',
  20. 'group_chat_room' => 'group-chat-room'
  21. ],
  22. 'upload' => [
  23. 'storage' => 'public'
  24. ]
  25. ];

Uncomment App\Providers\BroadcastServiceProvider in the providers array of your config/app.php configuration file

Install the JavaScript dependencies:

  1. npm install
  2. npm install --save laravel-echo js-cookie vue-timeago socket.io socket.io-client webrtc-adapter vue-chat-scroll

If you are running the Socket.IO server on the same domain as your web application, you may access the client library like

  1. <script src="//{{ Request::getHost() }}:6001/socket.io/socket.io.js"></script>

in your application’s head HTML element

Next, you will need to instantiate Echo with the socket.io connector and a host.

  1. require('webrtc-adapter');
  2. window.Cookies = require('js-cookie');
  3. import Echo from "laravel-echo"
  4. window.io = require('socket.io-client');
  5. window.Echo = new Echo({
  6. broadcaster: 'socket.io',
  7. host: window.location.hostname + ':6001'
  8. });

Finally, you will need to run a compatible Socket.IO server. Use
tlaverdure/laravel-echo-server GitHub repository.

In resources/js/app.js file:

  1. import VueChatScroll from 'vue-chat-scroll';
  2. import VueTimeago from 'vue-timeago';
  3. Vue.use(VueChatScroll);
  4. Vue.component('chat-room' , require('./components/laravel-video-chat/ChatRoom.vue'));
  5. Vue.component('group-chat-room', require('./components/laravel-video-chat/GroupChatRoom.vue'));
  6. Vue.component('video-section' , require('./components/laravel-video-chat/VideoSection.vue'));
  7. Vue.component('file-preview' , require('./components/laravel-video-chat/FilePreview.vue'));
  8. Vue.use(VueTimeago, {
  9. name: 'timeago', // component name, `timeago` by default
  10. locale: 'en-US',
  11. locales: {
  12. // you will need json-loader in webpack 1
  13. 'en-US': require('date-fns/locale/en')
  14. }
  15. })

Run npm run dev to recompile your assets.

Features

  • One To One Chat ( With Video Call )
  • Accept Message Request
  • Group Chat
  • File Sharing

Usage

Get All Conversation and Group Conversation

  1. $groups = Chat::getAllGroupConversations();
  2. $conversations = Chat::getAllConversations()
  1. <ul class="list-group">
  2. @foreach($conversations as $conversation)
  3. <li class="list-group-item">
  4. @if($conversation->message->conversation->is_accepted)
  5. <a href="#">
  6. <h2>{{$conversation->user->name}}</h2>
  7. @if(!is_null($conversation->message))
  8. <span>{{ substr($conversation->message->text, 0, 20)}}</span>
  9. @endif
  10. </a>
  11. @else
  12. <a href="#">
  13. <h2>{{$conversation->user->name}}</h2>
  14. @if($conversation->message->conversation->second_user_id == auth()->user()->id)
  15. <a href="accept_request_route" class="btn btn-xs btn-success">
  16. Accept Message Request
  17. </a>
  18. @endif
  19. </a>
  20. @endif
  21. </li>
  22. @endforeach
  23. @foreach($groups as $group)
  24. <li class="list-group-item">
  25. <a href="#">
  26. <h2>{{$group->name}}</h2>
  27. <span>{{ $group->users_count }} Member</span>
  28. </a>
  29. </li>
  30. @endforeach
  31. </ul>

Start Conversation

  1. Chat::startConversationWith($otherUserId);

Accept Conversation

  1. Chat::acceptMessageRequest($conversationId);

Get Conversation Messages

  1. $conversation = Chat::getConversationMessageById($conversationId);
  1. <chat-room :conversation="{{ $conversation }}" :current-user="{{ auth()->user() }}"></chat-room>

Send Message

You can change message send route in component

  1. Chat::sendConversationMessage($conversationId, $message);

Start Video Call ( Not Avaliable On Group Chat )

You can change video call route . I defined video call route trigger/{id} method POST
Use $request->all() for video call.

  1. Chat::startVideoCall($conversationId , $request->all());

Start Group Conversation

  1. Chat::createGroupConversation( $groupName , [ $otherUserId , $otherUserId2 ]);

Get Group Conversation Messages

  1. $conversation = Chat::getGroupConversationMessageById($groupConversationId);
  1. <group-chat-room :conversation="{{ $conversation }}" :current-user="{{ auth()->user() }}"></group-chat-room>

Send Group Chat Message

You can change message send route in component

  1. Chat::sendGroupConversationMessage($groupConversationId, $message);

Add Members to Group

  1. Chat::addMembersToExistingGroupConversation($groupConversationId, [ $otherUserId , $otherUserId2 ])

Remove Members from Group

  1. Chat::removeMembersFromGroupConversation($groupConversationId, [ $otherUserId , $otherUserId2 ])

Leave From Group

  1. Chat::leaveFromGroupConversation($groupConversationId);

File Sharing

Run this command php artisan storage:link

Send Files in Conversation

  1. Chat::sendFilesInConversation($conversationId , $request->file('files'));

Send Files in Group Conversation

  1. Chat::sendFilesInGroupConversation($groupConversationId , $request->file('files'));

ToDo

  • Add Members to Group
  • Remove Member From Group

Next Version

  • Group Video Call

Credits

  • All Contributors

License

The MIT License (MIT). Please see License File for more information.

Demo Project

This whole work is based on https://github.com/PHPJunior/laravel-video-chat but modified to make it compatible with laravel 5.7 this version does not work with laravel versions less than 5.7 for that you can download the original package